On Fri, Jan 10, 2020 at 07:50:02PM +0100, Jakub Jelinek wrote: > The changes I was asking for is, for gcc master and releases/gcc-* branch > commits to have the monotonically increasing short ids (printed by git descr > <commithash> with the git aliases I've posted) both somewhere early > in the subject before the one-line description, and somewhere in the body > too. For release branch commits, perhaps the
Here it is in patch form (against Joseph's git-hooks copy), but untested (both because the repo isn't converted yet, basepoints don't exist there either and because not sure how exactly it can be tested in a dry-run, say sending me mail instead of to the public list etc.). So, all I did test is some simple thing in python3 interactively because it is close to 20 years since I used python regularly. diff --git a/hooks/updates/__init__.py b/hooks/updates/__init__.py index c5d8181..4ddc566 100644 --- a/hooks/updates/__init__.py +++ b/hooks/updates/__init__.py @@ -299,11 +299,31 @@ class AbstractUpdate(object): # name in full to label the branch name. branch = '(%s)' % self.ref_name - subject = '[%(repo)s%(branch)s] %(subject)s' % { - 'repo': self.email_info.project_name, - 'branch': branch, - 'subject': commit.subject[:SUBJECT_MAX_SUBJECT_CHARS], - } + # GCC monotonically increasing commit ids. + rev_id = '' + rev_id_short = '' + if self.email_info.project_name == 'gcc' + and (self.short_ref_name == 'master' + or self.short_ref_name.startswith('releases/gcc-')): + rev_id = git.describe(commit.rev, all=True, + match='basepoints/gcc-[0-9]*') + if rev_id.starts_with('tags/basepoints/gcc-'): + rev_id = 'r' + rev_id[len('tags/basepoints/gcc-'):] + rev_id_short = rev_id[:rev_id.find('-g')] + else: + rev_id = '' + + if not rev_id: + subject = '[%(repo)s%(branch)s] %(subject)s' % { + 'repo': self.email_info.project_name, + 'branch': branch, + 'subject': commit.subject[:SUBJECT_MAX_SUBJECT_CHARS], + } + else: + subject = '%(rev_id)s %(subject)s' % { + 'rev_id': rev_id_short, + 'subject': commit.subject[:SUBJECT_MAX_SUBJECT_CHARS], + } # Generate the body of the email in two pieces: # 1. The commit description without the patch; @@ -322,6 +342,10 @@ class AbstractUpdate(object): # by stripping it from the output. body = git.log(commit.rev, max_count="1") + '\n' + + if rev_id: + body = re.sub(r'^commit ' + commit.rev', 'commit ' + rev_id, + body, 1, re.M) if git_config('hooks.commit-url') is not None: url_info = {'rev': commit.rev, 'ref_name': self.ref_name} Jakub