From b0ec418695c69bd6c69b4cf5ebd185335f4d0781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Wed, 29 Jun 2016 18:18:59 +0200 Subject: split out repo initialization from clone() to init() and reuse update() for rest --- MgaRepo/git.py | 98 ++++++++++++++++++++++++---------------------------------- 1 file changed, 41 insertions(+), 57 deletions(-) diff --git a/MgaRepo/git.py b/MgaRepo/git.py index 9760298..3462eb1 100644 --- a/MgaRepo/git.py +++ b/MgaRepo/git.py @@ -45,51 +45,32 @@ class GIT(VCS): for vcs in (SVN, GIT): if lexists(join(targetpath, vcs.vcs_dirname)): raise Error("target path %s already contains %s repository, aborting..." % (targetpath, vcs.vcs_name)) + + self.init(url, targetpath, fullnames=True, **kwargs) if url.split(':')[0].find("svn") < 0: return VCS.clone(self, url, **kwargs) else: - # To speed things up on huge repositories, we'll just grab all the - # revision numbers for this specific directory and grab these only - # in stead of having to go through each and every revision... - cmd = ["svn", "log", "-g", "--xml", url] - retval, result = execcmd(*cmd) - if retval: - return retval - xmllog = ElementTree.fromstring(result) - logentries = xmllog.getiterator("logentry") - revisions = [] - topurl = dirname(url) - trunk = basename(url) - tags = "releases" - # cloning svn braches as well should rather be optionalif reenabled.. - #cmd = ["svn", "init", topurl, "--trunk="+trunk, "--tags="+tags", targetpath] - - - cmd = ["svn", "init", url, abspath(targetpath)] - self._execVcs(*cmd, **kwargs) - os.environ.update({"GIT_WORK_TREE" : abspath(targetpath), "GIT_DIR" : join(abspath(targetpath),".git")}) - - for entry in logentries: - revisions.append(int(entry.attrib["revision"])) - revisions.sort() - - fetchcmd = ["svn", "fetch", "--log-window-size=1000"] - if fullnames: - usermap = UserTagParser() - # store configuration in local git config so that'll be reused later when ie. updating - gitconfig = {"svn-remote.authorlog.url" : usermap.url, - "svn-remote.authorlog.defaultmail": usermap.defaultmail} - self.configset(gitconfig) - usermapfile = usermap.get_user_map_file() - fetchcmd.extend(("--authors-file", usermapfile)) - - while revisions: - self._execVcs(*fetchcmd + ["-r%d"%revisions.pop(0)], **kwargs) - if fullnames: - usermap.cleanup() - - cmd = ["svn", "rebase", "--log-window-size=1000", "--local", "--fetch-all", "git-svn"] - return self._execVcs_success(*cmd, **kwargs) + return self.update(targetpath, clone=True, **kwargs) + + def init(self, url, targetpath, fullnames=True, **kwargs): + topurl = dirname(url) + trunk = basename(url) + tags = "releases" + # cloning svn braches as well should rather be optionalif reenabled.. + #cmd = ["svn", "init", topurl, "--trunk="+trunk, "--tags="+tags", targetpath] + + cmd = ["svn", "init", url, abspath(targetpath)] + self._execVcs(*cmd, **kwargs) + os.environ.update({"GIT_WORK_TREE" : abspath(targetpath), "GIT_DIR" : join(abspath(targetpath),".git")}) + + if fullnames: + usermap = UserTagParser() + # store configuration in local git config so that'll be reused later when ie. updating + gitconfig = {"svn-remote.authorlog.url" : usermap.url, + "svn-remote.authorlog.defaultmail": usermap.defaultmail} + self.configset(gitconfig) + + return True def info(self, path, **kwargs): cmd = ["svn", "info", path + '@' if '@' in path else path] @@ -112,25 +93,26 @@ class GIT(VCS): return [(x[0], x[8:]) for x in output.splitlines()] return None - def update(self, targetpath, **kwargs): + def update(self, targetpath, clone=False, **kwargs): os.environ.update({"GIT_WORK_TREE" : abspath(targetpath), "GIT_DIR" : join(abspath(targetpath),".git")}) - cmd = ["svn", "log", "--oneline", "--limit=1"] - retval, result = self._execVcs(*cmd) - if retval: - return retval + if not clone: + cmd = ["svn", "log", "--oneline", "--limit=1"] + retval, result = self._execVcs(*cmd) + if retval: + return retval - revision = result.split() + revision = result.split() - if revision[0][0] == 'r': - startrev = "-r"+str(int(revision[0][1:])+1) - else: - startrev = "BASE" + if revision[0][0] == 'r': + startrev = "-r"+str(int(revision[0][1:])+1) + else: + startrev = "BASE" - cmd = ["svn", "propget", "svn:entry:committed-rev"] - retval, lastrev = self._execVcs(*cmd) - if retval: - return retval + cmd = ["svn", "propget", "svn:entry:committed-rev"] + retval, lastrev = self._execVcs(*cmd) + if retval: + return retval #cmd = ["config", "--get-regexp", '^svn-remote.svn.(url|fetch)'] cmd = ["config", "--get", "svn-remote.svn.url"] @@ -145,7 +127,9 @@ class GIT(VCS): # To speed things up on huge repositories, we'll just grab all the # revision numbers for this specific directory and grab these only # in stead of having to go through each and every revision... - cmd = ["svn", "log", "-g", "--xml", "%s:%s" % (startrev,lastrev), url] + cmd = ["svn", "log", "-g", "--xml", url] + if not clone: + cmd.append("%s:%s" % (startrev,lastrev)) retval, result = execcmd(*cmd) if retval: return retval -- cgit v1.2.1