Patchwork [3,of,3] import: enable passing around 'Amend' in import

login
register
mail settings
Submitter Matthew Turk
Date Nov. 21, 2013, 10:33 p.m.
Message ID <78aec46503913303342f.1385073210@ridcully>
Download mbox | patch
Permalink /patch/3079/
State Superseded
Headers show

Comments

Matthew Turk - Nov. 21, 2013, 10:33 p.m.
# HG changeset patch
# User Matthew Turk <matthewturk@gmail.com>
# Date 1385073055 18000
#      Thu Nov 21 17:30:55 2013 -0500
# Node ID 78aec46503913303342f748137d9c637c99a414a
# Parent  feb80ffcab5811806c891b2a1e8a1e67f5915590
import: enable passing around 'Amend' in import

This will create an 'extra' dict if need be, and if --exact is supplied on the
command line it will attempt to replicate the obsstore changes so that the
appropriate (amended) changeset is marked as obsolete.

In cases where the amended changeset is not in a repository, it will not create
obsolete changeset markers, but will preserve the 'extra' data on the commit.

Patch

diff -r feb80ffcab58 -r 78aec4650391 mercurial/commands.py
--- a/mercurial/commands.py	Thu Nov 21 16:47:11 2013 -0500
+++ b/mercurial/commands.py	Thu Nov 21 17:30:55 2013 -0500
@@ -3680,10 +3680,12 @@ 
     def tryone(ui, hunk, parents):
         tmpname, message, user, date, branch, nodeid, p1, p2, amends = \
             patch.extract(ui, hunk)
-
         if not tmpname:
             return (None, None)
         msg = _('applied to working directory')
+        extra = {}
+        if amends:
+            extra = {'amend_source': amends}
 
         try:
             cmdline_message = cmdutil.logmessage(ui, opts)
@@ -3720,6 +3722,15 @@ 
             else:
                 p1, p2 = parents
 
+            if amends and opts.get('exact') and amends in repo:
+                old = repo[amends]
+                if old.phase() == phases.public:
+                    raise util.Abort(_('cannot amend public changesets'))
+                if len(repo[None].parents()) > 1:
+                    raise util.Abort(_('cannot amend while merging'))
+                if (not obsolete._enabled) and old.children():
+                    raise util.Abort(_('cannot amend changeset with children'))
+
             n = None
             if update:
                 if p1 != parents[0]:
@@ -3747,7 +3758,7 @@ 
                         m = scmutil.matchfiles(repo, files or [])
                     n = repo.commit(message, opts.get('user') or user,
                                     opts.get('date') or date, match=m,
-                                    editor=editor)
+                                    editor=editor, extra = extra)
             else:
                 if opts.get('exact') or opts.get('import_branch'):
                     branch = branch or 'default'
@@ -3771,8 +3782,12 @@ 
                     n = memctx.commit()
                 finally:
                     store.close()
-            if opts.get('exact') and hex(n) != nodeid:
-                raise util.Abort(_('patch is damaged or loses information'))
+            if opts.get('exact'):
+                if hex(n) != nodeid:
+                    raise util.Abort(_('patch is damaged or loses information'))
+                if obsolete._enabled and amends and amends in repo:
+                    obs = [(repo[amends], (repo[n],))]
+                    obsolete.createmarkers(repo, obs)
             if n:
                 # i18n: refers to a short changeset id
                 msg = _('created %s') % short(n)