changeset 30664:ced0d686ecb3

convert: add config option to control storing original revision common.commit.__init__ sets saverev=True by default. The side effect of this is that the hg sink will always set the "convert_revision" extras key to the commit being converted. This patch adds a config option to disable this behavior. While most consumers will want "convert_revision" to be a) written b) with the exact Git commit that was converted, some have use cases that prefer otherwise. In my case, I am performing significant rewrites of a Git repository *before* it is fed into `hg convert`. I have to do this because `hg convert` does not easily support the kind of transform I desire, even with extensions. (For the curious, I am "linearizing" the history of a GitHub repo by removing merge commits which add little value to the final history. It isn't easy to do this during `hg convert` because of Mercurial's file copy/rename metadata requirements.) In my scenario, my pre-convert transform stores a "convert_revision" key in the Git commit object containing the original Git commit ID. I want this original Git commit ID carried forward to Mercurial. By disabling the setting of this extra during `hg convert` and copying the value from the Git commit object, I can have the final "convert_revision" extra key contain the original Git commit ID. An added test verifies this exact scenario. This feature could likely be implemented for other VCS sources. But until someone needs the feature, I'm inclined to hold off implementing.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 22 Dec 2016 23:28:35 -0700
parents 1f21a6835604
children 69459fdf3b1b
files hgext/convert/__init__.py hgext/convert/git.py tests/test-convert-git.t tests/test-convert.t
diffstat 4 files changed, 64 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/__init__.py	Thu Dec 22 23:28:11 2016 -0700
+++ b/hgext/convert/__init__.py	Thu Dec 22 23:28:35 2016 -0700
@@ -337,6 +337,9 @@
         ``convert.git.remoteprefix`` as a prefix followed by a /. The default
         is 'remote'.
 
+    :convert.git.saverev: whether to store the original Git commit ID in the
+        metadata of the destination commit. The default is True.
+
     :convert.git.skipsubmodules: does not convert root level .gitmodules files
         or files with 160000 mode indicating a submodule. Default is False.
 
--- a/hgext/convert/git.py	Thu Dec 22 23:28:11 2016 -0700
+++ b/hgext/convert/git.py	Thu Dec 22 23:28:35 2016 -0700
@@ -322,11 +322,13 @@
         tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:]
         tz = -int(tzs) * (int(tzh) * 3600 + int(tzm))
         date = tm + " " + str(tz)
+        saverev = self.ui.configbool('convert', 'git.saverev', True)
 
         c = common.commit(parents=parents, date=date, author=author,
                           desc=message,
                           rev=version,
-                          extra=extra)
+                          extra=extra,
+                          saverev=saverev)
         return c
 
     def numcommits(self):
--- a/tests/test-convert-git.t	Thu Dec 22 23:28:11 2016 -0700
+++ b/tests/test-convert-git.t	Thu Dec 22 23:28:35 2016 -0700
@@ -928,3 +928,58 @@
   
   
 
+convert.git.saverev can be disabled to prevent convert_revision from being written
+
+  $ hg convert --config convert.git.saverev=false gitextras hgextras4
+  initializing destination hgextras4 repository
+  scanning source...
+  sorting...
+  converting...
+  1 initial
+  0 message with extras
+  updating bookmarks
+
+  $ hg -R hgextras4 log --debug -r 1
+  changeset:   1:1dcaf4ffe5bee43fa86db2800821f6f0af212c5c
+  bookmark:    master
+  tag:         tip
+  phase:       draft
+  parent:      0:a13935fec4daf06a5a87a7307ccb0fc94f98d06d
+  parent:      -1:0000000000000000000000000000000000000000
+  manifest:    0:6a3df4de388f3c4f8e28f4f9a814299a3cbb5f50
+  user:        test <test@example.com>
+  date:        Sun Sep 09 01:46:40 2001 +0000
+  extra:       branch=default
+  description:
+  message with extras
+  
+  
+
+convert.git.saverev and convert.git.extrakeys can be combined to preserve
+convert_revision from source
+
+  $ hg convert --config convert.git.saverev=false --config convert.git.extrakeys=convert_revision gitextras hgextras5
+  initializing destination hgextras5 repository
+  scanning source...
+  sorting...
+  converting...
+  1 initial
+  0 message with extras
+  updating bookmarks
+
+  $ hg -R hgextras5 log --debug -r 1
+  changeset:   1:574d85931544d4542007664fee3747360e85ee28
+  bookmark:    master
+  tag:         tip
+  phase:       draft
+  parent:      0:a13935fec4daf06a5a87a7307ccb0fc94f98d06d
+  parent:      -1:0000000000000000000000000000000000000000
+  manifest:    0:6a3df4de388f3c4f8e28f4f9a814299a3cbb5f50
+  user:        test <test@example.com>
+  date:        Sun Sep 09 01:46:40 2001 +0000
+  extra:       branch=default
+  extra:       convert_revision=0000aaaabbbbccccddddeeee
+  description:
+  message with extras
+  
+  
--- a/tests/test-convert.t	Thu Dec 22 23:28:11 2016 -0700
+++ b/tests/test-convert.t	Thu Dec 22 23:28:35 2016 -0700
@@ -279,6 +279,9 @@
                     remote refs are converted as bookmarks with
                     "convert.git.remoteprefix" as a prefix followed by a /. The
                     default is 'remote'.
+      convert.git.saverev
+                    whether to store the original Git commit ID in the metadata
+                    of the destination commit. The default is True.
       convert.git.skipsubmodules
                     does not convert root level .gitmodules files or files with
                     160000 mode indicating a submodule. Default is False.