Patchwork [2,of,4] add: pass options via keyword args

login
register
mail settings
Submitter Matt Harbison
Date Jan. 16, 2015, 3:39 a.m.
Message ID <c9313d348ff8b373820e.1421379594@Envy>
Download mbox | patch
Permalink /patch/7478/
State Accepted
Headers show

Comments

Matt Harbison - Jan. 16, 2015, 3:39 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1421114357 18000
#      Mon Jan 12 20:59:17 2015 -0500
# Node ID c9313d348ff8b373820e49359b03950875e737dc
# Parent  6c893ee9c85def62e2f19de9f4a2b5288a12a5fd
add: pass options via keyword args

The largefiles extensions needs to be able to pass --large, --normal and
--lfsize to subrepos via cmdutil.add() and hgsubrepo.add().  Rather than add
additional special purpose arguments, stop extracting the existing args from the
**opts passed to commands.add() and just pass them along.
Mads Kiilerich - Jan. 16, 2015, 4 a.m.
On 01/16/2015 04:39 AM, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1421114357 18000
> #      Mon Jan 12 20:59:17 2015 -0500
> # Node ID c9313d348ff8b373820e49359b03950875e737dc
> # Parent  6c893ee9c85def62e2f19de9f4a2b5288a12a5fd
> add: pass options via keyword args
>
> The largefiles extensions needs to be able to pass --large, --normal and
> --lfsize to subrepos via cmdutil.add() and hgsubrepo.add().  Rather than add
> additional special purpose arguments, stop extracting the existing args from the
> **opts passed to commands.add() and just pass them along.

I guess this patch should come before patch 1 to make sure every 
revision in history works?

/Mads
Matt Harbison - Jan. 16, 2015, 4:20 a.m.
On Thu, 15 Jan 2015 23:00:58 -0500, Mads Kiilerich <mads@kiilerich.com>  
wrote:

> On 01/16/2015 04:39 AM, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison@yahoo.com>
>> # Date 1421114357 18000
>> #      Mon Jan 12 20:59:17 2015 -0500
>> # Node ID c9313d348ff8b373820e49359b03950875e737dc
>> # Parent  6c893ee9c85def62e2f19de9f4a2b5288a12a5fd
>> add: pass options via keyword args
>>
>> The largefiles extensions needs to be able to pass --large, --normal and
>> --lfsize to subrepos via cmdutil.add() and hgsubrepo.add().  Rather  
>> than add
>> additional special purpose arguments, stop extracting the existing args  
>> from the
>> **opts passed to commands.add() and just pass them along.
>
> I guess this patch should come before patch 1 to make sure every  
> revision in history works?

Not sure I understand.  The test suite (at least '*large*', just now) runs  
clean with only #1 applied, and also 1 + 2.  There's no behavior change  
until #3, when the subrepo can call back into largefiles code via the  
cmdutil override.

But if you think they are better reordered, I have no issue with someone  
doing that in flight.

--Matt

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1979,7 +1979,7 @@ 
         nodes = nodes[:limit]
     return graphmod.nodes(repo, nodes)
 
-def add(ui, repo, match, dryrun, listsubrepos, prefix, explicitonly):
+def add(ui, repo, match, prefix, explicitonly, **opts):
     join = lambda f: os.path.join(prefix, f)
     bad = []
     oldbad = match.bad
@@ -2003,17 +2003,15 @@ 
         sub = wctx.sub(subpath)
         try:
             submatch = matchmod.narrowmatcher(subpath, match)
-            if listsubrepos:
-                bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
-                                   False))
+            if opts.get('subrepos'):
+                bad.extend(sub.add(ui, submatch, prefix, False, **opts))
             else:
-                bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
-                                   True))
+                bad.extend(sub.add(ui, submatch, prefix, True, **opts))
         except error.LookupError:
             ui.status(_("skipping missing subrepository: %s\n")
                            % join(subpath))
 
-    if not dryrun:
+    if not opts.get('dry_run'):
         rejected = wctx.add(names, prefix)
         bad.extend(f for f in rejected if f in match.files())
     return bad
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -199,8 +199,7 @@ 
     """
 
     m = scmutil.match(repo[None], pats, opts)
-    rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'),
-                           opts.get('subrepos'), prefix="", explicitonly=False)
+    rejected = cmdutil.add(ui, repo, m, "", False, **opts)
     return rejected and 1 or 0
 
 @command('addremove',
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -621,9 +621,10 @@ 
                 fp.close()
 
     @annotatesubrepoerror
-    def add(self, ui, match, dryrun, listsubrepos, prefix, explicitonly):
-        return cmdutil.add(ui, self._repo, match, dryrun, listsubrepos,
-                           os.path.join(prefix, self._path), explicitonly)
+    def add(self, ui, match, prefix, explicitonly, **opts):
+        return cmdutil.add(ui, self._repo, match,
+                           os.path.join(prefix, self._path), explicitonly,
+                           **opts)
 
     def addremove(self, m, prefix, opts, dry_run, similarity):
         # In the same way as sub directories are processed, once in a subrepo,