[PATCH] Re: 2 bugs in tag removal

Matt Mackall mpm at selenic.com
Sat Dec 8 10:32:02 CST 2007


On Sat, Dec 08, 2007 at 06:02:38PM +0900, Osku Salerma wrote:
> On Sat, 8 Dec 2007, Osku Salerma wrote:
> 
> >On Sat, 8 Dec 2007, Matt Mackall wrote:
> >>How about a parallel dict that tracks the source of each tag?
> >
> >I'll try implementing that.
> 
> Here's the parallel-dict implementation of fixing this. Note that this
> version implements the more restrictive checks, i.e. does not allow
> "deleting" a local tag that only exists as a global one.
> 
> # HG changeset patch
> # User Osku Salerma <osku at iki.fi>
> # Date 1197104242 -32400
> # Node ID 492de6e0986e9560799f46fa5f3929540a3ebe8d
> # Parent  feac5b0bf9bad2c125ebd5f3e133bcd46ecb8c7c
> Properly check tag's existence as a local/global tag when removing it.
> 
> diff -r feac5b0bf9ba -r 492de6e0986e mercurial/commands.py
> --- a/mercurial/commands.py	Wed Nov 28 13:58:31 2007 -0800
> +++ b/mercurial/commands.py	Sat Dec 08 17:57:22 2007 +0900
> @@ -2628,7 +2628,11 @@ def tag(ui, repo, name, rev_=None, **opt
>          rev_ = opts['rev']
>      message = opts['message']
>      if opts['remove']:
> -        if not name in repo.tags():
> +        tagtype = repo.gettagtype(name)
> +        found = (opts['local'] and tagtype == 'local') or \
> +                (not opts['local'] and tagtype == 'global')

Use () rather than \ here, please

> +
> +        if not found:
>              raise util.Abort(_('tag %s does not exist') % name)

If we're going to go to all this trouble, we should probably complain
more specifically.

>          self.tagscache = None
> +        self.tagstypecache = None

New members should have a _ prefix.

> +    def gettagtype(self, tagname):
> +        '''
> +        return the type of the given tag. result can be:
> +
> +        'local'  : a local tag
> +        'global' : a global tag
> +        None     : tag does not exist
> +        '''
> +
> +        self.tags()
> + 
> +        return self.tagstypecache.get(tagname)

Do we actually need this function? Can't the one user of tagtypes just
use the dict directly?

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial-devel mailing list