Patchwork [2,of,2] largefiles: set the extension as enabled locally after a share requiring it

login
register
mail settings
Submitter Matt Harbison
Date April 12, 2017, 2:42 a.m.
Message ID <9b4202740173227e2326.1491964963@Envy>
Download mbox | patch
Permalink /patch/20126/
State Accepted
Headers show

Comments

Matt Harbison - April 12, 2017, 2:42 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1491958490 14400
#      Tue Apr 11 20:54:50 2017 -0400
# Node ID 9b4202740173227e232659964725c4152d87e469
# Parent  ef3aa25da8e5b3137b917e9a1756df7a7eac5c3a
largefiles: set the extension as enabled locally after a share requiring it

This has been done for clone since e1dbe0b215ae, so it makes sense here for the
same reasons.
Augie Fackler - April 12, 2017, 8:15 p.m.
On Tue, Apr 11, 2017 at 10:42:43PM -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1491958490 14400
> #      Tue Apr 11 20:54:50 2017 -0400
> # Node ID 9b4202740173227e232659964725c4152d87e469
> # Parent  ef3aa25da8e5b3137b917e9a1756df7a7eac5c3a
> largefiles: set the extension as enabled locally after a share requiring it

Sure, queued, thanks.

>
> This has been done for clone since e1dbe0b215ae, so it makes sense here for the
> same reasons.
>
> diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
> --- a/hgext/largefiles/overrides.py
> +++ b/hgext/largefiles/overrides.py
> @@ -903,6 +903,14 @@
>
>      return result
>
> +def hgpostshare(orig, sourcerepo, destrepo, bookmarks=True, defaultpath=None):
> +    orig(sourcerepo, destrepo, bookmarks, defaultpath)
> +
> +    # If largefiles is required for this repo, permanently enable it locally
> +    if 'largefiles' in destrepo.requirements:
> +        with destrepo.vfs('hgrc', 'a+', text=True) as fp:
> +            fp.write('\n[extensions]\nlargefiles=\n')
> +
>  def overriderebase(orig, ui, repo, **opts):
>      if not util.safehasattr(repo, '_largefilesenabled'):
>          return orig(ui, repo, **opts)
> diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
> --- a/hgext/largefiles/uisetup.py
> +++ b/hgext/largefiles/uisetup.py
> @@ -120,6 +120,7 @@
>                   _('download all versions of all largefiles'))]
>      entry[1].extend(cloneopt)
>      entry = extensions.wrapfunction(hg, 'clone', overrides.hgclone)
> +    entry = extensions.wrapfunction(hg, 'postshare', overrides.hgpostshare)
>
>      entry = extensions.wrapcommand(commands.table, 'cat',
>                                     overrides.overridecat)
> diff --git a/tests/test-largefiles-misc.t b/tests/test-largefiles-misc.t
> --- a/tests/test-largefiles-misc.t
> +++ b/tests/test-largefiles-misc.t
> @@ -212,6 +212,18 @@
>    date:        Thu Jan 01 00:00:00 1970 +0000
>    summary:     add files
>
> +sharing a largefile repo automatically enables largefiles on the share
> +
> +  $ hg share --config extensions.share= . ../shared_lfrepo
> +  updating working directory
> +  getting changed largefiles
> +  1 largefiles updated, 0 removed
> +  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  $ cat ../shared_lfrepo/.hg/hgrc
> +
> +  [extensions]
> +  largefiles=
> +
>  verify that large files in subrepos handled properly
>    $ hg init subrepo
>    $ echo "subrepo = subrepo" > .hgsub
> diff --git a/tests/test-share.t b/tests/test-share.t
> --- a/tests/test-share.t
> +++ b/tests/test-share.t
> @@ -240,6 +240,14 @@
>       bm3                       4:62f4ded848e4
>    $ cd ..
>
> +non largefiles repos won't enable largefiles
> +
> +  $ hg share --config extensions.largefiles= repo3 sharedrepo
> +  updating working directory
> +  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  $ [ -f sharedrepo/.hg/hgrc ]
> +  [1]
> +
>  test pushing bookmarks works
>
>    $ hg clone repo3 repo4
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -903,6 +903,14 @@ 
 
     return result
 
+def hgpostshare(orig, sourcerepo, destrepo, bookmarks=True, defaultpath=None):
+    orig(sourcerepo, destrepo, bookmarks, defaultpath)
+
+    # If largefiles is required for this repo, permanently enable it locally
+    if 'largefiles' in destrepo.requirements:
+        with destrepo.vfs('hgrc', 'a+', text=True) as fp:
+            fp.write('\n[extensions]\nlargefiles=\n')
+
 def overriderebase(orig, ui, repo, **opts):
     if not util.safehasattr(repo, '_largefilesenabled'):
         return orig(ui, repo, **opts)
diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -120,6 +120,7 @@ 
                  _('download all versions of all largefiles'))]
     entry[1].extend(cloneopt)
     entry = extensions.wrapfunction(hg, 'clone', overrides.hgclone)
+    entry = extensions.wrapfunction(hg, 'postshare', overrides.hgpostshare)
 
     entry = extensions.wrapcommand(commands.table, 'cat',
                                    overrides.overridecat)
diff --git a/tests/test-largefiles-misc.t b/tests/test-largefiles-misc.t
--- a/tests/test-largefiles-misc.t
+++ b/tests/test-largefiles-misc.t
@@ -212,6 +212,18 @@ 
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     add files
   
+sharing a largefile repo automatically enables largefiles on the share
+
+  $ hg share --config extensions.share= . ../shared_lfrepo
+  updating working directory
+  getting changed largefiles
+  1 largefiles updated, 0 removed
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cat ../shared_lfrepo/.hg/hgrc
+  
+  [extensions]
+  largefiles=
+
 verify that large files in subrepos handled properly
   $ hg init subrepo
   $ echo "subrepo = subrepo" > .hgsub
diff --git a/tests/test-share.t b/tests/test-share.t
--- a/tests/test-share.t
+++ b/tests/test-share.t
@@ -240,6 +240,14 @@ 
      bm3                       4:62f4ded848e4
   $ cd ..
 
+non largefiles repos won't enable largefiles
+
+  $ hg share --config extensions.largefiles= repo3 sharedrepo
+  updating working directory
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ [ -f sharedrepo/.hg/hgrc ]
+  [1]
+
 test pushing bookmarks works
 
   $ hg clone repo3 repo4