[PATCH 2 of 4] largefiles: add error checking to tags conversion (issue3092)

Levi Bard taktaktaktaktaktaktaktaktaktak at gmail.com
Sun Jan 8 16:50:02 UTC 2012


# HG changeset patch
# User Levi Bard <levi at unity3d.com>
# Date 1326038794 -3600
# Node ID 7189d10c07aac2490f4d731e5fee30d6ce8a807b
# Parent  14749224f9f765d841d8466abc335f9f284237ea
largefiles: add error checking to tags conversion (issue3092)

Check for errors when parsing .hgtags during lfconvert,
and skip lines that don't parse or refer to invalid changesets.

diff -r 14749224f9f7 -r 7189d10c07aa hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py	Sun Jan 08 17:03:39 2012 +0100
+++ b/hgext/largefiles/lfcommands.py	Sun Jan 08 17:06:34 2012 +0100
@@ -295,9 +295,24 @@
             if f == '.hgtags':
                 newdata = []
                 for line in data.splitlines():
-                    id, name = line.split(' ', 1)
-                    newdata.append('%s %s\n' % (node.hex(revmap[node.bin(id)]),
-                        name))
+                    try:
+                        id, name = line.split(' ', 1)
+                    except ValueError:
+                        repo.ui.warn(_('skipping incorrectly formatted tag %s\n'
+                            % line))
+                        continue
+                    try:
+                        newid = node.bin(id)
+                    except TypeError:
+                        repo.ui.warn(_('skipping incorrectly formatted id %s\n'
+                            % id))
+                        continue
+                    try:
+                        newdata.append('%s %s\n' % (node.hex(revmap[newid]),
+                            name))
+                    except KeyError:
+                        repo.ui.warn(_('no mapping for id %s\n' % id))
+                        continue
                 data = ''.join(newdata)
             return context.memfilectx(f, data, 'l' in fctx.flags(),
                                       'x' in fctx.flags(), renamed)



More information about the Mercurial-devel mailing list