mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
16996f562f
Summary: Many diffs include multiple tags as prefixes, however the current implementation only greedily takes prefix as the substring up to ']'. ## Issues Current behaviour for - **non-tag right bracket:** `My fake diff title with [link]()` -> `My fake diff title with [link]` - **multiple tags:** `[hg][extensions] fake diff title` -> `[hg]` ## Solution Use regex to capture all prefix tags: ``` (?:\[.*?\])+ ``` ## Explanation - Non capturing group ( `(?: ... )` ) - matching the open bracket ( `\[` ) - and any character as few times as necessary (lazy) ( `.*?` ) - and the closing bracket ( `\]` ) - matching the group as many times as needed (greedy) ( `+` ) Also note `re.match()` matches from the beginning of the string (unlike `re.search()`) Reviewed By: ronmrdechai Differential Revision: D30415867 fbshipit-source-id: e09d4e6d2759d0106d41d1a5d4e607ec34eef3fa
74 lines
1.9 KiB
Perl
74 lines
1.9 KiB
Perl
#chg-compatible
|
|
|
|
Setup
|
|
|
|
$ enable myparent
|
|
$ hg init repo
|
|
$ cd repo
|
|
$ touch foo
|
|
$ cat >> ../commitmessage << EOF
|
|
> [prefix] My title
|
|
>
|
|
> Summary: Very good summary of my commit.
|
|
>
|
|
> Test Plan: cat foo
|
|
>
|
|
> Reviewers: #sourcecontrol, rmcelroy
|
|
>
|
|
> Subscribers: rmcelroy, mjpieters
|
|
>
|
|
> Differential Revision: https://phabricator.fb.com/D42
|
|
>
|
|
> Tasks: 1337
|
|
>
|
|
> Tags: mercurial
|
|
> EOF
|
|
$ hg commit -qAl ../commitmessage
|
|
$ touch bar
|
|
$ hg commit -qAm 'Differential Revision: https://phabricator.fb.com/D2'
|
|
|
|
All template keywords work if the current author matches the other of the
|
|
previous commit.
|
|
|
|
$ hg log -T '{myparentdiff}\n' -r .
|
|
D42
|
|
$ hg log -T '{myparentreviewers}\n' -r .
|
|
#sourcecontrol, rmcelroy
|
|
$ hg log -T '{myparentsubscribers}\n' -r .
|
|
rmcelroy, mjpieters
|
|
$ hg log -T '{myparenttasks}\n' -r .
|
|
1337
|
|
$ hg log -T '{myparenttitleprefix}\n' -r .
|
|
[prefix]
|
|
$ hg log -T '{myparenttags}\n' -r .
|
|
mercurial
|
|
|
|
If the authors do not match the keywords will be empty.
|
|
|
|
$ hg commit -q --amend --user hacker2
|
|
$ hg log -T '{myparentdiff}' -r .
|
|
$ hg log -T '{myparentreviewers}' -r .
|
|
$ hg log -T '{myparentsubscribers}' -r .
|
|
$ hg log -T '{myparenttasks}' -r .
|
|
$ hg log -T '{myparenttitleprefix}' -r .
|
|
$ hg log -T '{myparenttags}' -r .
|
|
|
|
Ensure multiple prefixes tags are supported
|
|
|
|
$ touch baz
|
|
$ hg commit -qAm '[long tag][ tag2][tag3 ] [tags must be connected] Adding baz'
|
|
$ touch foobar
|
|
$ hg commit -qAm 'Child commit'
|
|
$ hg log -T '{myparenttitleprefix}\n' -r .
|
|
[long tag][ tag2][tag3 ]
|
|
|
|
Make sure the template keywords are documented correctly
|
|
|
|
$ hg help templates | grep myparent
|
|
myparentdiff Show the differential revision of the commit's parent, if it
|
|
myparentreviewers
|
|
myparentsubscribers
|
|
myparenttags Show the tags from the commit's parent, if it has the same
|
|
myparenttasks
|
|
myparenttitleprefix
|