Patchwork [11,of,12] upgrade: use 'improvement' object for action too

login
register
mail settings
Submitter Pierre-Yves David
Date April 11, 2017, 10:47 p.m.
Message ID <ed384e9f47907a7521e3.1491950871@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20122/
State Accepted
Headers show

Comments

Pierre-Yves David - April 11, 2017, 10:47 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1491858705 -7200
#      Mon Apr 10 23:11:45 2017 +0200
# Node ID ed384e9f47907a7521e33012a5cf6f15053f23d3
# Parent  0646947aaf15ffa2a0f08f997d1bb699dcc4e612
# EXP-Topic upgraderepo
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r ed384e9f4790
upgrade: use 'improvement' object for action too

This simplify multiple pieces of code. For now we restrict this upgrade to the
top level function to keep this patch simple.
Ryan McElroy - April 12, 2017, 11:50 a.m.
On 4/11/17 11:47 PM, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1491858705 -7200
> #      Mon Apr 10 23:11:45 2017 +0200
> # Node ID ed384e9f47907a7521e33012a5cf6f15053f23d3
> # Parent  0646947aaf15ffa2a0f08f997d1bb699dcc4e612
> # EXP-Topic upgraderepo
> upgrade: use 'improvement' object for action too
>
> This simplify multiple pieces of code. For now we restrict this upgrade to the

s/simplify/simplifies

> top level function to keep this patch simple.
>
> diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
> --- a/mercurial/upgrade.py
> +++ b/mercurial/upgrade.py
> @@ -292,7 +292,7 @@ def determineactions(repo, deficiencies,
>           if name in knownreqs and name not in destreqs:
>               continue
>   
> -        newactions.append(name)
> +        newactions.append(d)
>   
>       # FUTURE consider adding some optimizations here for certain transitions.
>       # e.g. adding generaldelta could schedule parent redeltas.
> @@ -639,11 +639,10 @@ def upgraderepo(ui, repo, run=False, opt
>                                    'optimizations'))
>   
>       deficiencies = finddeficiencies(repo)
> -    improvements = deficiencies + optimizations
>       actions = determineactions(repo, deficiencies, repo.requirements, newreqs)
> -    actions.extend(o.name for o in sorted(optimizations)
> +    actions.extend(o for o in sorted(optimizations)
>                      # determineactions could have added optimisation
> -                   if o.name not in actions)
> +                   if o not in actions)
>   
>       def printrequirements():
>           ui.write(_('requirements\n'))
> @@ -661,11 +660,8 @@ def upgraderepo(ui, repo, run=False, opt
>           ui.write('\n')
>   
>       def printupgradeactions():
> -        for action in actions:
> -            for i in improvements:
> -                if i.name == action:
> -                    ui.write('%s\n   %s\n\n' %
> -                             (i.name, i.upgrademessage))
> +        for a in actions:
> +            ui.write('%s\n   %s\n\n' % (a.name, a.upgrademessage))
>   
>       if not run:
>           fromdefault = []
> @@ -705,8 +701,8 @@ def upgraderepo(ui, repo, run=False, opt
>           printrequirements()
>           printupgradeactions()
>   
> -        unusedoptimize = [i for i in alloptimizations
> -                          if i.name not in actions]
> +        unusedoptimize = [i for i in alloptimizations if i not in actions]
> +
>           if unusedoptimize:
>               ui.write(_('additional optimizations are available by specifying '
>                        '"--optimize <name>":\n\n'))
> @@ -719,6 +715,8 @@ def upgraderepo(ui, repo, run=False, opt
>       printrequirements()
>       printupgradeactions()
>   
> +    upgradeactions = [a.name for a in actions]
> +
>       ui.write(_('beginning upgrade...\n'))
>       with repo.wlock():
>           with repo.lock():
> @@ -740,7 +738,7 @@ def upgraderepo(ui, repo, run=False, opt
>                   with dstrepo.wlock():
>                       with dstrepo.lock():
>                           backuppath = _upgraderepo(ui, repo, dstrepo, newreqs,
> -                                                  actions)
> +                                                  upgradeactions)
>   
>               finally:
>                   ui.write(_('removing temporary repository %s\n') % tmppath)
>

Patch

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -292,7 +292,7 @@  def determineactions(repo, deficiencies,
         if name in knownreqs and name not in destreqs:
             continue
 
-        newactions.append(name)
+        newactions.append(d)
 
     # FUTURE consider adding some optimizations here for certain transitions.
     # e.g. adding generaldelta could schedule parent redeltas.
@@ -639,11 +639,10 @@  def upgraderepo(ui, repo, run=False, opt
                                  'optimizations'))
 
     deficiencies = finddeficiencies(repo)
-    improvements = deficiencies + optimizations
     actions = determineactions(repo, deficiencies, repo.requirements, newreqs)
-    actions.extend(o.name for o in sorted(optimizations)
+    actions.extend(o for o in sorted(optimizations)
                    # determineactions could have added optimisation
-                   if o.name not in actions)
+                   if o not in actions)
 
     def printrequirements():
         ui.write(_('requirements\n'))
@@ -661,11 +660,8 @@  def upgraderepo(ui, repo, run=False, opt
         ui.write('\n')
 
     def printupgradeactions():
-        for action in actions:
-            for i in improvements:
-                if i.name == action:
-                    ui.write('%s\n   %s\n\n' %
-                             (i.name, i.upgrademessage))
+        for a in actions:
+            ui.write('%s\n   %s\n\n' % (a.name, a.upgrademessage))
 
     if not run:
         fromdefault = []
@@ -705,8 +701,8 @@  def upgraderepo(ui, repo, run=False, opt
         printrequirements()
         printupgradeactions()
 
-        unusedoptimize = [i for i in alloptimizations
-                          if i.name not in actions]
+        unusedoptimize = [i for i in alloptimizations if i not in actions]
+
         if unusedoptimize:
             ui.write(_('additional optimizations are available by specifying '
                      '"--optimize <name>":\n\n'))
@@ -719,6 +715,8 @@  def upgraderepo(ui, repo, run=False, opt
     printrequirements()
     printupgradeactions()
 
+    upgradeactions = [a.name for a in actions]
+
     ui.write(_('beginning upgrade...\n'))
     with repo.wlock():
         with repo.lock():
@@ -740,7 +738,7 @@  def upgraderepo(ui, repo, run=False, opt
                 with dstrepo.wlock():
                     with dstrepo.lock():
                         backuppath = _upgraderepo(ui, repo, dstrepo, newreqs,
-                                                  actions)
+                                                  upgradeactions)
 
             finally:
                 ui.write(_('removing temporary repository %s\n') % tmppath)