Mercurial > public > mercurial-scm > hg-stable
comparison contrib/phabricator.py @ 33263:ed61189763ef
phabricator: check associated Differential Revision from commit message
Previously, only tags can "associate" a changeset to a Differential
Revision. But the usual pattern (arc patch or hg phabread) is to put the
Differential Revision URL in commit message.
This patch makes the code read commit message to find associated
Differential Revision if associated tags are not found.
This makes some workflows possible. For example, if the author loses their
repo, or switch to another computer, they can continue download their own
patches from Phabricator and update them without needing to manually create
tags.
author | Jun Wu <quark@fb.com> |
---|---|
date | Tue, 04 Jul 2017 16:16:37 -0700 |
parents | 04cf9927f350 |
children | 266321579c68 |
comparison
equal
deleted
inserted
replaced
33262:8e6f4939a69a | 33263:ed61189763ef |
---|---|
133 return None | 133 return None |
134 repophid = encoding.strtolocal(query[r'data'][0][r'phid']) | 134 repophid = encoding.strtolocal(query[r'data'][0][r'phid']) |
135 repo.ui.setconfig('phabricator', 'repophid', repophid) | 135 repo.ui.setconfig('phabricator', 'repophid', repophid) |
136 return repophid | 136 return repophid |
137 | 137 |
138 _differentialrevisionre = re.compile('\AD([1-9][0-9]*)\Z') | 138 _differentialrevisiontagre = re.compile('\AD([1-9][0-9]*)\Z') |
139 _differentialrevisiondescre = re.compile( | |
140 '^Differential Revision:.*D([1-9][0-9]*)$', re.M) | |
139 | 141 |
140 def getmapping(ctx): | 142 def getmapping(ctx): |
141 """return (node, associated Differential Revision ID) or (None, None) | 143 """return (node, associated Differential Revision ID) or (None, None) |
142 | 144 |
143 Examines all precursors and their tags. Tags with format like "D1234" are | 145 Examines all precursors and their tags. Tags with format like "D1234" are |
144 considered a match and the node with that tag, and the number after "D" | 146 considered a match and the node with that tag, and the number after "D" |
145 (ex. 1234) will be returned. | 147 (ex. 1234) will be returned. |
148 | |
149 If tags are not found, examine commit message. The "Differential Revision:" | |
150 line could associate this changeset to a Differential Revision. | |
146 """ | 151 """ |
147 unfi = ctx.repo().unfiltered() | 152 unfi = ctx.repo().unfiltered() |
148 nodemap = unfi.changelog.nodemap | 153 nodemap = unfi.changelog.nodemap |
154 | |
155 # Check tags like "D123" | |
149 for n in obsolete.allprecursors(unfi.obsstore, [ctx.node()]): | 156 for n in obsolete.allprecursors(unfi.obsstore, [ctx.node()]): |
150 if n in nodemap: | 157 if n in nodemap: |
151 for tag in unfi.nodetags(n): | 158 for tag in unfi.nodetags(n): |
152 m = _differentialrevisionre.match(tag) | 159 m = _differentialrevisiontagre.match(tag) |
153 if m: | 160 if m: |
154 return n, int(m.group(1)) | 161 return n, int(m.group(1)) |
162 | |
163 # Check commit message | |
164 m = _differentialrevisiondescre.search(ctx.description()) | |
165 if m: | |
166 return None, int(m.group(1)) | |
167 | |
155 return None, None | 168 return None, None |
156 | 169 |
157 def getdiff(ctx, diffopts): | 170 def getdiff(ctx, diffopts): |
158 """plain-text diff without header (user, commit message, etc)""" | 171 """plain-text diff without header (user, commit message, etc)""" |
159 output = util.stringio() | 172 output = util.stringio() |