From 65f42bebc99575c33fd7239dfb31b685176c4b1c Mon Sep 17 00:00:00 2001
From: Jonas Finnemann Jensen <jopsen@gmail.com>
Date: Wed, 4 Sep 2013 15:32:00 -0700
Subject: [PATCH] Bug 910658 - Add "qnew = -U" to defaults section in mach
 mercurial-setup; r=gps

DONTBUILD (NPOTB)
---
 tools/mercurial/hgsetup/config.py | 28 ++++++++++++++++++++++++++++
 tools/mercurial/hgsetup/wizard.py | 14 ++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/tools/mercurial/hgsetup/config.py b/tools/mercurial/hgsetup/config.py
index b5b20ef50d2e5..650d5a6cb2ac8 100644
--- a/tools/mercurial/hgsetup/config.py
+++ b/tools/mercurial/hgsetup/config.py
@@ -5,6 +5,7 @@
 from __future__ import unicode_literals
 
 from configobj import ConfigObj
+import re
 
 
 BUGZILLA_FINGERPRINT = '45:77:35:fd:6f:2c:1c:c2:90:4b:f7:b4:4d:60:c6:97:c5:5c:47:27'
@@ -115,3 +116,30 @@ class MercurialConfig(object):
                 del self._c['mqext']['mqcommit']
             except KeyError:
                 pass
+
+
+    def have_qnew_currentuser_default(self):
+        if 'defaults' not in self._c:
+            return False
+        d = self._c['defaults']
+        if 'qnew' not in d:
+            return False
+        argv = d['qnew'].split(' ')
+        for arg in argv:
+            if arg == '--currentuser' or re.match("-[^-]*U.*", arg):
+                return True
+        return False
+
+    def ensure_qnew_currentuser_default(self):
+        if self.have_qnew_currentuser_default():
+            return
+        if 'defaults' not in self._c:
+            self._c['defaults'] = {}
+
+        d = self._c['defaults']
+        if 'qnew' not in d:
+          d['qnew'] = '-U'
+        else:
+          d['qnew'] = '-U ' + d['qnew']
+
+
diff --git a/tools/mercurial/hgsetup/wizard.py b/tools/mercurial/hgsetup/wizard.py
index 979ebfb191af7..6317e5834b465 100644
--- a/tools/mercurial/hgsetup/wizard.py
+++ b/tools/mercurial/hgsetup/wizard.py
@@ -71,6 +71,12 @@ import patches from Bugzilla using a friendly bz:// URL handler. e.g.
 |hg qimport bz://123456|.
 '''.strip()
 
+QNEWCURRENTUSER_INFO = '''
+The mercurial queues command |hg qnew|, which creates new patches in your patch
+queue does not set patch author information by default. Author information
+should be included when uploading for review.
+'''.strip()
+
 FINISHED = '''
 Your Mercurial should now be properly configured and recommended extensions
 should be up to date!
@@ -204,6 +210,14 @@ class MercurialSetupWizard(object):
                     'default',
                     'Ensuring qimportbz extension is up to date...')
 
+            if not c.have_qnew_currentuser_default():
+                print(QNEWCURRENTUSER_INFO)
+                if self._prompt_yn('Would you like qnew to set patch author by '
+                                   'default'):
+                    c.ensure_qnew_currentuser_default()
+                    print('Configured qnew to set patch author by default.')
+                    print('')
+
         c.add_mozilla_host_fingerprints()
 
         b = StringIO()
-- 
GitLab