[PATCH 2 of 3] context: override workingctx.hex() to avoid a crash

Yuya Nishihara yuya at tcha.org
Mon Jun 15 10:26:16 CDT 2015


On Mon, 15 Jun 2015 00:28:58 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1434333857 14400
> #      Sun Jun 14 22:04:17 2015 -0400
> # Node ID f5f5e4ae488d9cae8111e9a212f647ed1430a019
> # Parent  9c738d2588313bb624465495a8923b293c45b999
> context: override workingctx.hex() to avoid a crash
> 
> Since node is None for workingctx, it can't use the base class implementation of
> 'hex(self.node())'.
> 
> It doesn't appear that there are any current callers of this, but there will be
> when archive supports 'wdir()'.  Since 'hg id' prints "p1.node() + '+'" for a
> dirty working copy, this does too.  That of course means that it isn't possible
> to call 'bin(ctx.hex())', but that seems circuitous.  Having the '+' seems like
> a useful distinction when building the .hg_archival.txt file.
> 
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -1334,6 +1334,12 @@
>      def __contains__(self, key):
>          return self._repo.dirstate[key] not in "?r"
>  
> +    def hex(self):
> +        hex = self.p1().hex()
> +        if self.dirty():
> +            hex += '+'
> +        return hex

I won't argue, but I have to say it won't be so useful.

I originally thought "{p1node}+" was useful in most cases [1], but I found it
wasn't for templating [2] because

 - "{node|short}" filter can't process "+" suffix
 - even if it could, we would have to do "{if(rev, rev, p1rev)}:{node|short}"
   to display both p1rev and p1node (can't avoid "if" anyway)
 - "{p1node}+" is a phony value only for display, which shouldn't appear in XML
   (and JSON) output

 [1]: http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/70867/focus=70871
 [2]: http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/78325/focus=78399


More information about the Mercurial-devel mailing list