[PATCH 2 of 5] Add ability to parse branch information to hg import

Brendan Cully brendan at kublai.com
Thu May 17 17:31:55 UTC 2007


On Thursday, 17 May 2007 at 09:43, hopper at omnifarious.org wrote:
> # HG changeset patch
> # User Eric Hopper <hopper at omnifarious.org>
> # Date 1179417189 25200
> # Node ID ef06e8ac64bdf3de74711ba1ba1f8ad769d8dcc7
> # Parent  32486cd3207b70bbbb16b336c566ec8246ee760d
> Add ability to parse branch information to hg import
> 
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1516,10 +1516,10 @@ def import_(ui, repo, patch1, *patches, 
>  
>          if pf == '-':
>              ui.status(_("applying patch from stdin\n"))
> -            tmpname, message, user, date, nodeid, p1, p2 = patch.extract(ui, sys.stdin)
> +            tmpname, message, user, date, branch, nodeid, p1, p2 = patch.extract(ui, sys.stdin)
>          else:
>              ui.status(_("applying %s\n") % p)
> -            tmpname, message, user, date, nodeid, p1, p2 = patch.extract(ui, file(pf))
> +            tmpname, message, user, date, branch, nodeid, p1, p2 = patch.extract(ui, file(pf))
>  
>          if tmpname is None:
>              raise util.Abort(_('no diffs found'))
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -55,6 +55,7 @@ def extract(ui, fileobj):
>          # should try to parse msg['Date']
>          date = None
>          nodeid = None
> +        branch = None
>          parents = []
>  
>          if message:
> @@ -99,6 +100,8 @@ def extract(ui, fileobj):
>                              ui.debug('From: %s\n' % user)
>                          elif line.startswith("# Date "):
>                              date = line[7:]
> +                        elif line.startswith("# Branch "):
> +                            branch = line[9:]
>                          elif line.startswith("# Node ID "):
>                              nodeid = line[10:]
>                          elif line.startswith("# Parent "):
> @@ -126,7 +129,7 @@ def extract(ui, fileobj):
>          return None, message, user, date, None, None, None

hmm, looks like you might not have caught all the return cases?

>      p1 = parents and parents.pop(0) or None
>      p2 = parents and parents.pop(0) or None
> -    return tmpname, message, user, date, nodeid, p1, p2
> +    return tmpname, message, user, date, branch, nodeid, p1, p2

(this tuple is getting a bit long too - it might be worth turning it
into a class or at least dict at some point...)



More information about the Mercurial-devel mailing list