rewriteutil: create a rewriteutil module to host utility function
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 22 Jul 2017 23:40:28 +0200
changeset 2756 f4dd6e6d4c73
parent 2755 f690d51dfe5e
child 2757 2878c8a686ab
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.
hgext3rd/evolve/__init__.py
hgext3rd/evolve/evocommands.py
hgext3rd/evolve/rewriteutil.py
--- a/hgext3rd/evolve/__init__.py	Sun Jul 23 06:47:34 2017 +0200
+++ b/hgext3rd/evolve/__init__.py	Sat Jul 22 23:40:28 2017 +0200
@@ -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	Sun Jul 23 06:47:34 2017 +0200
+++ b/hgext3rd/evolve/evocommands.py	Sat Jul 22 23:40:28 2017 +0200
@@ -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')):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hgext3rd/evolve/rewriteutil.py	Sat Jul 22 23:40:28 2017 +0200
@@ -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