largefiles: fix a traceback when addremove follows a remove (issue3507) stable
authorMatt Harbison <matt_harbison@yahoo.com>
Thu, 19 Jul 2012 11:12:05 -0400
branchstable
changeset 17231 2446b63c89ec
parent 17230 fc4c155658b7
child 17232 25248e2ebaee
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.
hgext/largefiles/overrides.py
tests/test-largefiles.t
--- a/hgext/largefiles/overrides.py	Thu Jul 19 10:00:15 2012 -0400
+++ b/hgext/largefiles/overrides.py	Thu Jul 19 11:12:05 2012 -0400
@@ -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:
--- a/tests/test-largefiles.t	Thu Jul 19 10:00:15 2012 -0400
+++ b/tests/test-largefiles.t	Thu Jul 19 11:12:05 2012 -0400
@@ -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.