Patchwork convert: add config option to control saving Git committer in message

login
register
mail settings
Submitter Gregory Szorc
Date Jan. 6, 2017, 6:57 p.m.
Message ID <1901566ab484a56b177b.1483729044@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/18129/
State Changes Requested
Headers show

Comments

Gregory Szorc - Jan. 6, 2017, 6:57 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1483729033 28800
#      Fri Jan 06 10:57:13 2017 -0800
# Node ID 1901566ab484a56b177b88ff080d635840e0912c
# Parent  3de9df6ee5bf7601aa3870f18304bbeb3ce351af
convert: add config option to control saving Git committer in message

As part of converting a Git repository to Mercurial at Mozilla, I
encountered a scenario where I didn't want `hg convert` to
automatically add the "committer: <committer>" line to commit messages.
While I can hack around it downstream by rewriting the Git commit
before feeding it into `hg convert`, I'd prefer to just specify a
config flag to turn it off. This patch adds that flag.
Sean Farley - Jan. 6, 2017, 7:36 p.m.
Gregory Szorc <gregory.szorc@gmail.com> writes:

> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1483729033 28800
> #      Fri Jan 06 10:57:13 2017 -0800
> # Node ID 1901566ab484a56b177b88ff080d635840e0912c
> # Parent  3de9df6ee5bf7601aa3870f18304bbeb3ce351af
> convert: add config option to control saving Git committer in message
>
> As part of converting a Git repository to Mercurial at Mozilla, I
> encountered a scenario where I didn't want `hg convert` to
> automatically add the "committer: <committer>" line to commit messages.
> While I can hack around it downstream by rewriting the Git commit
> before feeding it into `hg convert`, I'd prefer to just specify a
> config flag to turn it off. This patch adds that flag.

I'm fine with this as-is but what about maybe storing it in the
metadata? Just a thought.
Gregory Szorc - Jan. 6, 2017, 7:39 p.m.
On Fri, Jan 6, 2017 at 11:36 AM, Sean Farley <sean@farley.io> wrote:

> Gregory Szorc <gregory.szorc@gmail.com> writes:
>
> > # HG changeset patch
> > # User Gregory Szorc <gregory.szorc@gmail.com>
> > # Date 1483729033 28800
> > #      Fri Jan 06 10:57:13 2017 -0800
> > # Node ID 1901566ab484a56b177b88ff080d635840e0912c
> > # Parent  3de9df6ee5bf7601aa3870f18304bbeb3ce351af
> > convert: add config option to control saving Git committer in message
> >
> > As part of converting a Git repository to Mercurial at Mozilla, I
> > encountered a scenario where I didn't want `hg convert` to
> > automatically add the "committer: <committer>" line to commit messages.
> > While I can hack around it downstream by rewriting the Git commit
> > before feeding it into `hg convert`, I'd prefer to just specify a
> > config flag to turn it off. This patch adds that flag.
>
> I'm fine with this as-is but what about maybe storing it in the
> metadata? Just a thought.
>

I can implement that as a follow-up feature, behind yet another config
flag. There's a reason I put "message" in the config option :)
Sean Farley - Jan. 6, 2017, 7:48 p.m.
Gregory Szorc <gregory.szorc@gmail.com> writes:

> On Fri, Jan 6, 2017 at 11:36 AM, Sean Farley <sean@farley.io> wrote:
>
>> Gregory Szorc <gregory.szorc@gmail.com> writes:
>>
>> > # HG changeset patch
>> > # User Gregory Szorc <gregory.szorc@gmail.com>
>> > # Date 1483729033 28800
>> > #      Fri Jan 06 10:57:13 2017 -0800
>> > # Node ID 1901566ab484a56b177b88ff080d635840e0912c
>> > # Parent  3de9df6ee5bf7601aa3870f18304bbeb3ce351af
>> > convert: add config option to control saving Git committer in message
>> >
>> > As part of converting a Git repository to Mercurial at Mozilla, I
>> > encountered a scenario where I didn't want `hg convert` to
>> > automatically add the "committer: <committer>" line to commit messages.
>> > While I can hack around it downstream by rewriting the Git commit
>> > before feeding it into `hg convert`, I'd prefer to just specify a
>> > config flag to turn it off. This patch adds that flag.
>>
>> I'm fine with this as-is but what about maybe storing it in the
>> metadata? Just a thought.
>>
>
> I can implement that as a follow-up feature, behind yet another config
> flag. There's a reason I put "message" in the config option :)

Fair enough :-)
Gregory Szorc - Jan. 6, 2017, 8:21 p.m.
On Fri, Jan 6, 2017 at 11:48 AM, Sean Farley <sean@farley.io> wrote:

