Patchwork [5,of,6] merge: make calculateupdates() return file->action dict

login
register
mail settings
Submitter Martin von Zweigbergk
Date Dec. 17, 2014, 9:24 p.m.
Message ID <d15256ef6ca65ce717fe.1418851477@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7153/
State Superseded
Commit 289015e5028dac46afa94442323038a252188961
Headers show

Comments

Martin von Zweigbergk - Dec. 17, 2014, 9:24 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1418364461 28800
#      Thu Dec 11 22:07:41 2014 -0800
# Node ID d15256ef6ca65ce717fe48306e06e9d143c37bc9
# Parent  8c8d94bee5ed8f86b679db55a6deabf5a04188fb
merge: make calculateupdates() return file->action dict

This simplifies largefiles' overridecalculateupdates(), which no
longer has to do the conversion it started doing in 38e55e55ae4d
(largefiles: rewrite merge code using dictionary with entry per file,
2014-12-09).

To keep this patch small, we'll leave the name 'actionbyfile' in
overrides.py. It will be renamed in the next patch.
Pierre-Yves David - Dec. 19, 2014, 12:20 a.m.
On 12/17/2014 01:24 PM, Martin von Zweigbergk wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1418364461 28800
> #      Thu Dec 11 22:07:41 2014 -0800
> # Node ID d15256ef6ca65ce717fe48306e06e9d143c37bc9
> # Parent  8c8d94bee5ed8f86b679db55a6deabf5a04188fb
> merge: make calculateupdates() return file->action dict
>
> This simplifies largefiles' overridecalculateupdates(), which no
> longer has to do the conversion it started doing in 38e55e55ae4d
> (largefiles: rewrite merge code using dictionary with entry per file,
> 2014-12-09).
>
> To keep this patch small, we'll leave the name 'actionbyfile' in
> overrides.py. It will be renamed in the next patch.
>
> diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
> --- a/hgext/largefiles/overrides.py
> +++ b/hgext/largefiles/overrides.py
> @@ -428,15 +428,13 @@
>
>       # Convert to dictionary with filename as key and action as value.
>       lfiles = set()
> -    actionbyfile = {}
> -    for m, l in actions.iteritems():
> -        for f, args, msg in l:
> -            actionbyfile[f] = m, args, msg
> -            splitstandin = f and lfutil.splitstandin(f)
> -            if splitstandin in p1:
> -                lfiles.add(splitstandin)
> -            elif lfutil.standin(f) in p1:
> -                lfiles.add(f)
> +    actionbyfile = actions
> +    for f in actionbyfile.keys():

Any reason we use "keys() here? instead of direct iteration over 
actionbyfiles (or iterkeys?)
Martin von Zweigbergk - Dec. 19, 2014, 4:29 a.m.
On Thu Dec 18 2014 at 4:21:47 PM Pierre-Yves David <
pierre-yves.david@ens-lyon.org> wrote:

>
>
> On 12/17/2014 01:24 PM, Martin von Zweigbergk wrote:
> > # HG changeset patch
> > # User Martin von Zweigbergk <martinvonz@google.com>
> > # Date 1418364461 28800
> > #      Thu Dec 11 22:07:41 2014 -0800
> > # Node ID d15256ef6ca65ce717fe48306e06e9d143c37bc9
> > # Parent  8c8d94bee5ed8f86b679db55a6deabf5a04188fb
> > merge: make calculateupdates() return file->action dict
> >
> > This simplifies largefiles' overridecalculateupdates(), which no
> > longer has to do the conversion it started doing in 38e55e55ae4d
> > (largefiles: rewrite merge code using dictionary with entry per file,
> > 2014-12-09).
> >
> > To keep this patch small, we'll leave the name 'actionbyfile' in
> > overrides.py. It will be renamed in the next patch.
> >
> > diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.
> py
> > --- a/hgext/largefiles/overrides.py
> > +++ b/hgext/largefiles/overrides.py
> > @@ -428,15 +428,13 @@
> >
> >       # Convert to dictionary with filename as key and action as value.
> >       lfiles = set()
> > -    actionbyfile = {}
> > -    for m, l in actions.iteritems():
> > -        for f, args, msg in l:
> > -            actionbyfile[f] = m, args, msg
> > -            splitstandin = f and lfutil.splitstandin(f)
> > -            if splitstandin in p1:
> > -                lfiles.add(splitstandin)
> > -            elif lfutil.standin(f) in p1:
> > -                lfiles.add(f)
> > +    actionbyfile = actions
> > +    for f in actionbyfile.keys():
>
> Any reason we use "keys() here? instead of direct iteration over
> actionbyfiles (or iterkeys?)
>

Just a lack of knowledge about Python. I'll drop the "keys()" in V2.

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -428,15 +428,13 @@ 
 
     # Convert to dictionary with filename as key and action as value.
     lfiles = set()
-    actionbyfile = {}
-    for m, l in actions.iteritems():
-        for f, args, msg in l:
-            actionbyfile[f] = m, args, msg
-            splitstandin = f and lfutil.splitstandin(f)
-            if splitstandin in p1:
-                lfiles.add(splitstandin)
-            elif lfutil.standin(f) in p1:
-                lfiles.add(f)
+    actionbyfile = actions
+    for f in actionbyfile.keys():
+        splitstandin = f and lfutil.splitstandin(f)
+        if splitstandin in p1:
+            lfiles.add(splitstandin)
+        elif lfutil.standin(f) in p1:
+            lfiles.add(f)
 
     for lfile in lfiles:
         standin = lfutil.standin(lfile)
@@ -482,14 +480,7 @@ 
                 actionbyfile[lfile] = ('g', largs, 'replaces standin')
                 actionbyfile[standin] = ('r', None, 'replaced by non-standin')
 
-    # Convert back to dictionary-of-lists format
-    for l in actions.itervalues():
-        l[:] = []
-    actions['lfmr'] = []
-    for f, (m, args, msg) in actionbyfile.iteritems():
-        actions[m].append((f, args, msg))
-
-    return actions, diverge, renamedelete
+    return actionbyfile, diverge, renamedelete
 
 def mergerecordupdates(orig, repo, actions, branchmerge):
     if 'lfmr' in actions:
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -621,12 +621,6 @@ 
         fractions = _forgetremoved(wctx, mctx, branchmerge)
         actions.update(fractions)
 
-    # Convert to dictionary-of-lists format
-    actionbyfile = actions
-    actions = dict((m, []) for m in 'a f g cd dc r dm dg m e k'.split())
-    for f, (m, args, msg) in actionbyfile.iteritems():
-        actions[m].append((f, args, msg))
-
     return actions, diverge, renamedelete
 
 def batchremove(repo, actions):
@@ -1069,9 +1063,15 @@ 
             followcopies = True
 
         ### calculate phase
-        actions, diverge, renamedelete = calculateupdates(
+        actionbyfile, diverge, renamedelete = calculateupdates(
             repo, wc, p2, pas, branchmerge, force, partial, mergeancestor,
             followcopies)
+        # Convert to dictionary-of-lists format
+        actions = dict((m, []) for m in 'a f g cd dc r dm dg m e k'.split())
+        for f, (m, args, msg) in actionbyfile.iteritems():
+            if m not in actions:
+                actions[m] = []
+            actions[m].append((f, args, msg))
 
         if not util.checkcase(repo.path):
             # check collision between files only in p2 for clean update