Patchwork [1,of,3] revert: handle subrepos missing in the given --rev

mail settings
Submitter Matt Harbison
Date March 26, 2015, 4:20 a.m.
Message ID <6e1b26088b8eca13825a.1427343655@Envy>
Download mbox | patch
Permalink /patch/8287/
State Accepted
Commit 06d199e66bbcc4ce62da1d20e740746a753a362d
Headers show


Matt Harbison - March 26, 2015, 4:20 a.m.
# HG changeset patch
# User Matt Harbison <>
# Date 1427334887 14400
#      Wed Mar 25 21:54:47 2015 -0400
# Node ID 6e1b26088b8eca13825a91e4e1e3547c2e89f6a0
# Parent  98042b0e19f9a04be3270cecb07915eac3a515cf
revert: handle subrepos missing in the given --rev

The list of subrepos to revert is currently based on the given --rev, so there
is currently no way for this to fail.  Using the --rev context is wrong though,
because if the subrepo doesn't exist in --rev, it is skipped, so it won't be
changed.  This change makes it so that the revert aborts, which is what happens
if a plain file is reverted to -1.  Finding matches based on --rev is also
inconsistent with evaluating files against the working directory (5b85a5bc5bbb).

This change is made now, so as to not cause breakage when the context is
switched in an upcoming patch.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -3053,7 +3053,11 @@ 
         if targetsubs:
             # Revert the subrepos on the revert list
             for sub in targetsubs:
-                ctx.sub(sub).revert(ctx.substate[sub], *pats, **opts)
+                try:
+                    ctx.sub(sub).revert(ctx.substate[sub], *pats, **opts)
+                except KeyError:
+                    raise util.Abort("subrepository '%s' does not exist in %s!"
+                                      % (sub, short(ctx.node())))