Patchwork [1,of,5,RFC] phases: use constants for phase values

login
register
mail settings
Submitter Gregory Szorc
Date Feb. 16, 2016, 2:03 a.m.
Message ID <8449ef66f732a71008dc.1455588212@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/13218/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Gregory Szorc - Feb. 16, 2016, 2:03 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1455583792 28800
#      Mon Feb 15 16:49:52 2016 -0800
# Node ID 8449ef66f732a71008dc887ffd6efbfb6dc64ee0
# Parent  638dcaf3874940349d04f3369ddddc05fd9d5388
phases: use constants for phase values

Magic numbers hinder readability.
Gregory Szorc - Feb. 16, 2016, 2:04 a.m.
This one isn't radical and could be queued without much thought.

On Mon, Feb 15, 2016 at 6:03 PM, Gregory Szorc <gregory.szorc@gmail.com>
wrote:

> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1455583792 28800
> #      Mon Feb 15 16:49:52 2016 -0800
> # Node ID 8449ef66f732a71008dc887ffd6efbfb6dc64ee0
> # Parent  638dcaf3874940349d04f3369ddddc05fd9d5388
> phases: use constants for phase values
>
> Magic numbers hinder readability.
>
> diff --git a/mercurial/phases.py b/mercurial/phases.py
> --- a/mercurial/phases.py
> +++ b/mercurial/phases.py
> @@ -430,21 +430,21 @@ def analyzeremotephases(repo, subset, ro
>      # build list from dictionary
>      draftroots = []
>      nodemap = repo.changelog.nodemap # to filter unknown nodes
>      for nhex, phase in roots.iteritems():
>          if nhex == 'publishing': # ignore data related to publish option
>              continue
>          node = bin(nhex)
>          phase = int(phase)
> -        if phase == 0:
> +        if phase == public:
>              if node != nullid:
>                  repo.ui.warn(_('ignoring inconsistent public root'
>                                 ' from remote: %s\n') % nhex)
> -        elif phase == 1:
> +        elif phase == draft:
>              if node in nodemap:
>                  draftroots.append(node)
>          else:
>              repo.ui.warn(_('ignoring unexpected root from remote: %i
> %s\n')
>                           % (phase, nhex))
>      # compute heads
>      publicheads = newheads(repo, subset, draftroots)
>      return publicheads, draftroots
>
Yuya Nishihara - Feb. 20, 2016, 8:57 a.m.
On Mon, 15 Feb 2016 18:04:48 -0800, Gregory Szorc wrote:
> This one isn't radical and could be queued without much thought.
> 
> On Mon, Feb 15, 2016 at 6:03 PM, Gregory Szorc <gregory.szorc@gmail.com>
> wrote:
> 
> > # HG changeset patch
> > # User Gregory Szorc <gregory.szorc@gmail.com>
> > # Date 1455583792 28800
> > #      Mon Feb 15 16:49:52 2016 -0800
> > # Node ID 8449ef66f732a71008dc887ffd6efbfb6dc64ee0
> > # Parent  638dcaf3874940349d04f3369ddddc05fd9d5388
> > phases: use constants for phase values

Yep, pushed only this to the clowncopter, thanks.

Patch

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -430,21 +430,21 @@  def analyzeremotephases(repo, subset, ro
     # build list from dictionary
     draftroots = []
     nodemap = repo.changelog.nodemap # to filter unknown nodes
     for nhex, phase in roots.iteritems():
         if nhex == 'publishing': # ignore data related to publish option
             continue
         node = bin(nhex)
         phase = int(phase)
-        if phase == 0:
+        if phase == public:
             if node != nullid:
                 repo.ui.warn(_('ignoring inconsistent public root'
                                ' from remote: %s\n') % nhex)
-        elif phase == 1:
+        elif phase == draft:
             if node in nodemap:
                 draftroots.append(node)
         else:
             repo.ui.warn(_('ignoring unexpected root from remote: %i %s\n')
                          % (phase, nhex))
     # compute heads
     publicheads = newheads(repo, subset, draftroots)
     return publicheads, draftroots