Submitter | Gregory Szorc |
---|---|
Date | Dec. 23, 2016, 7:28 a.m. |
Message ID | <b782fa641daacb8aecf7.1482474528@gps-mbp.local> |
Download | mbox | patch |
Permalink | /patch/18014/ |
State | Accepted |
Headers | show |
Comments
On Thu, Dec 22, 2016 at 11:28:48PM -0800, Gregory Szorc wrote: > # HG changeset patch > # User Gregory Szorc <gregory.szorc@gmail.com> > # Date 1482474515 25200 > # Thu Dec 22 23:28:35 2016 -0700 > # Node ID b782fa641daacb8aecf71dacfd2fe7ddfa369485 > # Parent 9bf2ccdad0b6518c23c55cfda79d6bac31e33a1f > convert: add config option to control storing original revision Queued these, thanks. > > 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. > > diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py > --- a/hgext/convert/__init__.py > +++ b/hgext/convert/__init__.py > @@ -336,8 +336,11 @@ def convert(ui, src, dest=None, revmapfi > :convert.git.remoteprefix: 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. > > Perforce Source > diff --git a/hgext/convert/git.py b/hgext/convert/git.py > --- a/hgext/convert/git.py > +++ b/hgext/convert/git.py > @@ -321,13 +321,15 @@ class convert_git(common.converter_sourc > message += "\ncommitter: %s\n" % committer > 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): > output, ret = self.gitrunlines('rev-list', '--all') > diff --git a/tests/test-convert-git.t b/tests/test-convert-git.t > --- a/tests/test-convert-git.t > +++ b/tests/test-convert-git.t > @@ -916,4 +916,59 @@ Converting multiple extras works > message with extras > > > > +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 > + > + > diff --git a/tests/test-convert.t b/tests/test-convert.t > --- a/tests/test-convert.t > +++ b/tests/test-convert.t > @@ -278,8 +278,11 @@ > convert.git.remoteprefix > 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. > > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Patch
diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py --- a/hgext/convert/__init__.py +++ b/hgext/convert/__init__.py @@ -336,8 +336,11 @@ def convert(ui, src, dest=None, revmapfi :convert.git.remoteprefix: 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. Perforce Source diff --git a/hgext/convert/git.py b/hgext/convert/git.py --- a/hgext/convert/git.py +++ b/hgext/convert/git.py @@ -321,13 +321,15 @@ class convert_git(common.converter_sourc message += "\ncommitter: %s\n" % committer 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): output, ret = self.gitrunlines('rev-list', '--all') diff --git a/tests/test-convert-git.t b/tests/test-convert-git.t --- a/tests/test-convert-git.t +++ b/tests/test-convert-git.t @@ -916,4 +916,59 @@ Converting multiple extras works message with extras +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 + + diff --git a/tests/test-convert.t b/tests/test-convert.t --- a/tests/test-convert.t +++ b/tests/test-convert.t @@ -278,8 +278,11 @@ convert.git.remoteprefix 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.