[PATCH 2 of 2] Allow hg import to optionally import branch information

hopper at omnifarious.org hopper at omnifarious.org
Thu May 10 21:29:51 UTC 2007


# HG changeset patch
# User Eric Hopper <hopper at omnifarious.org>
# Date 1178829758 25200
# Node ID a3682450a872d3d67d9ff72b3056127e3793f902
# Parent  f60b0da1dec163b0bf563726f914ce5f5648aa4a
Allow hg import to optionally import branch information.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1514,10 +1514,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'))
@@ -1545,6 +1545,7 @@ def import_(ui, repo, patch1, *patches, 
                 if p1 != wp[0].node():
                     hg.clean(repo, p1, wlock=wlock)
                 repo.dirstate.setparents(p1, p2)
+                repo.dirstate.setbranch(branch or 'default')
             elif p2:
                 try:
                     p1 = repo.lookup(p1)
@@ -1553,6 +1554,8 @@ def import_(ui, repo, patch1, *patches, 
                         repo.dirstate.setparents(p1, p2)
                 except hg.RepoError:
                     pass
+            if not opts.get('exact') and opts.get('import-branch'):
+                repo.dirstate.setbranch(branch or 'default')
 
             files = {}
             try:
@@ -2804,7 +2807,9 @@ table = {
           ('f', 'force', None,
            _('skip check for outstanding uncommitted changes')),
           ('', 'exact', None,
-           _('apply patch to the nodes from which it was generated'))] + commitopts,
+           _('apply patch to the nodes from which it was generated')),
+          ('', 'import-branch', None,
+           _('Use any branch information in patch (implied by --exact)'))] + commitopts,
          _('hg import [-p NUM] [-m MESSAGE] [-f] PATCH...')),
     "incoming|in": (incoming,
          [('M', 'no-merges', None, _('do not show merges')),
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/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
     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
 
 GP_PATCH  = 1 << 0  # we have to run patch
 GP_FILTER = 1 << 1  # there's some copy/rename operation

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20070510/9b3574cd/attachment-0001.asc>


More information about the Mercurial mailing list