commit: 16407a22bd2099f880fe3aabe3b985f8683d34c1 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> AuthorDate: Tue Feb 16 20:06:30 2016 +0000 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> CommitDate: Tue Feb 16 20:06:30 2016 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=16407a22
repoman: Migrate the commit code to the vcs modules pym/repoman/actions.py | 84 +++++++++------------------------ pym/repoman/modules/vcs/None/changes.py | 13 +++++ pym/repoman/modules/vcs/bzr/changes.py | 1 - pym/repoman/modules/vcs/changes.py | 20 ++++++++ pym/repoman/modules/vcs/cvs/changes.py | 1 - pym/repoman/modules/vcs/git/changes.py | 10 ++++ pym/repoman/modules/vcs/hg/changes.py | 16 +++++++ 7 files changed, 82 insertions(+), 63 deletions(-) diff --git a/pym/repoman/actions.py b/pym/repoman/actions.py index c2222dd..4393e52 100644 --- a/pym/repoman/actions.py +++ b/pym/repoman/actions.py @@ -7,21 +7,19 @@ import io import logging import platform import signal -import subprocess import sys import tempfile from itertools import chain from _emerge.UserQuery import UserQuery -import portage +from repoman._portage import portage from portage import os from portage import _encodings from portage import _unicode_encode from portage.output import ( bold, create_color_func, green, red) from portage.package.ebuild.digestgen import digestgen -from portage.process import find_binary, spawn from portage.util import writemsg_level from repoman.gpg import gpgsign, need_signature @@ -432,43 +430,18 @@ class Actions(object): mymsg.write(_unicode_encode(commitmessage)) mymsg.close() - commit_cmd = [] - if self.options.pretend and self.vcs_settings.vcs is None: - # substitute a bogus value for pretend output - commit_cmd.append("cvs") - else: - commit_cmd.append(self.vcs_settings.vcs) - commit_cmd.extend(self.vcs_settings.vcs_global_opts) - commit_cmd.append("commit") - commit_cmd.extend(self.vcs_settings.vcs_local_opts) - if self.vcs_settings.vcs == "hg": - commit_cmd.extend(["--logfile", commitmessagefile]) - commit_cmd.extend(myfiles) - else: - commit_cmd.extend(["-F", commitmessagefile]) - commit_cmd.extend(f.lstrip("./") for f in myfiles) - + retval = self.vcs_settings.changes.commit(myfiles, commitmessagefile) + # cleanup the commit message before possibly exiting try: - if self.options.pretend: - print("(%s)" % (" ".join(commit_cmd),)) - else: - retval = spawn(commit_cmd, env=self.repo_settings.commit_env) - if retval != os.EX_OK: - if self.repo_settings.repo_config.sign_commit and not self.vcs_settings.status.supports_gpg_sign(): - # Inform user that newer git is needed (bug #403323). - logging.error( - "Git >=1.7.9 is required for signed commits!") - - writemsg_level( - "!!! Exiting on %s (shell) " - "error code: %s\n" % (self.vcs_settings.vcs, retval), - level=logging.ERROR, noiselevel=-1) - sys.exit(retval) - finally: - try: - os.unlink(commitmessagefile) - except OSError: - pass + os.unlink(commitmessagefile) + except OSError: + pass + if retval != os.EX_OK: + writemsg_level( + "!!! Exiting on %s (shell) " + "error code: %s\n" % (self.vcs_settings.vcs, retval), + level=logging.ERROR, noiselevel=-1) + sys.exit(retval) def priming_commit(self, myupdates, myremoved, commitmessage): @@ -492,29 +465,18 @@ class Actions(object): # so strip the prefix. myfiles = [f.lstrip("./") for f in myfiles] - commit_cmd = [self.vcs_settings.vcs] - commit_cmd.extend(self.vcs_settings.vcs_global_opts) - commit_cmd.append("commit") - commit_cmd.extend(self.vcs_settings.vcs_local_opts) - commit_cmd.extend(["-F", commitmessagefile]) - commit_cmd.extend(myfiles) - + retval = self.vcs_settings.changes.commit(myfiles, commitmessagefile) + # cleanup the commit message before possibly exiting try: - if self.options.pretend: - print("(%s)" % (" ".join(commit_cmd),)) - else: - retval = spawn(commit_cmd, env=self.repo_settings.commit_env) - if retval != os.EX_OK: - writemsg_level( - "!!! Exiting on %s (shell) " - "error code: %s\n" % (self.vcs_settings.vcs, retval), - level=logging.ERROR, noiselevel=-1) - sys.exit(retval) - finally: - try: - os.unlink(commitmessagefile) - except OSError: - pass + os.unlink(commitmessagefile) + except OSError: + pass + if retval != os.EX_OK: + writemsg_level( + "!!! Exiting on %s (shell) " + "error code: %s\n" % (self.vcs_settings.vcs, retval), + level=logging.ERROR, noiselevel=-1) + sys.exit(retval) def sign_manifest(self, myupdates, myremoved, mymanifests): diff --git a/pym/repoman/modules/vcs/None/changes.py b/pym/repoman/modules/vcs/None/changes.py index 98beedb..7f46177 100644 --- a/pym/repoman/modules/vcs/None/changes.py +++ b/pym/repoman/modules/vcs/None/changes.py @@ -26,3 +26,16 @@ class Changes(ChangesBase): def add_items(self, myautoadd): '''Nothing to add them to''' pass + + def commit(self, myfiles, commitmessagefile): + commit_cmd = [] + # substitute a bogus vcs value for pretend output + commit_cmd.append("pretend") + commit_cmd.extend(self.vcs_settings.vcs_global_opts) + commit_cmd.append("commit") + commit_cmd.extend(self.vcs_settings.vcs_local_opts) + commit_cmd.extend(["-F", commitmessagefile]) + commit_cmd.extend(f.lstrip("./") for f in myfiles) + + print("(%s)" % (" ".join(commit_cmd),)) + return 0 diff --git a/pym/repoman/modules/vcs/bzr/changes.py b/pym/repoman/modules/vcs/bzr/changes.py index 81e7cf5..e5e61ff 100644 --- a/pym/repoman/modules/vcs/bzr/changes.py +++ b/pym/repoman/modules/vcs/bzr/changes.py @@ -57,4 +57,3 @@ class Changes(ChangesBase): for x in broken_changelog_manifests: self.repoman_settings["O"] = os.path.join(self.repo_settings.repodir, x) digestgen(mysettings=self.repoman_settings, myportdb=self.repo_settings.portdb) - diff --git a/pym/repoman/modules/vcs/changes.py b/pym/repoman/modules/vcs/changes.py index ee94217..f322cb1 100644 --- a/pym/repoman/modules/vcs/changes.py +++ b/pym/repoman/modules/vcs/changes.py @@ -10,6 +10,8 @@ from itertools import chain from repoman._portage import portage from portage import _unicode_encode +from portage.process import spawn + class ChangesBase(object): '''Base Class object to scan and hold the resultant data @@ -22,6 +24,7 @@ class ChangesBase(object): self.options = options self.repo_settings = repo_settings self.repoman_settings = repo_settings.repoman_settings + self.vcs_settings = repo_settings.vcs_settings self._reset() def _reset(self): @@ -109,3 +112,20 @@ class ChangesBase(object): logging.error( "Exiting on %s error code: %s\n" % (self.vcs_settings.vcs, retcode)) sys.exit(retcode) + + + def commit(self, myfiles, commitmessagefile): + '''Common generic commit function''' + commit_cmd = [] + commit_cmd.append(self.vcs) + commit_cmd.extend(self.vcs_settings.vcs_global_opts) + commit_cmd.append("commit") + commit_cmd.extend(self.vcs_settings.vcs_local_opts) + commit_cmd.extend(["-F", commitmessagefile]) + commit_cmd.extend(f.lstrip("./") for f in myfiles) + + if self.options.pretend: + print("(%s)" % (" ".join(commit_cmd),)) + else: + retval = spawn(commit_cmd, env=self.repo_settings.commit_env) + return retval diff --git a/pym/repoman/modules/vcs/cvs/changes.py b/pym/repoman/modules/vcs/cvs/changes.py index 39499ab..1bb13d0 100644 --- a/pym/repoman/modules/vcs/cvs/changes.py +++ b/pym/repoman/modules/vcs/cvs/changes.py @@ -88,4 +88,3 @@ class Changes(ChangesBase): scanner.repolevel, scanner.reposplit, scanner.categories)): self.repoman_settings["O"] = os.path.join(self.repo_settings.repodir, x) digestgen(mysettings=self.repoman_settings, myportdb=self.repo_settings.portdb) - diff --git a/pym/repoman/modules/vcs/git/changes.py b/pym/repoman/modules/vcs/git/changes.py index 018458c..a0b836e 100644 --- a/pym/repoman/modules/vcs/git/changes.py +++ b/pym/repoman/modules/vcs/git/changes.py @@ -90,3 +90,13 @@ class Changes(ChangesBase): "error code: %s\n" % (self.vcs_settings.vcs, retval), level=logging.ERROR, noiselevel=-1) sys.exit(retval) + + def commit(self, myfiles, commitmessagefile): + '''Git commit the changes''' + retval = super(Changes, self).commit(myfiles, commitmessagefile) + if retval != os.EX_OK: + if self.repo_settings.repo_config.sign_commit and not self.vcs_settings.status.supports_gpg_sign(): + # Inform user that newer git is needed (bug #403323). + logging.error( + "Git >=1.7.9 is required for signed commits!") + return retval diff --git a/pym/repoman/modules/vcs/hg/changes.py b/pym/repoman/modules/vcs/hg/changes.py index 2667829..522981e 100644 --- a/pym/repoman/modules/vcs/hg/changes.py +++ b/pym/repoman/modules/vcs/hg/changes.py @@ -71,3 +71,19 @@ class Changes(ChangesBase): for x in broken_changelog_manifests: self.repoman_settings["O"] = os.path.join(self.repo_settings.repodir, x) digestgen(mysettings=self.repoman_settings, myportdb=self.repo_settings.portdb) + + def commit(self, myfiles, commitmessagefile): + '''Hg commit the changes''' + commit_cmd = [] + commit_cmd.append(self.vcs) + commit_cmd.extend(self.vcs_settings.vcs_global_opts) + commit_cmd.append("commit") + commit_cmd.extend(self.vcs_settings.vcs_local_opts) + commit_cmd.extend(["--logfile", commitmessagefile]) + commit_cmd.extend(myfiles) + + if self.options.pretend: + print("(%s)" % (" ".join(commit_cmd),)) + else: + retval = spawn(commit_cmd, env=self.repo_settings.commit_env) + return retval