[PATCH 2 of 4] convert: add bookmarks reading support to git backend

Matt Mackall mpm at selenic.com
Wed Mar 23 16:31:45 CDT 2011


On Wed, 2011-03-23 at 21:50 +0100, Edouard Gomez wrote:
> # HG changeset patch
> # User Edouard Gomez <ed.gomez at free.fr>
> # Date 1278454019 -7200
> # Branch stable
> # Node ID 3fda6383d43abf72561cd72ea03c197040889cc6
> # Parent  24fe02dbca9978a913650e23b49269530176d5ce
> convert: add bookmarks reading support to git backend

I don't know enough about git to have an opinion on this piece.

> diff --git a/hgext/convert/git.py b/hgext/convert/git.py
> --- a/hgext/convert/git.py
> +++ b/hgext/convert/git.py
> @@ -168,3 +168,30 @@
>              raise util.Abort(_('cannot read changes in %s') % version)
>  
>          return changes
> +
> +    def getbookmarks(self):
> +        bookmarks = {}
> +
> +        # Interesting references in git are prefixed
> +        prefix = 'refs/heads/'
> +        prefixlen = 11

len(prefix)

> +        # factor two commands
> +        gitcmd = { 'remote/': 'git ls-remote --heads origin',
> +                          '': 'git show-ref'}
> +
> +        # Origin heads
> +        for reftype in gitcmd: 
> +            try:
> +                fh = self.gitopen(gitcmd[reftype])
> +                for line in fh:
> +                    line = line.strip()
> +                    rev, name = line.split(None, 1)
> +                    if not name.startswith(prefix):
> +                        continue
> +                    name = '%s%s' % (reftype, name[prefixlen:])
> +                    bookmarks[name] = rev
> +            except:
> +                pass
> +
> +        return bookmarks
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list