largefiles: set the extension as enabled locally after a clone requiring it
authorMatt Harbison <matt_harbison@yahoo.com>
Mon, 02 Feb 2015 19:58:41 -0500
changeset 24029 e1dbe0b215ae
parent 24028 a78888d98606
child 24030 828dc8db5515
largefiles: set the extension as enabled locally after a clone requiring it When cloning a repo that requires largefiles, the user had to either enable the extension on the command line and then manually edit the local hgrc file after the clone, or just enable it globally for the user. Since it is a feature of last resort, and materially affects even repos without any largefiles when it is enabled, we should make it easier to not have it enabled globally. This simply adds the enabling statement to the local hgrc if the requires file mandates its use (which only happens after the first largefile is committed). That means that a user who works with a mix of largefile and normal repos can always clone with '--config extensions.largefiles=', and the extension is permanently enabled or not as appropriate. The change in test-largefiles.t is simply because the order of loading rebase and largefiles changed. The same change occurs if the order is flipped in the hgrc file at the top of the test.
hgext/largefiles/overrides.py
tests/test-largefiles.t
tests/test-subrepo-deep-nested-change.t
--- a/hgext/largefiles/overrides.py	Tue Feb 03 16:24:32 2015 -0800
+++ b/hgext/largefiles/overrides.py	Mon Feb 02 19:58:41 2015 -0500
@@ -821,6 +821,14 @@
         sourcerepo, destrepo = result
         repo = destrepo.local()
 
+        # If largefiles is required for this repo, permanently enable it locally
+        if 'largefiles' in repo.requirements:
+            fp = repo.vfs('hgrc', 'a', text=True)
+            try:
+                fp.write('\n[extensions]\nlargefiles=\n')
+            finally:
+                fp.close()
+
         # Caching is implicitly limited to 'rev' option, since the dest repo was
         # truncated at that point.  The user may expect a download count with
         # this option, so attempt whether or not this is a largefile repo.
--- a/tests/test-largefiles.t	Tue Feb 03 16:24:32 2015 -0800
+++ b/tests/test-largefiles.t	Mon Feb 02 19:58:41 2015 -0500
@@ -1183,12 +1183,12 @@
   adding manifests
   adding file changes
   added 1 changesets with 2 changes to 2 files (+1 heads)
-  0 largefiles cached
   rebasing 8:f574fb32bb45 "modify normal file largefile in repo d"
   Invoking status precommit hook
   M sub/normal4
   M sub2/large6
   saved backup bundle to $TESTTMP/d/.hg/strip-backup/f574fb32bb45-dd1d9f80-backup.hg (glob)
+  0 largefiles cached
   $ [ -f .hg/largefiles/e166e74c7303192238d60af5a9c4ce9bef0b7928 ]
   $ hg log --template '{rev}:{node|short}  {desc|firstline}\n'
   9:598410d3eb9a  modify normal file largefile in repo d
--- a/tests/test-subrepo-deep-nested-change.t	Tue Feb 03 16:24:32 2015 -0800
+++ b/tests/test-subrepo-deep-nested-change.t	Mon Feb 02 19:58:41 2015 -0500
@@ -46,12 +46,29 @@
 
 Clone main
 
-  $ hg clone main cloned
+  $ hg --config extensions.largefiles= clone main cloned
   updating to branch default
   cloning subrepo sub1 from $TESTTMP/sub1
   cloning subrepo sub1/sub2 from $TESTTMP/sub2 (glob)
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
+Largefiles is NOT enabled in the clone if the source repo doesn't require it
+  $ cat cloned/.hg/hgrc
+  # example repository config (see "hg help config" for more info)
+  [paths]
+  default = $TESTTMP/main (glob)
+  
+  # path aliases to other clones of this repo in URLs or filesystem paths
+  # (see "hg help config.paths" for more info)
+  #
+  # default-push = ssh://jdoe@example.net/hg/jdoes-fork
+  # my-fork      = ssh://jdoe@example.net/hg/jdoes-fork
+  # my-clone     = /home/jdoe/jdoes-clone
+  
+  [ui]
+  # name and email (local to this repository, optional), e.g.
+  # username = Jane Doe <jdoe@example.com>
+
 Checking cloned repo ids
 
   $ printf "cloned " ; hg id -R cloned
@@ -319,6 +336,31 @@
   ../archive_lf/sub1/sub2/large.bin
   $ rm -rf ../archive_lf
 
+The local repo enables largefiles if a largefiles repo is cloned
+  $ hg showconfig extensions
+  abort: repository requires features unknown to this Mercurial: largefiles!
+  (see http://mercurial.selenic.com/wiki/MissingRequirement for more information)
+  [255]
+  $ hg --config extensions.largefiles= clone -qU . ../lfclone
+  $ cat ../lfclone/.hg/hgrc
+  # example repository config (see "hg help config" for more info)
+  [paths]
+  default = $TESTTMP/cloned (glob)
+  
+  # path aliases to other clones of this repo in URLs or filesystem paths
+  # (see "hg help config.paths" for more info)
+  #
+  # default-push = ssh://jdoe@example.net/hg/jdoes-fork
+  # my-fork      = ssh://jdoe@example.net/hg/jdoes-fork
+  # my-clone     = /home/jdoe/jdoes-clone
+  
+  [ui]
+  # name and email (local to this repository, optional), e.g.
+  # username = Jane Doe <jdoe@example.com>
+  
+  [extensions]
+  largefiles=
+
 Find an exact match to a standin (should archive nothing)
   $ hg --config extensions.largefiles= archive -S -I 'sub/sub2/.hglf/large.bin' ../archive_lf
   $ find ../archive_lf 2> /dev/null | sort