mirror of
https://xff.cz/git/u-boot/
synced 2025-09-02 17:22:22 +02:00
patman: Move the 'git log' command into a function
Move the code that builds a 'git log' command into a function so we can more easily adjust it. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -14,6 +14,31 @@ import terminal
|
|||||||
import checkpatch
|
import checkpatch
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
|
def LogCmd(commit_range, git_dir=None, oneline=False, reverse=False,
|
||||||
|
count=None):
|
||||||
|
"""Create a command to perform a 'git log'
|
||||||
|
|
||||||
|
Args:
|
||||||
|
commit_range: Range expression to use for log, None for none
|
||||||
|
git_dir: Path to git repositiory (None to use default)
|
||||||
|
oneline: True to use --oneline, else False
|
||||||
|
reverse: True to reverse the log (--reverse)
|
||||||
|
count: Number of commits to list, or None for no limit
|
||||||
|
Return:
|
||||||
|
List containing command and arguments to run
|
||||||
|
"""
|
||||||
|
cmd = ['git']
|
||||||
|
if git_dir:
|
||||||
|
cmd += ['--git-dir', git_dir]
|
||||||
|
cmd += ['log', '--no-color']
|
||||||
|
if oneline:
|
||||||
|
cmd.append('--oneline')
|
||||||
|
cmd.append('--no-decorate')
|
||||||
|
if count is not None:
|
||||||
|
cmd.append('-n%d' % count)
|
||||||
|
if commit_range:
|
||||||
|
cmd.append(commit_range)
|
||||||
|
return cmd
|
||||||
|
|
||||||
def CountCommitsToBranch():
|
def CountCommitsToBranch():
|
||||||
"""Returns number of commits between HEAD and the tracking branch.
|
"""Returns number of commits between HEAD and the tracking branch.
|
||||||
@@ -24,8 +49,7 @@ def CountCommitsToBranch():
|
|||||||
Return:
|
Return:
|
||||||
Number of patches that exist on top of the branch
|
Number of patches that exist on top of the branch
|
||||||
"""
|
"""
|
||||||
pipe = [['git', 'log', '--no-color', '--oneline', '--no-decorate',
|
pipe = [LogCmd('@{upstream}..', oneline=True),
|
||||||
'@{upstream}..'],
|
|
||||||
['wc', '-l']]
|
['wc', '-l']]
|
||||||
stdout = command.RunPipe(pipe, capture=True, oneline=True).stdout
|
stdout = command.RunPipe(pipe, capture=True, oneline=True).stdout
|
||||||
patch_count = int(stdout)
|
patch_count = int(stdout)
|
||||||
@@ -87,8 +111,7 @@ def CountCommitsInBranch(git_dir, branch, include_upstream=False):
|
|||||||
range_expr = GetRangeInBranch(git_dir, branch, include_upstream)
|
range_expr = GetRangeInBranch(git_dir, branch, include_upstream)
|
||||||
if not range_expr:
|
if not range_expr:
|
||||||
return None
|
return None
|
||||||
pipe = [['git', '--git-dir', git_dir, 'log', '--oneline', '--no-decorate',
|
pipe = [LogCmd(range_expr, git_dir=git_dir, oneline=True),
|
||||||
range_expr],
|
|
||||||
['wc', '-l']]
|
['wc', '-l']]
|
||||||
result = command.RunPipe(pipe, capture=True, oneline=True)
|
result = command.RunPipe(pipe, capture=True, oneline=True)
|
||||||
patch_count = int(result.stdout)
|
patch_count = int(result.stdout)
|
||||||
@@ -102,7 +125,7 @@ def CountCommits(commit_range):
|
|||||||
Return:
|
Return:
|
||||||
Number of patches that exist on top of the branch
|
Number of patches that exist on top of the branch
|
||||||
"""
|
"""
|
||||||
pipe = [['git', 'log', '--oneline', '--no-decorate', commit_range],
|
pipe = [LogCmd(commit_range, oneline=True),
|
||||||
['wc', '-l']]
|
['wc', '-l']]
|
||||||
stdout = command.RunPipe(pipe, capture=True, oneline=True).stdout
|
stdout = command.RunPipe(pipe, capture=True, oneline=True).stdout
|
||||||
patch_count = int(stdout)
|
patch_count = int(stdout)
|
||||||
|
@@ -379,14 +379,9 @@ def GetMetaDataForList(commit_range, git_dir=None, count=None,
|
|||||||
Returns:
|
Returns:
|
||||||
A Series object containing information about the commits.
|
A Series object containing information about the commits.
|
||||||
"""
|
"""
|
||||||
params = ['git', 'log', '--no-color', '--reverse', '--no-decorate',
|
params = gitutil.LogCmd(commit_range,reverse=True, count=count,
|
||||||
commit_range]
|
git_dir=git_dir)
|
||||||
if count is not None:
|
stdout = command.RunPipe([params], capture=True).stdout
|
||||||
params[2:2] = ['-n%d' % count]
|
|
||||||
if git_dir:
|
|
||||||
params[1:1] = ['--git-dir', git_dir]
|
|
||||||
pipe = [params]
|
|
||||||
stdout = command.RunPipe(pipe, capture=True).stdout
|
|
||||||
ps = PatchStream(series, is_log=True)
|
ps = PatchStream(series, is_log=True)
|
||||||
for line in stdout.splitlines():
|
for line in stdout.splitlines():
|
||||||
ps.ProcessLine(line)
|
ps.ProcessLine(line)
|
||||||
|
Reference in New Issue
Block a user