diff options
author | Simon Glass | 2020-07-05 21:41:51 -0600 |
---|---|---|
committer | Simon Glass | 2020-07-20 11:37:46 -0600 |
commit | e9799e0890339dcf9f816f7b904147f791fca011 (patch) | |
tree | ef6907830bc90d3c760eabc11ca4740507cee51b /tools/patman/gitutil.py | |
parent | 5d597584dbf027ce3e87d06001f5cbc2bde26eb2 (diff) |
patman: Allow creating patches for another branch
Add a -b option to allow patches to be created from a branch other than
the current one.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/gitutil.py')
-rw-r--r-- | tools/patman/gitutil.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index 29444bf8e92..b683481a574 100644 --- a/tools/patman/gitutil.py +++ b/tools/patman/gitutil.py @@ -49,17 +49,24 @@ def LogCmd(commit_range, git_dir=None, oneline=False, reverse=False, cmd.append('--') return cmd -def CountCommitsToBranch(): +def CountCommitsToBranch(branch): """Returns number of commits between HEAD and the tracking branch. This looks back to the tracking branch and works out the number of commits since then. + Args: + branch: Branch to count from (None for current branch) + Return: Number of patches that exist on top of the branch """ - pipe = [LogCmd('@{upstream}..', oneline=True), - ['wc', '-l']] + if branch: + us, msg = GetUpstream('.git', branch) + rev_range = '%s..%s' % (us, branch) + else: + rev_range = '@{upstream}..' + pipe = [LogCmd(rev_range, oneline=True), ['wc', '-l']] stdout = command.RunPipe(pipe, capture=True, oneline=True).stdout patch_count = int(stdout) return patch_count @@ -252,13 +259,14 @@ def Fetch(git_dir=None, work_tree=None): if result.return_code != 0: raise OSError('git fetch: %s' % result.stderr) -def CreatePatches(start, count, ignore_binary, series): +def CreatePatches(branch, start, count, ignore_binary, series): """Create a series of patches from the top of the current branch. The patch files are written to the current directory using git format-patch. Args: + branch: Branch to create patches from (None for current branch) start: Commit to start from: 0=HEAD, 1=next one, etc. count: number of commits to include ignore_binary: Don't generate patches for binary files @@ -277,7 +285,8 @@ def CreatePatches(start, count, ignore_binary, series): prefix = series.GetPatchPrefix() if prefix: cmd += ['--subject-prefix=%s' % prefix] - cmd += ['HEAD~%d..HEAD~%d' % (start + count, start)] + brname = branch or 'HEAD' + cmd += ['%s~%d..%s~%d' % (brname, start + count, brname, start)] stdout = command.RunList(cmd) files = stdout.splitlines() |