> Gregory Szorc <gregory.szorc@gmail.com> writes:
>
> > On Fri, Jan 6, 2017 at 11:36 AM, Sean Farley <sean@farley.io> wrote:
> >
> >> Gregory Szorc <gregory.szorc@gmail.com> writes:
> >>
> >> > # HG changeset patch
> >> > # User Gregory Szorc <gregory.szorc@gmail.com>
> >> > # Date 1483729033 28800
> >> > #      Fri Jan 06 10:57:13 2017 -0800
> >> > # Node ID 1901566ab484a56b177b88ff080d635840e0912c
> >> > # Parent  3de9df6ee5bf7601aa3870f18304bbeb3ce351af
> >> > convert: add config option to control saving Git committer in message
> >> >
> >> > As part of converting a Git repository to Mercurial at Mozilla, I
> >> > encountered a scenario where I didn't want `hg convert` to
> >> > automatically add the "committer: <committer>" line to commit
> messages.
> >> > While I can hack around it downstream by rewriting the Git commit
> >> > before feeding it into `hg convert`, I'd prefer to just specify a
> >> > config flag to turn it off. This patch adds that flag.
> >>
> >> I'm fine with this as-is but what about maybe storing it in the
> >> metadata? Just a thought.
> >>
> >
> > I can implement that as a follow-up feature, behind yet another config
> > flag. There's a reason I put "message" in the config option :)
>
> Fair enough :-)
>

Thinking about this a little more, I suppose I can have a single option
defining a list of actions to take w.r.t. author and committer. If you feel
this is more appropriate, please drop and I'll send V2.
Sean Farley - Jan. 6, 2017, 9:51 p.m.
Gregory Szorc <gregory.szorc@gmail.com> writes:

> On Fri, Jan 6, 2017 at 11:48 AM, Sean Farley <sean@farley.io> wrote:
>
>> Gregory Szorc <gregory.szorc@gmail.com> writes:
>>
>> > On Fri, Jan 6, 2017 at 11:36 AM, Sean Farley <sean@farley.io> wrote:
>> >
>> >> Gregory Szorc <gregory.szorc@gmail.com> writes:
>> >>
>> >> > # HG changeset patch
>> >> > # User Gregory Szorc <gregory.szorc@gmail.com>
>> >> > # Date 1483729033 28800
>> >> > #      Fri Jan 06 10:57:13 2017 -0800
>> >> > # Node ID 1901566ab484a56b177b88ff080d635840e0912c
>> >> > # Parent  3de9df6ee5bf7601aa3870f18304bbeb3ce351af
>> >> > convert: add config option to control saving Git committer in message
>> >> >
>> >> > As part of converting a Git repository to Mercurial at Mozilla, I
>> >> > encountered a scenario where I didn't want `hg convert` to
>> >> > automatically add the "committer: <committer>" line to commit
>> messages.
>> >> > While I can hack around it downstream by rewriting the Git commit
>> >> > before feeding it into `hg convert`, I'd prefer to just specify a
>> >> > config flag to turn it off. This patch adds that flag.
>> >>
>> >> I'm fine with this as-is but what about maybe storing it in the
>> >> metadata? Just a thought.
>> >>
>> >
>> > I can implement that as a follow-up feature, behind yet another config
>> > flag. There's a reason I put "message" in the config option :)
>>
>> Fair enough :-)
>>
>
> Thinking about this a little more, I suppose I can have a single option
> defining a list of actions to take w.r.t. author and committer. If you feel
> this is more appropriate, please drop and I'll send V2.

At least to me, that sounds pretty robust / better.
Mike Hommey - Jan. 6, 2017, 10:51 p.m.
On Fri, Jan 06, 2017 at 11:36:32AM -0800, Sean Farley wrote:
> Gregory Szorc <gregory.szorc@gmail.com> writes:
> 
> > # HG changeset patch
> > # User Gregory Szorc <gregory.szorc@gmail.com>
> > # Date 1483729033 28800
> > #      Fri Jan 06 10:57:13 2017 -0800
> > # Node ID 1901566ab484a56b177b88ff080d635840e0912c
> > # Parent  3de9df6ee5bf7601aa3870f18304bbeb3ce351af
> > convert: add config option to control saving Git committer in message
> >
> > As part of converting a Git repository to Mercurial at Mozilla, I
> > encountered a scenario where I didn't want `hg convert` to
> > automatically add the "committer: <committer>" line to commit messages.
> > While I can hack around it downstream by rewriting the Git commit
> > before feeding it into `hg convert`, I'd prefer to just specify a
> > config flag to turn it off. This patch adds that flag.
> 
> I'm fine with this as-is but what about maybe storing it in the
> metadata? Just a thought.

... like hg-git does.

