changeset 2852:f4dd6e6d4c73

rewriteutil: create a rewriteutil module to host utility function The ultimate goal of this module is to gather basic building block for rewriting changesets. This is aimed at moving into core and being use by the core extension.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 22 Jul 2017 23:40:28 +0200
parents f690d51dfe5e
children 2878c8a686ab
files hgext3rd/evolve/__init__.py hgext3rd/evolve/evocommands.py hgext3rd/evolve/rewriteutil.py
diffstat 3 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py
+++ b/hgext3rd/evolve/__init__.py
@@ -284,6 +284,7 @@
     obscache,
     obsexchange,
     obshistory,
+    rewriteutil,
     safeguard,
     templatekw,
     utility,
@@ -316,7 +317,7 @@
 aliases, entry = cmdutil.findcmd('commit', commands.table)
 commitopts3 = evocommands.commitopts3
 interactiveopt = evocommands.interactiveopt
-_bookmarksupdater = evocommands._bookmarksupdater
+_bookmarksupdater = rewriteutil.bookmarksupdater
 
 # This extension contains the following code
 #
--- a/hgext3rd/evolve/evocommands.py
+++ b/hgext3rd/evolve/evocommands.py
@@ -31,7 +31,7 @@
 
 from . import (
     exthelper,
-    compat,
+    rewriteutil,
 )
 
 eh = exthelper.exthelper()
@@ -64,17 +64,6 @@
 
 interactiveopt = [['i', 'interactive', None, _('use interactive mode')]]
 
-def _bookmarksupdater(repo, oldid, tr):
-    """Return a callable update(newid) updating the current bookmark
-    and bookmarks bound to oldid to newid.
-    """
-    def updatebookmarks(newid):
-        oldbookmarks = repo.nodebookmarks(oldid)
-        bmchanges = [(b, newid) for b in oldbookmarks]
-        if bmchanges:
-            compat.bookmarkapplychanges(repo, tr, bmchanges)
-    return updatebookmarks
-
 @eh.command(
     'amend|refresh',
     [('A', 'addremove', None,
@@ -288,7 +277,7 @@
 
         # Recommit the filtered changeset
         tr = repo.transaction('uncommit')
-        updatebookmarks = _bookmarksupdater(repo, old.node(), tr)
+        updatebookmarks = rewriteutil.bookmarksupdater(repo, old.node(), tr)
         newid = None
         includeorexclude = opts.get('include') or opts.get('exclude')
         if (pats or includeorexclude or opts.get('all')):
new file mode 100644
--- /dev/null
+++ b/hgext3rd/evolve/rewriteutil.py
@@ -0,0 +1,27 @@
+# Module dedicated to host utility code dedicated to changeset rewrite
+#
+# Copyright 2017 Octobus <contact@octobus.net>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+# Status: Stabilization of the API in progress
+#
+#   The content of this module should move into core incrementally once we are
+#   happy one piece of it (and hopefully, able to reuse it in other core
+#   commands).
+
+from . import (
+    compat,
+)
+
+def bookmarksupdater(repo, oldid, tr):
+    """Return a callable update(newid) updating the current bookmark
+    and bookmarks bound to oldid to newid.
+    """
+    def updatebookmarks(newid):
+        oldbookmarks = repo.nodebookmarks(oldid)
+        bmchanges = [(b, newid) for b in oldbookmarks]
+        if bmchanges:
+            compat.bookmarkapplychanges(repo, tr, bmchanges)
+    return updatebookmarks