[PATCH 1 of 2 STABLE] diff: don't crash when diffing a revision with a deleted subrepo (issue3153)

Renato Cunha renato at renatocunha.com
Wed Dec 14 08:31:40 CST 2011


# HG changeset patch
# User Renato Cunha <renato at renatocunha.com>
# Date 1323872880 7200
# Node ID 6aaafc6ab31322c2d89b66c37f993121eaebe53d
# Parent  e6868bd17f24324db347a289bb2ae0120dd5cd54
diff: don't crash when diffing a revision with a deleted subrepo (issue3153)

When a user requested a diff between a revision (r1) that contained a subrepo
and another (r2) that did not, mercurial would crash if r1 was specified before
r2 but would execute the diff otherwise. This fixes this behavior by skipping
the missing subrepo in the diff.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -588,8 +588,14 @@
         ctx1 = repo[node1]
         ctx2 = repo[node2]
         for subpath, sub in subrepo.itersubrepos(ctx1, ctx2):
-            if node2 is not None:
-                node2 = ctx2.substate[subpath][1]
+            try:
+                if node2 is not None:
+                    node2 = ctx2.substate[subpath][1]
+            except KeyError:
+                # A subrepo that existed in node1 was deleted between node1 and
+                # node2 (inclusive). Thus, ctx2's substate won't contain that
+                # subpath. The best we can do is to ignore it.
+                node2 = None
             submatch = matchmod.narrowmatcher(subpath, match)
             sub.diff(diffopts, node2, submatch, changes=changes,
                      stat=stat, fp=fp, prefix=prefix)


More information about the Mercurial-devel mailing list