[PATCH 1 of 2] subrepo/svn: fix checked out rev number retrieval (issue2968)

Patrick Mezard patrick at mezard.eu
Mon Apr 30 10:31:40 CDT 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1335798195 -7200
# Branch stable
# Node ID 8d99310d751a94ce2bfe2c97709f5b7e25d169fe
# Parent  be786c5ac0a852cab965d9e541611f882bdb0bb8
subrepo/svn: fix checked out rev number retrieval (issue2968)

The initial version was to take the "Revision" field from svn info. It works
but produces false positive when parent paths are being moved or unrelated
changes are being committed, causing it to change while the svn checkout itself
remains the same. To avoid spurious commit, we took "Revision" and "Last
Changed Rev" for general comparison and kept the latter to answer "what is your
revision?" question. This is better but fails when the subrepo path exists at
"Revision" but not at "Last Changed Rev". This patch adds a check for this, and
returns "Revision" if the path does not exist. We try to avoid doing this as
much as possible at it implies an extra, *remote* call.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -715,13 +715,24 @@
         return True
 
     def basestate(self):
-        return self._wcrev()
+        lastrev, rev = self._wcrevs()
+        if lastrev != rev:
+            # Last committed rev is not the same than rev. We would
+            # like to take lastrev but we do not know if the subrepo
+            # URL exists at lastrev.  Test it and fallback to rev it
+            # is not there.
+            try:
+                self._svncommand(['info', '%s@%s' % (self._state[0], lastrev)])
+                return lastrev
+            except error.Abort:
+                pass
+        return rev
 
     def commit(self, text, user, date):
         # user and date are out of our hands since svn is centralized
         changed, extchanged, missing = self._wcchanged()
         if not changed:
-            return self._wcrev()
+            return self.basestate()
         if extchanged:
             # Do not try to commit externals
             raise util.Abort(_('cannot commit svn externals'))
diff --git a/tests/test-subrepo-svn.t b/tests/test-subrepo-svn.t
--- a/tests/test-subrepo-svn.t
+++ b/tests/test-subrepo-svn.t
@@ -564,3 +564,42 @@
   $ hg forget 'notafile*'
   notafile*: No such file or directory
   [1]
+
+Test a subrepo referencing a just moved svn path. Last commit rev will
+be different from the revision, and the path will be different as
+well.
+
+  $ cd $WCROOT
+  $ svn up > /dev/null
+  $ mkdir trunk/subdir branches
+  $ echo a > trunk/subdir/a
+  $ svn add trunk/subdir branches
+  A         trunk/subdir
+  A         trunk/subdir/a
+  A         branches
+  $ svn ci -m addsubdir
+  Adding         branches
+  Adding         trunk/subdir
+  Adding         trunk/subdir/a
+  Transmitting file data .
+  Committed revision 14.
+  $ svn cp -m branchtrunk $SVNREPO/trunk $SVNREPO/branches/somebranch
+  
+  Committed revision 15.
+  $ cd ..
+
+  $ hg init repo2
+  $ cd repo2
+  $ svn co $SVNREPO/branches/somebranch/subdir
+  A    subdir/a
+  Checked out revision 15.
+  $ echo "subdir = [svn] $SVNREPO/branches/somebranch/subdir" > .hgsub
+  $ hg add .hgsub
+  $ hg ci -m addsub
+  $ hg up null
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ hg up
+  A    *subdir/a (glob)
+  Checked out revision 15.
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd ..


More information about the Mercurial-devel mailing list