diff options
Diffstat (limited to 'MgaRepo/git.py')
-rw-r--r-- | MgaRepo/git.py | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/MgaRepo/git.py b/MgaRepo/git.py index 45c628d..b91dcb2 100644 --- a/MgaRepo/git.py +++ b/MgaRepo/git.py @@ -2,8 +2,10 @@ from MgaRepo import Error, config from MgaRepo.util import execcmd from MgaRepo.VCS import * from MgaRepo.svn import SVN +from MgaRepo.log import UserTagParser from os.path import basename, dirname, abspath, lexists, join from os import chdir, getcwd +from tempfile import mkstemp import sys import re import time @@ -23,7 +25,23 @@ class GIT(VCS): self.vcs_supports['clone'] = True self.env_defaults = {"GIT_SSH": self.vcs_wrapper} - def clone(self, url, targetpath, **kwargs): + def configget(self, key="", location="--local"): + cmd = ["config", location, "--get-regexp", key] + config = None + status, output = self._execVcs(*cmd, noerror=True) + if not status and output: + config = eval("{'" + output.replace("\n", "',\n'").replace(" ", "' : '") + "'}") + return config + + def configset(self, config, location="--local"): + cmd = ("config", location) + for pair in config.items(): + status, output = self._execVcs(*cmd + pair) + if status: + return False + return True + + def clone(self, url, targetpath, fullnames=True, **kwargs): if lexists(join(targetpath, SVN.vcs_dirname)): raise Error("Target path %s already contains svn checkout, aborting..." % targetpath) if url.split(':')[0].find("svn") < 0: @@ -44,15 +62,31 @@ class GIT(VCS): 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: - cmd = ["svn", "fetch", "--log-window-size=1000", "-r%d" % revisions.pop(0)] - self._execVcs(*cmd, **kwargs) + 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) @@ -114,15 +148,25 @@ class GIT(VCS): retval, result = execcmd(*cmd) if retval: return retval + xmllog = ElementTree.fromstring(result) logentries = xmllog.getiterator("logentry") revisions = [] for entry in logentries: revisions.append(int(entry.attrib["revision"])) revisions.sort() + + fetchcmd = ["svn", "fetch", "--log-window-size=1000"] + gitconfig = self.configget("svn-remote.authorlog") + if gitconfig: + usermap = UserTagParser(url=gitconfig.get("svn-remote.authorlog.url"),defaultmail=gitconfig.get("svn-remote.authorlog.defaultmail")) + usermapfile = usermap.get_user_map_file() + fetchcmd.extend(("--authors-file", usermapfile)) + while revisions: - cmd = ["svn", "fetch", "--log-window-size=1000", "-r%d" % revisions.pop(0)] - self._execVcs(*cmd, **kwargs) + self._execVcs(*fetchcmd + ["-r%d"%revisions.pop(0)], **kwargs) + if gitconfig: + usermap.cleanup() cmd = ["svn", "rebase", "--log-window-size=1000", "--local", "--fetch-all", "git-svn"] status, output = self._execVcs(*cmd, **kwargs) |