Patchwork largefiles: avoid unnecessary creation of .hg/largefiles when opening lfdirstate

login
register
mail settings
Submitter Matt Harbison
Date July 18, 2014, 3:03 a.m.
Message ID <3b4e692db02e610aa2c9.1405652607@Envy>
Download mbox | patch
Permalink /patch/5184/
State Accepted
Commit ac3b3a2d976d1b8ea8d81920f0f53a6b575c0495
Headers show

Comments

Matt Harbison - July 18, 2014, 3:03 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1405642637 14400
#      Thu Jul 17 20:17:17 2014 -0400
# Node ID 3b4e692db02e610aa2c90067aedc6917ca07bf40
# Parent  08dcb572a45668599ba82bdaf1940d373660b562
largefiles: avoid unnecessary creation of .hg/largefiles when opening lfdirstate

Previously, the directory '.hg/largefiles' would always be created if it didn't
exist when the lfdirstate was opened.  If there were no standin files, no
dirstate file would be created in the directory.  The end result was that
enabling the largefiles extension globally, but not explicitly adding a
largefile would result in the repository eventually sprouting this directory.

Creation of this directory effectively changes readonly operations like summary
and status into operations that require write access.  Without write access,
commands that would succeed without the extension loaded would abort with a
surprising error when the extension is loaded, but not actively used:

  $ hg sum -R /tmp/thg --config extensions.largefiles=
  parent: 16541:00dc703d5aed
   repowidget: specify incoming bundle by plain file path to avoid url parsing
  branch: default
  abort: Permission denied: '/tmp/thg/.hg/largefiles'


This change is simpler than changing the callers of openlfdirstate() to use the
'create' parameter that was introduced in ae57920ac188, and probably how that
should have been implemented in the first place.
Matt Mackall - July 18, 2014, 7:17 p.m.
On Thu, 2014-07-17 at 23:03 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1405642637 14400
> #      Thu Jul 17 20:17:17 2014 -0400
> # Node ID 3b4e692db02e610aa2c90067aedc6917ca07bf40
> # Parent  08dcb572a45668599ba82bdaf1940d373660b562
> largefiles: avoid unnecessary creation of .hg/largefiles when opening lfdirstate

Nice, queued for default.

Patch

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -123,9 +123,13 @@ 
     # it. This ensures that we create it on the first meaningful
     # largefiles operation in a new clone.
     if create and not os.path.exists(os.path.join(lfstoredir, 'dirstate')):
-        util.makedirs(lfstoredir)
         matcher = getstandinmatcher(repo)
-        for standin in repo.dirstate.walk(matcher, [], False, False):
+        standins = repo.dirstate.walk(matcher, [], False, False)
+
+        if len(standins) > 0:
+            util.makedirs(lfstoredir)
+
+        for standin in standins:
             lfile = splitstandin(standin)
             lfdirstate.normallookup(lfile)
     return lfdirstate
diff --git a/tests/test-issue3084.t b/tests/test-issue3084.t
--- a/tests/test-issue3084.t
+++ b/tests/test-issue3084.t
@@ -154,7 +154,20 @@ 
   $ hg init merges
   $ cd merges
   $ touch f1
-  $ hg ci -Aqm "0-root"
+  $ hg ci -Aqm "0-root" --config extensions.largefiles=!
+
+Ensure that .hg/largefiles isn't created before largefiles are added
+#if unix-permissions
+  $ chmod 555 .hg
+#endif
+  $ hg status
+#if unix-permissions
+  $ chmod 755 .hg
+#endif
+
+  $ find .hg/largefiles
+  find: `.hg/largefiles': No such file or directory
+  [1]
 
 ancestor is "normal":
   $ echo normal > f