[PATCH 1 of 2 STABLE] largefiles: fix a traceback in lfconvert if a largefile is missing (issue3519)

Matt Harbison matt_harbison at yahoo.com
Sun Oct 14 19:40:24 CDT 2012


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1350240248 14400
# Branch stable
# Node ID 7511497ca804329869060fa2b37262e41640a8d8
# Parent  605fe310691fbe1579ca8458f9f640d921ce3f1e
largefiles: fix a traceback in lfconvert if a largefile is missing (issue3519)

The largefile may be missing for various reasons, including that a remote
repository was cloned without the --all-largefiles option.  Therefore, it seems
reasonable to attempt to download the missing files and failing that, abort and
indicate the affected file and revision so the user can manually fix the
problem.

diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -16,7 +16,7 @@
 from mercurial.i18n import _
 from mercurial.lock import release
 
-import lfutil
+import lfutil, lfcommands
 import basestore
 
 # -- Commands ----------------------------------------------------------
@@ -141,7 +141,17 @@
 
             hash = fctx.data().strip()
             path = lfutil.findfile(rsrc, hash)
-            ### TODO: What if the file is not cached?
+
+            # If one file is missing, likely all files from this rev are
+            if path is None:
+                lfcommands.cachelfiles(ui, rsrc, ctx.node())
+                path = lfutil.findfile(rsrc, hash)
+
+                if path is None:
+                    raise util.Abort(
+                        _("missing largefile \'%s\' from revision %s")
+                         % (f, node.hex(ctx.node())))
+
             data = ''
             fd = None
             try:
diff --git a/tests/test-lfconvert.t b/tests/test-lfconvert.t
--- a/tests/test-lfconvert.t
+++ b/tests/test-lfconvert.t
@@ -1,3 +1,5 @@
+  $ USERCACHE="$TESTTMP/cache"; export USERCACHE
+  $ mkdir "${USERCACHE}"
   $ cat >> $HGRCPATH <<EOF
   > [extensions]
   > largefiles =
@@ -8,6 +10,7 @@
   > minsize = 0.5
   > patterns = **.other
   >     **.dat
+  > usercache=${USERCACHE}
   > EOF
 
 "lfconvert" works
@@ -270,3 +273,14 @@
   pass
 
   $ cd ..
+
+Avoid a traceback if a largefile isn't available (issue3519)
+
+  $ hg clone -U largefiles-repo issue3519
+  $ rm "${USERCACHE}"/*
+  $ hg lfconvert --to-normal issue3519 normalized3519
+  initializing destination normalized3519
+  abort: missing largefile 'large' from revision d4892ec57ce212905215fad1d9018f56b99202ad
+  [255]
+
+


More information about the Mercurial-devel mailing list