[PATCH 5 of 7] revert: group related data in tuple in the dispatch table

Kevin Bullock kbullock+mercurial at ringworld.org
Mon Jun 9 22:31:06 CDT 2014


On May 19, 2014, at 10:58 AM, pierre-yves.david at ens-lyon.org wrote:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1400027299 25200
> #      Tue May 13 17:28:19 2014 -0700
> # Node ID b76ab6980b95e67d4e71162da416de47864b03a1
> # Parent  eaff5c46777081a267917ab8631e74f7f51780d3
> revert: group related data in tuple in the dispatch table
> 
> The dispatch table used to be:
> 
> - action if in target manifest
> - action if not in target manifest
> - make backup if in target manifest
> - make backup if not in target manifest
> 
> We turn this into two (action, make backup) tuples.
> 
> This helps both readability of the dispatch table and handling of each case.
> 
> This also prepares a refactoring where the different actions we performs, whether
> "file is in target manifest" or not, are determined before reaching this loop.
> 
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -2318,14 +2318,18 @@ def revert(ui, repo, ctx, parents, *pats
>             #   file state
>             #   action if in target manifest
>             #   action if not in target manifest
>             #   make backup if in target manifest
>             #   make backup if not in target manifest

You neglected to update the comment here.

pacem in terris / мир / शान्ति / ‎‫سَلاَم‬ / 平和
Kevin R. Bullock

> -            (modified, actions['revert'],   actions['remove'], True,  True),
> -            (added,    actions['revert'],   actions['remove'], True,  False),
> -            (removed,  actions['undelete'], None,              True,  False),
> -            (deleted,  actions['revert'],   actions['remove'], False, False),
> +            (modified, (actions['revert'],   True),
> +                       (actions['remove'],   True)),
> +            (added,    (actions['revert'],   True),
> +                       (actions['remove'],   False)),
> +            (removed,  (actions['undelete'], True),
> +                       (None,                False)),
> +            (deleted,  (actions['revert'], False),
> +                       (actions['remove'], False)),
>             )
> 
>         for abs, (rel, exact) in sorted(names.items()):
>             # hash on file in target manifest (or None if missing from target)
>             mfentry = mf.get(abs)
> @@ -2347,18 +2351,18 @@ def revert(ui, repo, ctx, parents, *pats
>                         msg = msg(abs)
>                     ui.status(msg % rel)
>             # search the entry in the dispatch table.
>             # if the file is in any of this sets, it was touched in the working
>             # directory parent and we are sure it needs to be reverted.
> -            for table, hitlist, misslist, backuphit, backupmiss in disptable:
> +            for table, hit, miss in disptable:
>                 if abs not in table:
>                     continue
>                 # file has changed in dirstate
>                 if mfentry:
> -                    handle(hitlist, backuphit)
> -                elif misslist is not None:
> -                    handle(misslist, backupmiss)
> +                    handle(*hit)
> +                elif miss[0] is not None:
> +                    handle(*miss)
>                 break
>             else:
>                 # Not touched in current dirstate.
> 
>                 # file is unknown in parent, restore older version or ignore.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list