Mike
Augie Fackler - Jan. 7, 2017, 5:51 p.m.
On Fri, Jan 06, 2017 at 01:51:59PM -0800, Sean Farley wrote:
> Gregory Szorc <gregory.szorc@gmail.com> writes:
>
> > On Fri, Jan 6, 2017 at 11:48 AM, Sean Farley <sean@farley.io> wrote:
> >
> >> Gregory Szorc <gregory.szorc@gmail.com> writes:
> >>
> >> > On Fri, Jan 6, 2017 at 11:36 AM, Sean Farley <sean@farley.io> wrote:
> >> >
> >> >> Gregory Szorc <gregory.szorc@gmail.com> writes:
> >> >>
> >> >> > # HG changeset patch
> >> >> > # User Gregory Szorc <gregory.szorc@gmail.com>
> >> >> > # Date 1483729033 28800
> >> >> > #      Fri Jan 06 10:57:13 2017 -0800
> >> >> > # Node ID 1901566ab484a56b177b88ff080d635840e0912c
> >> >> > # Parent  3de9df6ee5bf7601aa3870f18304bbeb3ce351af
> >> >> > convert: add config option to control saving Git committer in message
> >> >> >
> >> >> > As part of converting a Git repository to Mercurial at Mozilla, I
> >> >> > encountered a scenario where I didn't want `hg convert` to
> >> >> > automatically add the "committer: <committer>" line to commit
> >> messages.
> >> >> > While I can hack around it downstream by rewriting the Git commit
> >> >> > before feeding it into `hg convert`, I'd prefer to just specify a
> >> >> > config flag to turn it off. This patch adds that flag.
> >> >>
> >> >> I'm fine with this as-is but what about maybe storing it in the
> >> >> metadata? Just a thought.
> >> >>
> >> >
> >> > I can implement that as a follow-up feature, behind yet another config
> >> > flag. There's a reason I put "message" in the config option :)
> >>
> >> Fair enough :-)
> >>
> >
> > Thinking about this a little more, I suppose I can have a single option
> > defining a list of actions to take w.r.t. author and committer. If you feel
> > this is more appropriate, please drop and I'll send V2.
>
> At least to me, that sounds pretty robust / better.

I'd like to see it. Feel encouraged to send a proposed config spec
before rolling the whole v2 if you want early feedback on that (I'm
not quite sure what you have in mind, but I'm also not worried given
your track record.)

> _______________________________________________
> 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
@@ -340,6 +340,11 @@  def convert(ui, src, dest=None, revmapfi
     :convert.git.saverev: whether to store the original Git commit ID in the
         metadata of the destination commit. The default is True.
 
+    :convert.git.savecommitterinmessage: whether to record the Git commit
+        "committer" in the commit message if it is different from the commit
+        "author." When enable, a ``committer: <committer>`` line is appended
+        to the commit message as necessary. 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
--- a/hgext/convert/git.py
+++ b/hgext/convert/git.py
@@ -317,7 +317,10 @@  class convert_git(common.converter_sourc
             if n in self.copyextrakeys:
                 extra[n] = v
 
-        if committer and committer != author:
+        committerinmessage = self.ui.configbool('convert',
+                                                'git.savecommitterinmessage',
+                                                True)
+        if committer and committer != author and committerinmessage:
             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))
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
@@ -482,6 +482,37 @@  convert author committer
   
   
 
+recording committer in commit message can be disabled
+
+  $ hg --config convert.git.savecommitterinmessage=false convert git-repo4 git-repo4-hg-no-committer
+  initializing destination git-repo4-hg-no-committer repository
+  scanning source...
+  sorting...
+  converting...
+  1 addfoo
+  0 addfoo2
+  updating bookmarks
+
+  $ hg -R git-repo4-hg-no-committer log -v
+  changeset:   1:190b2da396cc
+  bookmark:    master
+  tag:         tip
+  user:        nottest <test@example.org>
+  date:        Mon Jan 01 00:00:21 2007 +0000
+  files:       foo
+  description:
+  addfoo2
+  
+  
+  changeset:   0:0735477b0224
+  user:        test <test@example.org>
+  date:        Mon Jan 01 00:00:20 2007 +0000
+  files:       foo
+  description:
+  addfoo
+  
+  
+
 --sourceorder should fail
 
   $ hg convert --sourcesort git-repo4 git-repo4-sourcesort-hg
diff --git a/tests/test-convert.t b/tests/test-convert.t
--- a/tests/test-convert.t
+++ b/tests/test-convert.t
@@ -282,6 +282,11 @@ 
       convert.git.saverev
                     whether to store the original Git commit ID in the metadata
                     of the destination commit. The default is True.
+      convert.git.savecommitterinmessage
+                    whether to record the Git commit "committer" in the commit
+                    message if it is different from the commit "author." When
+                    enable, a "committer: <committer>" line is appended to the
+                    commit message as necessary. 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.