diff mercurial/commands.py @ 12727:52971985be14

backout: provide linear backout as a default (without --merge option) This changes backouts changeset to retain linear history, .e. it is committed as a child of the working directory parent, not the reverted changeset parent. The default behavior was previously to just commit a reverted change as a child of the backed out changeset - thus creating a new head. Most of the time, you would use the --merge option, as it does not make sense to keep this dangling head as is. The previous behavior could be obtained by using 'hg update --clean .' after a 'hg backout --merge'. The --merge option itself is not affected by this change. There is also still an autocommit of the backout if a merge is not needed, i.e. in case the backout is the parent of the working directory. Previously we had (pwd = parent of the working directory): pwd older backout auto merge backout --merge auto commit With the new linear approach: pwd older backout auto commit backout --merge auto commit auto: commit done by the backout command merge: backout also already committed but explicit merge and commit needed commit: user need to commit the update/merge
author Gilles Moris <gilles.moris@free.fr>
date Fri, 10 Sep 2010 10:28:18 +0200
parents 61c0df2b089a
children 05bd2658bbb3
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Oct 11 10:07:42 2010 -0500
+++ b/mercurial/commands.py	Fri Sep 10 10:28:18 2010 +0200
@@ -204,17 +204,26 @@
 def backout(ui, repo, node=None, rev=None, **opts):
     '''reverse effect of earlier changeset
 
-    Commit the backed out changes as a new changeset. The new
-    changeset is a child of the backed out changeset.
-
-    If you backout a changeset other than the tip, a new head is
-    created. This head will be the new tip and you should merge this
-    backout changeset with another head.
-
+    The backout command merges the reverse effect of the reverted
+    changeset into the working directory.
+
+    With the --merge option, it first commits the reverted changes
+    as a new changeset. This new changeset is a child of the reverted
+    changeset.
     The --merge option remembers the parent of the working directory
     before starting the backout, then merges the new head with that
-    changeset afterwards. This saves you from doing the merge by hand.
-    The result of this merge is not committed, as with a normal merge.
+    changeset afterwards.
+    This will result in an explicit merge in the history.
+
+    If you backout a changeset other than the original parent of the
+    working directory, the result of this merge is not committed,
+    as with a normal merge. Otherwise, no merge is needed and the
+    commit is automatic.
+
+    Note that the default behavior (without --merge) has changed in
+    version 1.7. To restore the previous default behavior, use
+    :hg:`backout --merge` and then :hg:`update --clean .` to get rid of
+    the ongoing merge.
 
     See :hg:`help dates` for a list of formats valid for -d/--date.
 
@@ -268,6 +277,9 @@
     revert_opts['rev'] = hex(parent)
     revert_opts['no_backup'] = None
     revert(ui, repo, **revert_opts)
+    if not opts.get('merge') and op1 != node:
+        return hg.update(repo, op1)
+
     commit_opts = opts.copy()
     commit_opts['addremove'] = False
     if not commit_opts['message'] and not commit_opts['logfile']:
@@ -279,17 +291,12 @@
         return '%d:%s' % (repo.changelog.rev(node), short(node))
     ui.status(_('changeset %s backs out changeset %s\n') %
               (nice(repo.changelog.tip()), nice(node)))
-    if op1 != node:
+    if opts.get('merge') and op1 != node:
         hg.clean(repo, op1, show_stats=False)
-        if opts.get('merge'):
-            ui.status(_('merging with changeset %s\n')
-                      % nice(repo.changelog.tip()))
-            hg.merge(repo, hex(repo.changelog.tip()))
-        else:
-            ui.status(_('the backout changeset is a new head - '
-                        'do not forget to merge\n'))
-            ui.status(_('(use "backout --merge" '
-                        'if you want to auto-merge)\n'))
+        ui.status(_('merging with changeset %s\n')
+                  % nice(repo.changelog.tip()))
+        return hg.merge(repo, hex(repo.changelog.tip()))
+    return 0
 
 def bisect(ui, repo, rev=None, extra=None, command=None,
                reset=None, good=None, bad=None, skip=None, noupdate=None):