Commits

Angel Ezquerra  committed eaa6503

commit: refactor code that reads and displays the current options

The code that reads the current repository options and displays it has been
refactored into its own functions. This is necessary to be able to reuse this
code from the commit panel of the merge dialog (which will be done on a
separate, future patch).

  • Participants
  • Parent commits a035d36
  • Branches stable

Comments (0)

Files changed (1)

File tortoisehg/hgqt/commit.py

 else:
     _hasbugtraq = False
 
+def readrepoopts(repo):
+    opts = {}
+    opts['ciexclude'] = repo.ui.config('tortoisehg', 'ciexclude', '')
+    opts['pushafter'] = repo.ui.config('tortoisehg', 'cipushafter', '')
+    opts['autoinc'] = repo.ui.config('tortoisehg', 'autoinc', '')
+    opts['recurseinsubrepos'] = repo.ui.config('tortoisehg', 'recurseinsubrepos', None)
+    opts['bugtraqplugin'] = repo.ui.config('tortoisehg', 'issue.bugtraqplugin', None)
+    opts['bugtraqparameters'] = repo.ui.config('tortoisehg', 'issue.bugtraqparameters', None)
+    if opts['bugtraqparameters']:
+        opts['bugtraqparameters'] = os.path.expandvars(opts['bugtraqparameters'])
+    opts['bugtraqtrigger'] = repo.ui.config('tortoisehg', 'issue.bugtraqtrigger', None)
+
+    return opts
+
+def commitopts2str(opts, mode='commit'):
+    optslist = []
+    for opt, value in opts.iteritems():
+        if opt in ['user', 'date', 'pushafter', 'autoinc',
+                   'recurseinsubrepos']:
+            if mode == 'merge' and opt == 'autoinc':
+                # autoinc does not apply to merge commits
+                continue
+            if value is True:
+                optslist.append('--' + opt)
+            elif value:
+                optslist.append('--%s=%s' % (opt, value))
+    return ' '.join(optslist)
+
 # Technical Debt for CommitWidget
 #  disable commit button while no message is entered or no files are selected
 #  qtlib decode failure dialog (ask for retry locale, suggest HGENCODING)
         self.currentAction = None
         self.currentProgress = None
 
-        opts['ciexclude'] = repo.ui.config('tortoisehg', 'ciexclude', '')
-        opts['pushafter'] = repo.ui.config('tortoisehg', 'cipushafter', '')
-        opts['autoinc'] = repo.ui.config('tortoisehg', 'autoinc', '')
-        opts['recurseinsubrepos'] = repo.ui.config('tortoisehg', 'recurseinsubrepos', None)
-        opts['bugtraqplugin'] = repo.ui.config('tortoisehg', 'issue.bugtraqplugin', None)
-        opts['bugtraqparameters'] = repo.ui.config('tortoisehg', 'issue.bugtraqparameters', None)
-        if opts['bugtraqparameters']:
-            opts['bugtraqparameters'] = os.path.expandvars(opts['bugtraqparameters'])
-        opts['bugtraqtrigger'] = repo.ui.config('tortoisehg', 'issue.bugtraqtrigger', None)
-        self.opts = opts # user, date
+        self.opts = opts = readrepoopts(repo) # user, date
 
         self.stwidget = status.StatusWidget(repo, pats, opts, self)
         self.stwidget.showMessage.connect(self.showMessage)
         self.branchbutton.setText(title)
 
         # Update options label, showing only whitelisted options.
-        opts = []
-        for opt, value in self.opts.iteritems():
-            if opt in ['user', 'date', 'pushafter', 'autoinc',
-                       'recurseinsubrepos']:
-                if value is True:
-                    opts.append('--' + opt)
-                elif value:
-                    opts.append('--%s=%s' % (opt, value))
-
+        opts = commitopts2str(self.opts)
         self.optionslabelfmt = _('<b>Selected Options:</b> %s')
         self.optionslabel.setText(self.optionslabelfmt
-                                  % hglib.tounicode(' '.join(opts)))
+                                  % hglib.tounicode(opts))
         self.optionslabel.setVisible(bool(opts))
 
         # Update parent csinfo widget