Mercurial > public > mercurial-scm > hg-stable
comparison contrib/phabricator.py @ 33564:91e3dcefc9b7
phabricator: sanity check Differential Revision from commit message
Previously, we trust Differential Revision in commit message blindly. This
patch adds sanity check so a host name change will be detected and the
commit message will be ignored.
Differential Revision: https://phab.mercurial-scm.org/D35
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 10 Jul 2017 18:02:03 -0700 |
parents | b7a75b9a3386 |
children | 850d2ec2cf6a |
comparison
equal
deleted
inserted
replaced
33563:da94a99df96b | 33564:91e3dcefc9b7 |
---|---|
136 repo.ui.setconfig('phabricator', 'repophid', repophid) | 136 repo.ui.setconfig('phabricator', 'repophid', repophid) |
137 return repophid | 137 return repophid |
138 | 138 |
139 _differentialrevisiontagre = re.compile('\AD([1-9][0-9]*)\Z') | 139 _differentialrevisiontagre = re.compile('\AD([1-9][0-9]*)\Z') |
140 _differentialrevisiondescre = re.compile( | 140 _differentialrevisiondescre = re.compile( |
141 '^Differential Revision:.*D([1-9][0-9]*)$', re.M) | 141 '^Differential Revision:\s*(.*)D([1-9][0-9]*)$', re.M) |
142 | 142 |
143 def getoldnodedrevmap(repo, nodelist): | 143 def getoldnodedrevmap(repo, nodelist): |
144 """find previous nodes that has been sent to Phabricator | 144 """find previous nodes that has been sent to Phabricator |
145 | 145 |
146 return {node: (oldnode or None, Differential Revision ID)} | 146 return {node: (oldnode or None, Differential Revision ID)} |
170 m = _differentialrevisiontagre.match(tag) | 170 m = _differentialrevisiontagre.match(tag) |
171 if m: | 171 if m: |
172 toconfirm[node] = (n, set(precnodes), int(m.group(1))) | 172 toconfirm[node] = (n, set(precnodes), int(m.group(1))) |
173 continue | 173 continue |
174 | 174 |
175 # Check commit message | 175 # Check commit message (make sure URL matches) |
176 m = _differentialrevisiondescre.search(ctx.description()) | 176 m = _differentialrevisiondescre.search(ctx.description()) |
177 if m: | 177 if m: |
178 result[node] = (None, int(m.group(1))) | 178 if m.group(1).rstrip('/') == url.rstrip('/'): |
179 result[node] = (None, int(m.group(2))) | |
180 else: | |
181 unfi.ui.warn(_('%s: Differential Revision URL ignored - host ' | |
182 'does not match config\n') % ctx) | |
179 | 183 |
180 # Double check if tags are genuine by collecting all old nodes from | 184 # Double check if tags are genuine by collecting all old nodes from |
181 # Phabricator, and expect precursors overlap with it. | 185 # Phabricator, and expect precursors overlap with it. |
182 if toconfirm: | 186 if toconfirm: |
183 confirmed = {} # {drev: {oldnode}} | 187 confirmed = {} # {drev: {oldnode}} |