From 57ef32586b9ca77aea81cc1b7a35efcbd3f50606 Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Thu, 22 Dec 2016 23:28:35 -0700 Subject: [PATCH] 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. --- hgext/convert/__init__.py | 3 +++ hgext/convert/git.py | 4 ++- tests/test-convert-git.t | 55 +++++++++++++++++++++++++++++++++++++++ tests/test-convert.t | 3 +++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py index 5d663a4a31..e6a97ecfe1 100644 --- a/hgext/convert/__init__.py +++ b/hgext/convert/__init__.py @@ -337,6 +337,9 @@ def convert(ui, src, dest=None, revmapfile=None, **opts): ``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. diff --git a/hgext/convert/git.py b/hgext/convert/git.py index b3092e07fd..c26c7cebe9 100644 --- a/hgext/convert/git.py +++ b/hgext/convert/git.py @@ -322,11 +322,13 @@ class convert_git(common.converter_source, common.commandline): 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): diff --git a/tests/test-convert-git.t b/tests/test-convert-git.t index 5755cd9df0..f0e7025869 100644 --- a/tests/test-convert-git.t +++ b/tests/test-convert-git.t @@ -928,3 +928,58 @@ Converting multiple extras works +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 + 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 + date: Sun Sep 09 01:46:40 2001 +0000 + extra: branch=default + extra: convert_revision=0000aaaabbbbccccddddeeee + description: + message with extras + + diff --git a/tests/test-convert.t b/tests/test-convert.t index 0a14803293..e1c98ca81c 100644 --- a/tests/test-convert.t +++ b/tests/test-convert.t @@ -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.