mirror of
https://github.com/git/git.git
synced 2024-11-15 13:43:45 +01:00
460d10262d
If fast-export did not complete successfully the error handling code
itself would error out.
This was broken in commit 23b093ee0
(Brandon Casey, Wed Jun 9 2010,
Remove python 2.5'isms). Revert that commit an introduce our own copy
of check_call in util.py instead.
Tested by changing 'if retcode' to 'if not retcode' temporarily.
Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
76 lines
1.8 KiB
Python
76 lines
1.8 KiB
Python
import os
|
|
import subprocess
|
|
|
|
from git_remote_helpers.util import check_call
|
|
|
|
|
|
def sanitize(rev, sep='\t'):
|
|
"""Converts a for-each-ref line to a name/value pair.
|
|
"""
|
|
|
|
splitrev = rev.split(sep)
|
|
branchval = splitrev[0]
|
|
branchname = splitrev[1].strip()
|
|
if branchname.startswith("refs/heads/"):
|
|
branchname = branchname[11:]
|
|
|
|
return branchname, branchval
|
|
|
|
def is_remote(url):
|
|
"""Checks whether the specified value is a remote url.
|
|
"""
|
|
|
|
prefixes = ["http", "file", "git"]
|
|
|
|
for prefix in prefixes:
|
|
if url.startswith(prefix):
|
|
return True
|
|
return False
|
|
|
|
class GitRepo(object):
|
|
"""Repo object representing a repo.
|
|
"""
|
|
|
|
def __init__(self, path):
|
|
"""Initializes a new repo at the given path.
|
|
"""
|
|
|
|
self.path = path
|
|
self.head = None
|
|
self.revmap = {}
|
|
self.local = not is_remote(self.path)
|
|
|
|
if(self.path.endswith('.git')):
|
|
self.gitpath = self.path
|
|
else:
|
|
self.gitpath = os.path.join(self.path, '.git')
|
|
|
|
if self.local and not os.path.exists(self.gitpath):
|
|
os.makedirs(self.gitpath)
|
|
|
|
def get_revs(self):
|
|
"""Fetches all revs from the remote.
|
|
"""
|
|
|
|
args = ["git", "ls-remote", self.gitpath]
|
|
path = ".cached_revs"
|
|
ofile = open(path, "w")
|
|
|
|
check_call(args, stdout=ofile)
|
|
output = open(path).readlines()
|
|
self.revmap = dict(sanitize(i) for i in output)
|
|
if "HEAD" in self.revmap:
|
|
del self.revmap["HEAD"]
|
|
self.revs = self.revmap.keys()
|
|
ofile.close()
|
|
|
|
def get_head(self):
|
|
"""Determines the head of a local repo.
|
|
"""
|
|
|
|
if not self.local:
|
|
return
|
|
|
|
path = os.path.join(self.gitpath, "HEAD")
|
|
head = open(path).readline()
|
|
self.head, _ = sanitize(head, ' ')
|