mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-17 10:24:49 +00:00
patman: Show the base commit and branch
It is helpful to know which commit patches are based on, even if that commit might not be available to readers. Add a tag for this in the cover letter. Also add the local-branch name since that may be useful to the writer. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
206ca97fac
commit
774e966f29
4 changed files with 59 additions and 4 deletions
|
@ -216,6 +216,8 @@ class TestFunctional(unittest.TestCase):
|
|||
|
||||
text = self._get_text('test01.txt')
|
||||
series = patchstream.get_metadata_for_test(text)
|
||||
series.base_commit = Commit('1a44532')
|
||||
series.branch = 'mybranch'
|
||||
cover_fname, args = self._create_patches_for_test(series)
|
||||
get_maintainer_script = str(pathlib.Path(__file__).parent.parent.parent
|
||||
/ 'get_maintainer.pl') + ' --norolestats'
|
||||
|
@ -308,6 +310,8 @@ Simon Glass (2):
|
|||
--\x20
|
||||
2.7.4
|
||||
|
||||
base-commit: 1a44532
|
||||
branch: mybranch
|
||||
'''
|
||||
lines = open(cover_fname, encoding='utf-8').read().splitlines()
|
||||
self.assertEqual(
|
||||
|
@ -511,12 +515,18 @@ complicated as possible''')
|
|||
# Check that it can detect a different branch
|
||||
self.assertEqual(3, gitutil.count_commits_to_branch('second'))
|
||||
with capture_sys_output() as _:
|
||||
_, cover_fname, patch_files = control.prepare_patches(
|
||||
series, cover_fname, patch_files = control.prepare_patches(
|
||||
col, branch='second', count=-1, start=0, end=0,
|
||||
ignore_binary=False, signoff=True)
|
||||
self.assertIsNotNone(cover_fname)
|
||||
self.assertEqual(3, len(patch_files))
|
||||
|
||||
cover = tools.read_file(cover_fname, binary=False)
|
||||
lines = cover.splitlines()[-2:]
|
||||
base = repo.lookup_reference('refs/heads/base').target
|
||||
self.assertEqual(f'base-commit: {base}', lines[0])
|
||||
self.assertEqual('branch: second', lines[1])
|
||||
|
||||
# Check that it can skip patches at the end
|
||||
with capture_sys_output() as _:
|
||||
_, cover_fname, patch_files = control.prepare_patches(
|
||||
|
@ -524,6 +534,13 @@ complicated as possible''')
|
|||
ignore_binary=False, signoff=True)
|
||||
self.assertIsNotNone(cover_fname)
|
||||
self.assertEqual(2, len(patch_files))
|
||||
|
||||
cover = tools.read_file(cover_fname, binary=False)
|
||||
lines = cover.splitlines()[-2:]
|
||||
base2 = repo.lookup_reference('refs/heads/second')
|
||||
ref = base2.peel(pygit2.GIT_OBJ_COMMIT).parents[0].parents[0].id
|
||||
self.assertEqual(f'base-commit: {ref}', lines[0])
|
||||
self.assertEqual('branch: second', lines[1])
|
||||
finally:
|
||||
os.chdir(orig_dir)
|
||||
|
||||
|
|
|
@ -755,8 +755,12 @@ def get_metadata(branch, start, count):
|
|||
Returns:
|
||||
Series: Object containing information about the commits.
|
||||
"""
|
||||
return get_metadata_for_list(
|
||||
'%s~%d' % (branch if branch else 'HEAD', start), None, count)
|
||||
top = f"{branch if branch else 'HEAD'}~{start}"
|
||||
series = get_metadata_for_list(top, None, count)
|
||||
series.base_commit = commit.Commit(gitutil.get_hash(f'{top}~{count}'))
|
||||
series.branch = branch or gitutil.get_branch()
|
||||
series.top = top
|
||||
return series
|
||||
|
||||
def get_metadata_for_test(text):
|
||||
"""Process metadata from a file containing a git log. Used for tests
|
||||
|
@ -868,4 +872,11 @@ def insert_cover_letter(fname, series, count):
|
|||
out = series.MakeChangeLog(None)
|
||||
line += '\n' + '\n'.join(out)
|
||||
fil.write(line)
|
||||
|
||||
# Insert the base commit and branch
|
||||
if series.base_commit:
|
||||
print(f'base-commit: {series.base_commit.hash}', file=fil)
|
||||
if series.branch:
|
||||
print(f'branch: {series.branch}', file=fil)
|
||||
|
||||
fil.close()
|
||||
|
|
|
@ -42,6 +42,8 @@ class Series(dict):
|
|||
self.notes = []
|
||||
self.changes = {}
|
||||
self.allow_overwrite = False
|
||||
self.base_commit = None
|
||||
self.branch = None
|
||||
|
||||
# Written in MakeCcFile()
|
||||
# key: name of patch file
|
||||
|
|
|
@ -701,13 +701,38 @@ def setup():
|
|||
.return_code == 0)
|
||||
|
||||
|
||||
def get_hash(spec):
|
||||
"""Get the hash of a commit
|
||||
|
||||
Args:
|
||||
spec (str): Git commit to show, e.g. 'my-branch~12'
|
||||
|
||||
Returns:
|
||||
str: Hash of commit
|
||||
"""
|
||||
return command.output_one_line('git', 'show', '-s', '--pretty=format:%H',
|
||||
spec)
|
||||
|
||||
|
||||
def get_head():
|
||||
"""Get the hash of the current HEAD
|
||||
|
||||
Returns:
|
||||
Hash of HEAD
|
||||
"""
|
||||
return command.output_one_line('git', 'show', '-s', '--pretty=format:%H')
|
||||
return get_hash('HEAD')
|
||||
|
||||
|
||||
def get_branch():
|
||||
"""Get the branch we are currently on
|
||||
|
||||
Return:
|
||||
str: branch name, or None if none
|
||||
"""
|
||||
out = command.output_one_line('git', 'rev-parse', '--abbrev-ref', 'HEAD')
|
||||
if out == 'HEAD':
|
||||
return None
|
||||
return out
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Reference in a new issue