[PATCH 3 of 4] largefiles: enable subrepo support for add

Matt Harbison mharbison72 at gmail.com
Thu Jan 15 21:39:55 CST 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1421117083 18000
#      Mon Jan 12 21:44:43 2015 -0500
# Node ID 46fd3fdff1e68afbc4b66ed1960d696ed5e67124
# Parent  c9313d348ff8b373820e49359b03950875e737dc
largefiles: enable subrepo support for add

The --large, --normal and --lfsize args couldn't be passed to a subrepo before,
and files in the subrepos would be added silently (if -v wasn't specified) as
normal files.  As an added bonus, 'hg add --dry-run' no longer prints that
largefiles would also be added as normal files as well.

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -242,23 +242,25 @@
 
 # -- Wrappers: modify existing commands --------------------------------
 
-# Add works by going through the files that the user wanted to add and
-# checking if they should be added as largefiles. Then it makes a new
-# matcher which matches only the normal files and runs the original
-# version of add.
 def overrideadd(orig, ui, repo, *pats, **opts):
     normal = opts.get('normal')
     if normal:
         if opts.get('large'):
             raise util.Abort(_('--normal cannot be used with --large'))
-        return orig(ui, repo, *pats, **opts)
-    matcher = scmutil.match(repo[None], pats, opts)
-    added, bad = addlargefiles(ui, repo, False, matcher, **opts)
-    installnormalfilesmatchfn(repo[None].manifest())
-    result = orig(ui, repo, *pats, **opts)
-    restorematchfn()
+    return orig(ui, repo, *pats, **opts)
 
-    return (result == 1 or bad) and 1 or 0
+def cmdutiladd(orig, ui, repo, matcher, prefix, explicitonly, **opts):
+    # The --normal flag short circuits this override
+    if opts.get('normal'):
+        return orig(ui, repo, matcher, prefix, explicitonly, **opts)
+
+    ladded, lbad = addlargefiles(ui, repo, False, matcher, **opts)
+    normalmatcher = composenormalfilematcher(matcher, repo[None].manifest(),
+                                             ladded)
+    bad = orig(ui, repo, normalmatcher, prefix, explicitonly, **opts)
+
+    bad.extend(f for f in lbad)
+    return bad
 
 def cmdutilremove(orig, ui, repo, matcher, prefix, after, force, subrepos):
     normalmatcher = composenormalfilematcher(matcher, repo[None].manifest())
diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -33,6 +33,7 @@
     # and in the process of handling commit -A (issue3542)
     entry = extensions.wrapfunction(scmutil, 'addremove',
                                     overrides.scmutiladdremove)
+    extensions.wrapfunction(cmdutil, 'add', overrides.cmdutiladd)
     extensions.wrapfunction(cmdutil, 'remove', overrides.cmdutilremove)
     extensions.wrapfunction(cmdutil, 'forget', overrides.cmdutilforget)
 
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
@@ -214,7 +214,7 @@
   A .hgsub
   ? .hgsubstate
   $ echo "rev 1" > subrepo/large.txt
-  $ hg -R subrepo add --large subrepo/large.txt
+  $ hg add --large subrepo/large.txt
   $ hg sum
   parent: 1:8ee150ea2e9c tip
    add subrepo
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -326,19 +326,27 @@
   $ cat >> $HGRCPATH <<EOF
   > [extensions]
   > largefiles=
+  > [largefiles]
+  > patterns=glob:**.dat
   > EOF
 
 Test forget through a deep subrepo with the largefiles extension, both a
 largefile and a normal file.  Then a largefile that hasn't been committed yet.
   $ touch sub1/sub2/untracked.txt
+  $ touch sub1/sub2/large.dat
   $ hg forget sub1/sub2/large.bin sub1/sub2/test.txt sub1/sub2/untracked.txt
   not removing sub1/sub2/untracked.txt: file is already untracked (glob)
   [1]
-  $ hg add -v --large -R sub1/sub2 sub1/sub2/untracked.txt
+  $ hg add --large --dry-run -v sub1/sub2/untracked.txt
   adding sub1/sub2/untracked.txt as a largefile (glob)
+  $ hg add --large -v sub1/sub2/untracked.txt
+  adding sub1/sub2/untracked.txt as a largefile (glob)
+  $ hg add --normal -v sub1/sub2/large.dat
+  adding sub1/sub2/large.dat (glob)
   $ hg forget -v sub1/sub2/untracked.txt
   removing sub1/sub2/untracked.txt (glob)
   $ hg status -S
+  A sub1/sub2/large.dat
   R sub1/sub2/large.bin
   R sub1/sub2/test.txt
   ? foo/bar/abc


More information about the Mercurial-devel mailing list