diff options
author | Paul Sherwood <paul.sherwood@codethink.co.uk> | 2014-04-29 20:37:28 +0000 |
---|---|---|
committer | Paul Sherwood <paul.sherwood@codethink.co.uk> | 2014-04-29 20:37:28 +0000 |
commit | e98c205a5c3fb893ffdda3f5e05d1967b4a79c1d (patch) | |
tree | 3ecbd4f05ab9601cefa7b322323039795db440a9 /git_remote_helpers/git/repo.py | |
parent | 43efcf42382e87de4aa423e5e1607958ad1717d0 (diff) | |
parent | 0bc85abb7aa9b24b093253018801a0fb43d01122 (diff) | |
download | git-baserock/ps/update-git.tar.gz |
Merge tag 'v1.9.2' into HEADbaserock/ps/update-git
Git 1.9.2
Diffstat (limited to 'git_remote_helpers/git/repo.py')
-rw-r--r-- | git_remote_helpers/git/repo.py | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/git_remote_helpers/git/repo.py b/git_remote_helpers/git/repo.py deleted file mode 100644 index acbf8d7785..0000000000 --- a/git_remote_helpers/git/repo.py +++ /dev/null @@ -1,76 +0,0 @@ -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, ' ') |