[PATCH 3 of 4 STABLE] largefiles: fix a traceback when addremove follows a remove (issue3507)

Matt Harbison matt_harbison at yahoo.com
Fri Jul 20 16:19:04 CDT 2012


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1342710725 14400
# Node ID 80c271cf1203be11aac9afa6326a4cefa857fb6e
# Parent  4cf8aa8986e321ba8de95e6017b20c723f4642e7
largefiles: fix a traceback when addremove follows a remove (issue3507)

The problem only occurred if a file was removed with 'hg rm' (as opposed to the
OS utilities), and then addremove was run before a commit.  Both normal and
large files were affected.

Ensuring that the file exists prior to an lstat() for size seems like the Right
Thing.  But oddly enough, the missing file that was causing lstat() to blow up
was a standin when a largefile was removed, which seems fishy, because a standin
should never be added as a largefile.  I was then able to get a standin added as
a largefile (whose name is 'large') with

   hg addremove --config largefiles.patterns=**large

which also causes a backtrace.  That will be fixed next.

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -82,8 +82,15 @@
             continue
 
         if exact or not exists:
+            wfile = repo.wjoin(f)
+
+            # In case the file was removed previously, but not committed
+            # (issue3507)
+            if not os.path.exists(wfile):
+                continue
+
             abovemin = (lfsize and
-                        os.lstat(repo.wjoin(f)).st_size >= lfsize * 1024 * 1024)
+                        os.lstat(wfile).st_size >= lfsize * 1024 * 1024)
             if large or abovemin or (lfmatcher and lfmatcher(f)):
                 lfnames.append(f)
                 if ui.verbose or not exact:
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -440,6 +440,55 @@
   C sub2/large6
   C sub2/large7
   $ hg st
+
+Test 3507 (both normal files and largefiles were a problem)
+
+  $ touch normal
+  $ touch large
+  $ hg add normal
+  $ hg add --large large
+  $ hg ci -m "added"
+  Invoking status precommit hook
+  A large
+  A normal
+  Invoking status postcommit hook
+  C large
+  C normal
+  C normal3
+  C sub/large4
+  C sub/normal4
+  C sub2/large6
+  C sub2/large7
+  $ hg remove normal
+  $ hg addremove --traceback
+  $ hg ci -m "addremoved normal"
+  Invoking status precommit hook
+  R normal
+  Invoking status postcommit hook
+  C large
+  C normal3
+  C sub/large4
+  C sub/normal4
+  C sub2/large6
+  C sub2/large7
+  $ hg up -C '.^'
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  getting changed largefiles
+  0 largefiles updated, 0 removed
+  $ hg remove large
+  $ hg addremove --traceback
+  $ hg ci -m "removed large"
+  Invoking status precommit hook
+  R large
+  created new head
+  Invoking status postcommit hook
+  C normal
+  C normal3
+  C sub/large4
+  C sub/normal4
+  C sub2/large6
+  C sub2/large7
+
   $ cd ../a
 
 Clone a largefiles repo.


More information about the Mercurial-devel mailing list