convert/git: check status when reading output stream stable
authorPatrick Mezard <pmezard@gmail.com>
Sun, 25 Apr 2010 23:07:46 +0200
branchstable
changeset 10987 b3af02b1f19f
parent 10986 610f047326b9
child 10988 f2340d699e79
child 10990 bb377a311109
convert/git: check status when reading output stream
hgext/convert/git.py
tests/test-convert-git
tests/test-convert-git.out
--- a/hgext/convert/git.py	Sun Apr 25 22:59:50 2010 +0200
+++ b/hgext/convert/git.py	Sun Apr 25 23:07:46 2010 +0200
@@ -94,6 +94,8 @@
                 self.modecache[(f, h)] = (p and "x") or (s and "l") or ""
                 changes.append((f, h))
             entry = None
+        if fh.close():
+            raise util.Abort(_('cannot read changes in %s') % version)
         return (changes, {})
 
     def getcommit(self, version):
@@ -144,6 +146,8 @@
                 continue
             tag = tag[len(prefix):-3]
             tags[tag] = node
+        if fh.close():
+            raise util.Abort(_('cannot read tags from %s') % self.path)
 
         return tags
 
@@ -156,11 +160,11 @@
                     continue
                 m, f = l[:-1].split("\t")
                 changes.append(f)
-            fh.close()
         else:
             fh = self.gitopen('git diff-tree --name-only --root -r %s "%s^%s" --'
                              % (version, version, i + 1))
             changes = [f.rstrip('\n') for f in fh]
-            fh.close()
+        if fh.close():
+            raise util.Abort(_('cannot read changes in %s') % version)
 
         return changes
--- a/tests/test-convert-git	Sun Apr 25 22:59:50 2010 +0200
+++ b/tests/test-convert-git	Sun Apr 25 23:07:46 2010 +0200
@@ -170,4 +170,17 @@
 echo '% --sourceorder should fail'
 hg convert --sourcesort git-repo4 git-repo4-sourcesort-hg
 
+echo '% damage git repository and convert again'
+cat > damage.py <<EOF
+import os
+for root, dirs, files in os.walk('git-repo4/.git/objects'):
+    if files:
+        path = os.path.join(root, files[0])
+        os.remove(path)
+        break
+EOF
+python damage.py
+hg convert git-repo4 git-repo4-broken-hg 2>&1 | \
+    sed 's/fatal:.*/fatal: git error/g'
+
 true
--- a/tests/test-convert-git.out	Sun Apr 25 22:59:50 2010 +0200
+++ b/tests/test-convert-git.out	Sun Apr 25 23:07:46 2010 +0200
@@ -127,3 +127,11 @@
 % --sourceorder should fail
 initializing destination git-repo4-sourcesort-hg repository
 abort: --sourcesort is not supported by this data source
+% damage git repository and convert again
+fatal: git error
+initializing destination git-repo4-broken-hg repository
+scanning source...
+sorting...
+converting...
+1 addfoo
+abort: cannot read changes in 6a101ac3f6d8b2524a64295ffd9be87ed927bfeb