changeset 38769:7e023ce26c7f stable

convert: don't drop missing or corrupt tag entries Cleaning up the tags file could be a useful feature in some cases, so maybe there should be a switch for this. However, the default hg -> hg convert tries to maintain identical hashes (thus convert.hg.saverev is off by default, but is on by default for other source types). It looks like _rewritesubstate() has a `continue` in it, and therefore a similar problem. I ran into this conversion divergence when a coworker "merged" two repositories by copy/pasting all of the files from the source repo and massaging the code, and forgetting to revert the .hg* files. That silently emptied the .hgtags file after the conversion. (This isn't the manifest node bug Yuya has been helping with- this occurred well after the bzr -> hg conversion and wasn't a merge commit, which made it extra puzzling. That bug is still an issue.)
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 14 Aug 2018 14:00:35 -0400
parents 5caee9f923ae
children 3730b779ed5b 08b2ae9fc030
files hgext/convert/hg.py tests/test-convert-hg-sink.t
diffstat 2 files changed, 28 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/hg.py	Thu Aug 09 13:04:52 2018 +0800
+++ b/hgext/convert/hg.py	Tue Aug 14 14:00:35 2018 -0400
@@ -143,12 +143,17 @@
         for line in data.splitlines():
             s = line.split(' ', 1)
             if len(s) != 2:
+                self.ui.warn(_('invalid tag entry: "%s"\n') % line)
+                fp.write('%s\n' % line)  # Bogus, but keep for hash stability
                 continue
             revid = revmap.get(source.lookuprev(s[0]))
             if not revid:
                 if s[0] == nodemod.nullhex:
                     revid = s[0]
                 else:
+                    # missing, but keep for hash stability
+                    self.ui.warn(_('missing tag entry: "%s"\n') % line)
+                    fp.write('%s\n' % line)
                     continue
             fp.write('%s %s\n' % (revid, s[1]))
         return fp.getvalue()
--- a/tests/test-convert-hg-sink.t	Thu Aug 09 13:04:52 2018 +0800
+++ b/tests/test-convert-hg-sink.t	Tue Aug 14 14:00:35 2018 -0400
@@ -17,10 +17,17 @@
   $ hg ci -qAm 'add foo/file'
   $ hg tag some-tag
   $ hg tag -l local-tag
+  $ echo '1234567890123456789012345678901234567890 missing_tag' >> .hgtags
+  $ hg ci -m 'add a missing tag'
   $ hg log
+  changeset:   4:3fb95ee23a66
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add a missing tag
+  
   changeset:   3:593cbf6fb2b4
   tag:         local-tag
-  tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     Added tag some-tag for changeset ad681a868e44
@@ -48,12 +55,16 @@
   scanning source...
   sorting...
   converting...
-  3 add foo and bar
-  2 remove foo
-  1 add foo/file
-  0 Added tag some-tag for changeset ad681a868e44
+  4 add foo and bar
+  3 remove foo
+  2 add foo/file
+  1 Added tag some-tag for changeset ad681a868e44
+  0 add a missing tag
+  missing tag entry: "1234567890123456789012345678901234567890 missing_tag"
   $ cd new
   $ hg log -G --template '{rev} {node|short} ({phase}) "{desc}"\n'
+  o  4 3fb95ee23a66 (public) "add a missing tag"
+  |
   o  3 593cbf6fb2b4 (public) "Added tag some-tag for changeset ad681a868e44"
   |
   o  2 ad681a868e44 (public) "add foo/file"
@@ -125,14 +136,16 @@
   scanning source...
   sorting...
   converting...
-  4 add foo and bar
-  3 remove foo
-  2 add foo/file
-  1 Added tag some-tag for changeset ad681a868e44
+  5 add foo and bar
+  4 remove foo
+  3 add foo/file
+  2 Added tag some-tag for changeset ad681a868e44
+  1 add a missing tag
+  missing tag entry: "1234567890123456789012345678901234567890 missing_tag"
   0 add baz
   $ cd new-filemap
   $ hg tags
-  tip                                2:3c74706b1ff8
+  tip                                3:7bb553f2c68a
   some-tag                           0:ba8636729451
   $ cd ..