[PATCH 2 of 2] subrepo/svn: improve error message on missing files

Patrick Mezard patrick at mezard.eu
Thu Apr 26 05:18:22 CDT 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1335435200 -7200
# Branch stable
# Node ID aefc68d8ba1e3631cd8d0bba936d3eee30023045
# Parent  24e35aca83788861d715fd1149edb4a82009a47e
subrepo/svn: improve error message on missing files

From:

  abort: failed to commit svn changes

to:

  abort: cannot commit missing svn entries

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -680,12 +680,13 @@
         return self._wcrevs()[0]
 
     def _wcchanged(self):
-        """Return (changes, extchanges) where changes is True
-        if the working directory was changed, and extchanges is
-        True if any of these changes concern an external entry.
+        """Return (changes, extchanges, missing) where changes is True
+        if the working directory was changed, extchanges is
+        True if any of these changes concern an external entry and missing
+        is True if any change is a missing entry.
         """
         output, err = self._svncommand(['status', '--xml'])
-        externals, changes = [], []
+        externals, changes, missing = [], [], []
         doc = xml.dom.minidom.parseString(output)
         for e in doc.getElementsByTagName('entry'):
             s = e.getElementsByTagName('wc-status')
@@ -696,14 +697,16 @@
             path = e.getAttribute('path')
             if item == 'external':
                 externals.append(path)
+            elif item == 'missing':
+                missing.append(path)
             if (item not in ('', 'normal', 'unversioned', 'external')
                 or props not in ('', 'none', 'normal')):
                 changes.append(path)
         for path in changes:
             for ext in externals:
                 if path == ext or path.startswith(ext + os.sep):
-                    return True, True
-        return bool(changes), False
+                    return True, True, bool(missing)
+        return bool(changes), False, bool(missing)
 
     def dirty(self, ignoreupdate=False):
         if not self._wcchanged()[0]:
@@ -716,12 +719,16 @@
 
     def commit(self, text, user, date):
         # user and date are out of our hands since svn is centralized
-        changed, extchanged = self._wcchanged()
+        changed, extchanged, missing = self._wcchanged()
         if not changed:
             return self._wcrev()
         if extchanged:
             # Do not try to commit externals
             raise util.Abort(_('cannot commit svn externals'))
+        if missing:
+            # svn can commit with missing entries but aborting like hg
+            # seems a better approach.
+            raise util.Abort(_('cannot commit missing svn entries'))
         commitinfo, err = self._svncommand(['commit', '-m', text])
         self._ui.status(commitinfo)
         newrev = re.search('Committed revision ([0-9]+).', commitinfo)
@@ -773,7 +780,7 @@
         status, err = self._svncommand(args, failok=True)
         if not re.search('Checked out revision [0-9]+.', status):
             if ('is already a working copy for a different URL' in err
-                and (self._wcchanged() == (False, False))):
+                and (self._wcchanged()[:2] == (False, False))):
                 # obstructed but clean working copy, so just blow it away.
                 self.remove()
                 self.get(state, overwrite=False)
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
@@ -125,7 +125,7 @@
   $ rm s/alpha
   $ hg commit --subrepos -m 'abort on missing file'
   committing subrepository s
-  abort: failed to commit svn changes
+  abort: cannot commit missing svn entries
   [255]
   $ svn revert s/alpha > /dev/null
 


More information about the Mercurial-devel mailing list