Also add a "changeid" configuration, (overridden by the command line
option "--no-changeid") which will automatically add a new "Change-Id:"
line to commits. This is useful for when working with Gerrit, as the
commit hook is not run during stgit workflow.

Signed-off-by: Jacob Keller <[email protected]>
---
 examples/gitconfig        | 3 +++
 stgit/argparse.py         | 6 ++++++
 stgit/commands/common.py  | 7 +++++++
 stgit/commands/edit.py    | 2 +-
 stgit/commands/refresh.py | 2 +-
 stgit/lib/edit.py         | 4 +++-
 stgit/stack.py            | 8 ++++++--
 7 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/examples/gitconfig b/examples/gitconfig
index 48a42468b76b..51da75cbb771 100644
--- a/examples/gitconfig
+++ b/examples/gitconfig
@@ -17,6 +17,9 @@
        # Automatically sign newly created patches
        #autosign = Signed-off-by
 
+       # Automatically generate gerrit style change id
+       #changeid = true
+
        # SMTP server for sending patches
        #smtpserver = /usr/sbin/sendmail -t -i
        #smtpserver = localhost:25
diff --git a/stgit/argparse.py b/stgit/argparse.py
index 43c6cf9bbbb3..b8ddb1f27ed9 100644
--- a/stgit/argparse.py
+++ b/stgit/argparse.py
@@ -113,6 +113,12 @@ def callback(option, opt_str, value, parser, sign_str):
                 'Cannot give more than one of --ack, --sign, --review')
         parser.values.sign_str = sign_str
     return [
+        opt('--changeid', action = 'store_true', dest='changeid',
+            short = 'Add a "Change-Id:" line', long = """
+            Add a "Change-Id:" to the end of the patch."""),
+        opt('--no-changeid', action = 'store_false', dest='changeid',
+            short = 'Do not add a "Change-Id:" line', long = """
+            Do not add a "Change-Id:" to the end of the patch."""),
         opt('--sign', action = 'callback', dest = 'sign_str', args = [],
             callback = callback, callback_args = ('Signed-off-by',),
             short = 'Add "Signed-off-by:" line', long = """
diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index 1a7044b5a738..4ff5657d6320 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -485,6 +485,13 @@ def update_commit_data(cd, options):
     # Modify author data.
     cd = cd.set_author(options.author(cd.author))
 
+    # Add Change-Id:
+    changeid = options.changeid
+    if changeid == None:
+        changeid = config.getbool("stgit.changeid")
+    if changeid:
+        cd = cd.set_message(add_changeid_line(cd.message, cd.changeid()))
+
     # Add Signed-off-by: or similar.
     if options.sign_str != None:
         sign_str = options.sign_str
diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py
index c8ef31f999dc..79c671f3009e 100644
--- a/stgit/commands/edit.py
+++ b/stgit/commands/edit.py
@@ -102,7 +102,7 @@ def func(parser, options, args):
     cd, failed_diff = edit.auto_edit_patch(
         stack.repository, cd, msg = options.message, contains_diff = True,
         author = options.author, committer = lambda p: p,
-        sign_str = options.sign_str)
+        sign_str = options.sign_str, changeid = options.changeid)
 
     if options.save_template:
         options.save_template(
diff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py
index aebfd8fb36f0..521b9352160d 100644
--- a/stgit/commands/refresh.py
+++ b/stgit/commands/refresh.py
@@ -268,7 +268,7 @@ def edit_fun(cd):
         cd, failed_diff = edit.auto_edit_patch(
             stack.repository, cd, msg = options.message, contains_diff = False,
             author = options.author, committer = lambda p: p,
-            sign_str = options.sign_str)
+            sign_str = options.sign_str, changeid = options.changeid)
         assert not failed_diff
         if options.edit:
             cd, failed_diff = edit.interactive_edit_patch(
diff --git a/stgit/lib/edit.py b/stgit/lib/edit.py
index c8d29f64726f..1f4e370e8a1b 100644
--- a/stgit/lib/edit.py
+++ b/stgit/lib/edit.py
@@ -68,7 +68,7 @@ def interactive_edit_patch(repo, cd, edit_diff, diff_flags, 
replacement_diff):
             '.stgit-edit.' + ['txt', 'patch'][bool(edit_diff)]),
         edit_diff)
 
-def auto_edit_patch(repo, cd, msg, contains_diff, author, committer, sign_str):
+def auto_edit_patch(repo, cd, msg, contains_diff, author, committer, sign_str, 
changeid = False):
     """Edit the patch noninteractively in a couple of ways:
 
          - If C{msg} is not C{None}, parse it to find a replacement
@@ -92,6 +92,8 @@ def auto_edit_patch(repo, cd, msg, contains_diff, author, 
committer, sign_str):
     a, c = author(cd.author), committer(cd.committer)
     if (a, c) != (cd.author, cd.committer):
         cd = cd.set_author(a).set_committer(c)
+    if changeid:
+        cd = cd.set_message(utils.add_changeid_line(cd.message, cd.changeid()))
     if sign_str != None:
         cd = cd.set_message(utils.add_sign_line(
                 cd.message, sign_str, git.Person.committer().name,
diff --git a/stgit/stack.py b/stgit/stack.py
index f79f76feabbc..f41e3f07b7a5 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -680,7 +680,7 @@ def refresh_patch(self, files = None, message = None, edit 
= False,
                       author_date = None,
                       committer_name = None, committer_email = None,
                       backup = True, sign_str = None, log = 'refresh',
-                      notes = None, bottom = None):
+                      notes = None, bottom = None, changeid = None):
         """Generates a new commit for the topmost patch
         """
         patch = self.get_current_patch()
@@ -710,6 +710,8 @@ def refresh_patch(self, files = None, message = None, edit 
= False,
         if not committer_email:
             committer_email = patch.get_commemail()
 
+        descr = add_changeid_line(descr, changeid)
+
         descr = add_sign_line(descr, sign_str, committer_name, committer_email)
 
         if not bottom:
@@ -750,7 +752,7 @@ def new_patch(self, name, message = None, can_edit = True,
                   top = None, bottom = None, commit = True,
                   author_name = None, author_email = None, author_date = None,
                   committer_name = None, committer_email = None,
-                  before_existing = False, sign_str = None):
+                  before_existing = False, sign_str = None, changeid = None):
         """Creates a new patch, either pointing to an existing commit object,
         or by creating a new commit object.
         """
@@ -769,6 +771,8 @@ def new_patch(self, name, message = None, can_edit = True,
         # TODO: move this out of the stgit.stack module, it is really
         # for higher level commands to handle the user interaction
         def sign(msg):
+            msg = add_changeid_line(msg, changeid)
+
             return add_sign_line(msg, sign_str,
                                  committer_name or git.committer().name,
                                  committer_email or git.committer().email)
-- 
2.6.1.264.gbab76a9


_______________________________________________
stgit-users mailing list
[email protected]
https://mail.gna.org/listinfo/stgit-users

Reply via email to