Beispiel #1
0
 def commits(self, num=None, reverse=False):
     # Deleted refs have no commits.
     if self.deleted():
         return
     # Only report commits that aren't reachable from any other branch
     refs = []
     args = ["for-each-ref", "--format=%(refname)"]
     for r in run.git(*args)[1].splitlines():
         if r.strip() == self.name:
             continue
         if r.strip().startswith("refs/heads/"):
             refs.append("^%s" % r.strip())
     args = ["rev-list"]
     if num is not None:
         args += ["-n", str(num)]
     if reverse:
         args.append("--reverse")
     if self.created():
         args += refs
     if self.created():
         args.append(self.newsha)
     else:
         args.append("%s..%s" % (self.oldsha, self.newsha))
     for line in run.git(*args)[1].splitlines():
         sha = line.strip()
         yield Commit(self, sha)
Beispiel #2
0
def _git_config(key, default=NO_DEFAULT):
    cmd = ["config", key]
    try:
        return run.git(*cmd)[1].strip()
    except sp.CalledProcessError:
        if default == NO_DEFAULT:
            raise
        return default
Beispiel #3
0
    def __init__(self, ref, sha):
        self.ref = ref
        self.sha = sha

        fmt = "--format=format:%s%%x00" % r'%x00'.join([s for _, s in FIELDS])
        args = ["show", "--stat=75", fmt, self.sha]
        parts = map(util.decode, run.git(*args, decode=False)[1].split("\x00"))

        self.stats = u"\n".join(filter(None, parts.pop(-1).splitlines()))
        for pos, (key, _) in enumerate(FIELDS):
            setattr(self, key, parts[pos])

        self.committed_unix = int(self.committed_unix)
        parts = self.committer_email.split(u"@")
        self.committer_uname = parts[0]
        if len(parts) > 1:
            self.committer_domain = parts[1]
        else:
            self.committer_domain = ""
Beispiel #4
0
 def diff(self, fname):
     args = ["show", "--format=format:", self.sha, "--", fname]
     return run.git(*args)[1].lstrip()
Beispiel #5
0
 def files(self):
     files = run.git("show", "--name-only", "--format=format:", self.sha)[1]
     return [l.strip() for l in files.splitlines() if l.strip()]
Beispiel #6
0
 def merge_base(self):
     if ("0" * 40) in (self.oldsha, self.newsha):
         return "0" * 40
     (_, sha, _) = run.git("merge-base", self.oldsha, self.newsha)
     return sha.strip()
Beispiel #7
0
def _repo_name():
    path = filter(None, os.environ["PATH_INFO"].split("/"))
    path = filter(lambda p: p != "git-receive-pack", path)
    if len(path) != 1:
        raise ValueError("Invalid PATH_INFO: %s" % os.environ["PATH_INFO"])
    path = path[0]
    if path.endswith('.git'):
        return util.decode(path[:-4])
    return util.decode(path)


if os.environ.get('GIT_ORIGIN_REPO'):
  os.chdir(os.environ.get('GIT_ORIGIN_REPO'))
_all_config = dict(c.split('=')
                   for c in run.git('config', '--list')[1].splitlines()
                   if c.strip())
if os.environ.get('GIT_WIKI_REPO'):
  os.chdir(os.environ.get('GIT_WIKI_REPO'))

def _git_config(key, default=NO_DEFAULT):
    if key not in _all_config:
        if default is NO_DEFAULT:
            # When debugging, this is a good default value to return.
            #return '0'
            raise KeyError(key)
        return default
    return _all_config[key]


repo_name = _repo_name()