[PATCH] largefiles: adding a file of 2GB causes errors in dirstate (issue3063)

Na'Tosha Bard natosha at unity3d.com
Wed Jan 11 11:19:18 CST 2012


# HG changeset patch
# User Na'Tosha Bard <natosha at unity3d.com>
# Date 1326302335 -3600
# Node ID 605af3cc5dad4bb86f449a872e9eb481e2ab8d74
# Parent  c47d69ce5208d5b5cfd2fb2f0f1d7a2b4795fbf5
largefiles: adding a file of 2GB causes errors in dirstate (issue3063)

Due to limitations of Mercurial's native dirstate, files larger than 2 GB
cannot be added.  Since it's not unlikely users of largefiles will try to
add very large files, this patch checks the file size and politely warns
the user that files greater than 2 GB are not supoprted.

diff -r c47d69ce5208 -r 605af3cc5dad hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py	Wed Jan 11 09:27:53 2012 -0600
+++ b/hgext/largefiles/overrides.py	Wed Jan 11 18:18:55 2012 +0100
@@ -20,6 +20,9 @@
 import lfutil
 import lfcommands
 
+# 2 GB in bytes -- the maximum file size we can support
+_maxsize = 2147483648
+
 # -- Utility functions: commonly/repeatedly needed functionality ---------------
 
 def installnormalfilesmatchfn(manifest):
@@ -99,14 +102,21 @@
         if not opts.get('dry_run'):
             lfdirstate = lfutil.openlfdirstate(ui, repo)
             for f in lfnames:
-                standinname = lfutil.standin(f)
-                lfutil.writestandin(repo, standinname, hash='',
-                    executable=lfutil.getexecutable(repo.wjoin(f)))
-                standins.append(standinname)
-                if lfdirstate[f] == 'r':
-                    lfdirstate.normallookup(f)
+                size = os.lstat(repo.wjoin(f)).st_size
+                # Check size against 2 GB limit
+                if size > _maxsize:
+                    ui.warn(_('not adding %s: file is too large\n')
+                            % f)
+                    ui.warn(_('files greater than 2 GB are not supported\n'))
                 else:
-                    lfdirstate.add(f)
+                    standinname = lfutil.standin(f)
+                    lfutil.writestandin(repo, standinname, hash='',
+                        executable=lfutil.getexecutable(repo.wjoin(f)))
+                    standins.append(standinname)
+                    if lfdirstate[f] == 'r':
+                        lfdirstate.normallookup(f)
+                    else:
+                        lfdirstate.add(f)
             lfdirstate.write()
             bad += [lfutil.splitstandin(f)
                     for f in lfutil.repo_add(repo, standins)


More information about the Mercurial-devel mailing list