Commits

Patrick Mézard committed 297e2b4

editor: add addmissing() and test config to make it fail

Missing files should be the exception not the norm. Right now, a lot of
these are caused by incorrect handling of branch updates. The
hgsubversion.failonmissing configuration entry will help chase them.

Comments (0)

Files changed (1)

hgsubversion/editor.py

     __slots__ = [
         'file', 'added', 'deleted', 'rev', 'execfiles', 'symlinks', 'batons',
         'copies', 'missing', 'emptybranches', 'base', 'externals', 'ui',
-        'exception', 'store',
+        'exception', 'store', '_failonmissing',
     ]
 
     def __init__(self, ui):
         # Map fully qualified destination file paths to module source path
         self.copies = {}
         self.missing = set()
+        # Used in tests and debugging
+        self._failonmissing = self.ui.config(
+            'hgsubversion', 'failonmissing', False)
         self.emptybranches = {}
         self.externals = {}
         self.exception = None
             files.update(g)
         return sorted(files)
 
+    def addmissing(self, path):
+        if self._failonmissing:
+            raise EditingError('missing entry: %s' % path)
+        self.missing.add(path)
+
     def findmissing(self, svn):
 
         if not self.missing:
         parent = self.meta.get_parent_revision(baserev + 1, branch, True)
         ctx = self.repo[parent]
         if fpath not in ctx:
-            self.current.missing.add(path)
+            self.current.addmissing(path)
             return None
 
         fctx = ctx.filectx(fpath)
         (from_file,
          from_branch) = self.meta.split_branch_path(copyfrom_path)[:2]
         if not from_file:
-            self.current.missing.add(path)
+            self.current.addmissing(path)
             return None
         # Use exact=True because during replacements ('R' action) we select
         # replacing branch as parent, but svn delta editor provides delta
                                            from_branch, True)
         ctx = self.repo.changectx(ha)
         if from_file not in ctx:
-            self.current.missing.add(path)
+            self.current.addmissing(path)
             return None
 
         fctx = ctx.filectx(from_file)
         if tag not in self.meta.tags:
             tag = None
             if not self.meta.is_path_valid(copyfrom_path):
-                self.current.missing.add('%s/' % path)
+                self.current.addmissing('%s/' % path)
                 return path
         if tag:
             changeid = self.meta.tags[tag]
                 self.meta.branches[branch] = tmp
         new_hash = self.meta.get_parent_revision(source_rev + 1, source_branch, True)
         if new_hash == node.nullid:
-            self.current.missing.add('%s/' % path)
+            self.current.addmissing('%s/' % path)
             return path
         fromctx = self.repo.changectx(new_hash)
         if frompath != '/' and frompath != '':
                         path, target, isexec, islink, copypath)
             except svnwrap.SubversionException, e: # pragma: no cover
                 if e.args[1] == svnwrap.ERR_INCOMPLETE_DATA:
-                    self.current.missing.add(path)
+                    self.current.addmissing(path)
                 else: # pragma: no cover
                     raise hgutil.Abort(*e.args)
             except: # pragma: no cover
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.