Mercurial > hg
comparison tests/drawdag.py @ 33558:0103e7187237
drawdag: include files from both parents in merge commits
Consider a graph like this:
D
|\
B C
|/
A
drawdag will add a file called A in commit A, file B in B, file C in
C. That's fine and expected. In merge commits like D, I would expect
the files and their contents to be taken from the parent commits, so
commit D in this example would have files A, B, and C. However,
drawdag will instead add the file D compared to the first
parent. Depending on whether B or C got a smaller nodeid, the contents
of D would be {A, B, D} or {A, C, D}. This patch changes it to to be
{A, B, C}.
Differential Revision: https://phab.mercurial-scm.org/D92
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 14 Jul 2017 22:32:58 -0700 |
parents | 0830c841fc7f |
children | 0531ffd59a98 |
comparison
equal
deleted
inserted
replaced
33557:875b054e5b95 | 33558:0103e7187237 |
---|---|
233 | 233 |
234 def flags(self): | 234 def flags(self): |
235 return '' | 235 return '' |
236 | 236 |
237 class simplecommitctx(context.committablectx): | 237 class simplecommitctx(context.committablectx): |
238 def __init__(self, repo, name, parentctxs, added=None): | 238 def __init__(self, repo, name, parentctxs, added): |
239 opts = { | 239 opts = { |
240 'changes': scmutil.status([], added or [], [], [], [], [], []), | 240 'changes': scmutil.status([], list(added), [], [], [], [], []), |
241 'date': '0 0', | 241 'date': '0 0', |
242 'extra': {'branch': 'default'}, | 242 'extra': {'branch': 'default'}, |
243 } | 243 } |
244 super(simplecommitctx, self).__init__(self, name, **opts) | 244 super(simplecommitctx, self).__init__(self, name, **opts) |
245 self._repo = repo | 245 self._repo = repo |
246 self._name = name | 246 self._added = added |
247 self._parents = parentctxs | 247 self._parents = parentctxs |
248 self._parents.sort(key=lambda c: c.node()) | |
249 while len(self._parents) < 2: | 248 while len(self._parents) < 2: |
250 self._parents.append(repo[node.nullid]) | 249 self._parents.append(repo[node.nullid]) |
251 | 250 |
252 def filectx(self, key): | 251 def filectx(self, key): |
253 return simplefilectx(key, self._name) | 252 return simplefilectx(key, self._added[key]) |
254 | 253 |
255 def commit(self): | 254 def commit(self): |
256 return self._repo.commitctx(self) | 255 return self._repo.commitctx(self) |
257 | 256 |
258 def _walkgraph(edges): | 257 def _walkgraph(edges): |
315 # commit in topological order | 314 # commit in topological order |
316 for name, parents in _walkgraph(edges): | 315 for name, parents in _walkgraph(edges): |
317 if name in committed: | 316 if name in committed: |
318 continue | 317 continue |
319 pctxs = [repo[committed[n]] for n in parents] | 318 pctxs = [repo[committed[n]] for n in parents] |
320 ctx = simplecommitctx(repo, name, pctxs, [name]) | 319 pctxs.sort(key=lambda c: c.node()) |
320 added = {} | |
321 if len(parents) > 1: | |
322 # If it's a merge, take the files and contents from the parents | |
323 for f in pctxs[1].manifest(): | |
324 if f not in pctxs[0].manifest(): | |
325 added[f] = pctxs[1][f].data() | |
326 else: | |
327 # If it's not a merge, add a single file | |
328 added[name] = name | |
329 ctx = simplecommitctx(repo, name, pctxs, added) | |
321 n = ctx.commit() | 330 n = ctx.commit() |
322 committed[name] = n | 331 committed[name] = n |
323 tagsmod.tag(repo, name, n, message=None, user=None, date=None, | 332 tagsmod.tag(repo, name, n, message=None, user=None, date=None, |
324 local=True) | 333 local=True) |
325 | 334 |