commit: 2f194c3aa5182694c1c94e9225a78bac9a54ebbd Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> AuthorDate: Sat Sep 19 02:07:27 2015 +0000 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> CommitDate: Sun Sep 20 02:00:29 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=2f194c3a
repoman/actions.py: Break out changes detectection into sudo vcs plugins pym/repoman/actions.py | 215 +++++++++++++++++++++++++++---------------------- 1 file changed, 120 insertions(+), 95 deletions(-) diff --git a/pym/repoman/actions.py b/pym/repoman/actions.py index 611c0dd..1f70815 100644 --- a/pym/repoman/actions.py +++ b/pym/repoman/actions.py @@ -74,102 +74,9 @@ class Actions(object): self._vcs_deleted(mydeleted) - if self.vcs_settings.vcs == "cvs": - mycvstree = cvstree.getentries("./", recursive=1) - mychanged = cvstree.findchanged(mycvstree, recursive=1, basedir="./") - mynew = cvstree.findnew(mycvstree, recursive=1, basedir="./") - myremoved = portage.cvstree.findremoved(mycvstree, recursive=1, basedir="./") - bin_blob_pattern = re.compile("^-kb$") - no_expansion = set(portage.cvstree.findoption( - mycvstree, bin_blob_pattern, recursive=1, basedir="./")) - - if self.vcs_settings.vcs == "svn": - with repoman_popen("svn status") as f: - svnstatus = f.readlines() - mychanged = [ - "./" + elem.split()[-1:][0] - for elem in svnstatus - if (elem[:1] in "MR" or elem[1:2] in "M")] - mynew = [ - "./" + elem.split()[-1:][0] - for elem in svnstatus - if elem.startswith("A")] - myremoved = [ - "./" + elem.split()[-1:][0] - for elem in svnstatus - if elem.startswith("D")] - - # Subversion expands keywords specified in svn:keywords properties. - with repoman_popen("svn propget -R svn:keywords") as f: - props = f.readlines() - expansion = dict( - ("./" + prop.split(" - ")[0], prop.split(" - ")[1].split()) - for prop in props if " - " in prop) - - elif self.vcs_settings.vcs == "git": - with repoman_popen( - "git diff-index --name-only " - "--relative --diff-filter=M HEAD") as f: - mychanged = f.readlines() - mychanged = ["./" + elem[:-1] for elem in mychanged] - - with repoman_popen( - "git diff-index --name-only " - "--relative --diff-filter=A HEAD") as f: - mynew = f.readlines() - mynew = ["./" + elem[:-1] for elem in mynew] - - with repoman_popen( - "git diff-index --name-only " - "--relative --diff-filter=D HEAD") as f: - myremoved = f.readlines() - myremoved = ["./" + elem[:-1] for elem in myremoved] - - if self.vcs_settings.vcs == "bzr": - with repoman_popen("bzr status -S .") as f: - bzrstatus = f.readlines() - mychanged = [ - "./" + elem.split()[-1:][0].split('/')[-1:][0] - for elem in bzrstatus - if elem and elem[1:2] == "M"] - mynew = [ - "./" + elem.split()[-1:][0].split('/')[-1:][0] - for elem in bzrstatus - if elem and (elem[1:2] in "NK" or elem[0:1] == "R")] - myremoved = [ - "./" + elem.split()[-1:][0].split('/')[-1:][0] - for elem in bzrstatus - if elem.startswith("-")] - myremoved = [ - "./" + elem.split()[-3:-2][0].split('/')[-1:][0] - for elem in bzrstatus - if elem and (elem[1:2] == "K" or elem[0:1] == "R")] - # Bazaar expands nothing. - - if self.vcs_settings.vcs == "hg": - with repoman_popen("hg status --no-status --modified .") as f: - mychanged = f.readlines() - mychanged = ["./" + elem.rstrip() for elem in mychanged] - - with repoman_popen("hg status --no-status --added .") as f: - mynew = f.readlines() - mynew = ["./" + elem.rstrip() for elem in mynew] - - with repoman_popen("hg status --no-status --removed .") as f: - myremoved = f.readlines() - myremoved = ["./" + elem.rstrip() for elem in myremoved] + changes = self.get_vcs_changed(mydeleted) - if self.vcs_settings.vcs: - a_file_is_changed = mychanged or mynew or myremoved - a_file_is_deleted_hg = self.vcs_settings.vcs == "hg" and mydeleted - - if not (a_file_is_changed or a_file_is_deleted_hg): - utilities.repoman_sez( - "\"Doing nothing is not always good for QA.\"") - print() - print("(Didn't find any changed files...)") - print() - sys.exit(1) + mynew, mychanged, myremoved, no_expansion, expansion = changes # Manifests need to be regenerated after all other commits, so don't commit # them now even if they have changed. @@ -772,3 +679,121 @@ class Actions(object): print() print() sys.exit(1) + + + def get_vcs_changed(self, mydeleted): + '''Holding function which calls the approriate VCS module for the data''' + changed = ([], [], [], [], []) + if self.vcs_settings.vcs: + vcs_module = getattr(self, '_get_changed_%s_' % self.vcs_settings.vcs) + changed = vcs_module(mydeleted) + mynew, mychanged, myremoved, no_expansion, expansion = changed + + a_file_is_changed = mychanged or mynew or myremoved + a_file_is_deleted_hg = self.vcs_settings.vcs == "hg" and mydeleted + + if not (a_file_is_changed or a_file_is_deleted_hg): + utilities.repoman_sez( + "\"Doing nothing is not always good for QA.\"") + print() + print("(Didn't find any changed files...)") + print() + sys.exit(1) + return changed + + + def _get_changed_cvs_(self, mydeleted): + mycvstree = cvstree.getentries("./", recursive=1) + mychanged = cvstree.findchanged(mycvstree, recursive=1, basedir="./") + mynew = cvstree.findnew(mycvstree, recursive=1, basedir="./") + myremoved = portage.cvstree.findremoved(mycvstree, recursive=1, basedir="./") + bin_blob_pattern = re.compile("^-kb$") + no_expansion = set(portage.cvstree.findoption( + mycvstree, bin_blob_pattern, recursive=1, basedir="./")) + expansion = {} + return (mynew, mychanged, myremoved, no_expansion, expansion) + + def _get_changed_svn_(self, mydeleted): + with repoman_popen("svn status") as f: + svnstatus = f.readlines() + mychanged = [ + "./" + elem.split()[-1:][0] + for elem in svnstatus + if (elem[:1] in "MR" or elem[1:2] in "M")] + mynew = [ + "./" + elem.split()[-1:][0] + for elem in svnstatus + if elem.startswith("A")] + myremoved = [ + "./" + elem.split()[-1:][0] + for elem in svnstatus + if elem.startswith("D")] + # Subversion expands keywords specified in svn:keywords properties. + with repoman_popen("svn propget -R svn:keywords") as f: + props = f.readlines() + expansion = dict( + ("./" + prop.split(" - ")[0], prop.split(" - ")[1].split()) + for prop in props if " - " in prop) + no_expansion = set() + return (mynew, mychanged, myremoved, no_expansion, expansion) + + def _get_changed_git_(self, mydeleted): + with repoman_popen( + "git diff-index --name-only " + "--relative --diff-filter=M HEAD") as f: + mychanged = f.readlines() + mychanged = ["./" + elem[:-1] for elem in mychanged] + with repoman_popen( + "git diff-index --name-only " + "--relative --diff-filter=A HEAD") as f: + mynew = f.readlines() + mynew = ["./" + elem[:-1] for elem in mynew] + with repoman_popen( + "git diff-index --name-only " + "--relative --diff-filter=D HEAD") as f: + myremoved = f.readlines() + myremoved = ["./" + elem[:-1] for elem in myremoved] + no_expansion = set() + expansion = {} + return (mynew, mychanged, myremoved, no_expansion, expansion) + + def _get_changed_bzr_(self, mydeleted): + with repoman_popen("bzr status -S .") as f: + bzrstatus = f.readlines() + mychanged = [ + "./" + elem.split()[-1:][0].split('/')[-1:][0] + for elem in bzrstatus + if elem and elem[1:2] == "M"] + mynew = [ + "./" + elem.split()[-1:][0].split('/')[-1:][0] + for elem in bzrstatus + if elem and (elem[1:2] in "NK" or elem[0:1] == "R")] + myremoved = [ + "./" + elem.split()[-1:][0].split('/')[-1:][0] + for elem in bzrstatus + if elem.startswith("-")] + myremoved = [ + "./" + elem.split()[-3:-2][0].split('/')[-1:][0] + for elem in bzrstatus + if elem and (elem[1:2] == "K" or elem[0:1] == "R")] + # Bazaar expands nothing. + no_expansion = set() + expansion = {} + return (mynew, mychanged, myremoved, no_expansion, expansion) + + def _get_changed_hg_(self, mydeleted): + with repoman_popen("hg status --no-status --modified .") as f: + mychanged = f.readlines() + mychanged = ["./" + elem.rstrip() for elem in mychanged] + + with repoman_popen("hg status --no-status --added .") as f: + mynew = f.readlines() + mynew = ["./" + elem.rstrip() for elem in mynew] + + with repoman_popen("hg status --no-status --removed .") as f: + myremoved = f.readlines() + myremoved = ["./" + elem.rstrip() for elem in myremoved] + no_expansion = set() + expansion = {} + return (mynew, mychanged, myremoved, no_expansion, expansion) +