summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-10-17 20:56:15 +0100
committerLars Wirzenius <liw@liw.fi>2011-10-17 20:56:15 +0100
commita7d16bcc787fbce9e6ef431dead91a54bf8a50ca (patch)
tree998d0bf3053879973e936f63866f6757a2f70d91
parent98507401bd5e3d52b448c7890f952f1a5ff01567 (diff)
downloadmorph-a7d16bcc787fbce9e6ef431dead91a54bf8a50ca.tar.gz
Move get_git_commit_id into morphlib.git and rename.
-rw-r--r--morphlib/builder.py17
-rw-r--r--morphlib/git.py12
2 files changed, 17 insertions, 12 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py
index 6faa72b1..b697337b 100644
--- a/morphlib/builder.py
+++ b/morphlib/builder.py
@@ -85,7 +85,7 @@ class Builder(object):
self.ex.run(morph.install_commands, as_fakeroot=True)
self.prepare_binary_metadata(morph,
repo=repo,
- ref=self.get_git_commit_id(repo, ref))
+ ref=morphlib.git.get_commit_id(repo, ref))
self.create_chunk(morph, repo, ref)
self.tempdir.clear()
@@ -163,7 +163,10 @@ class Builder(object):
def get_cached_name(self, name, kind, repo, ref):
'''Return the cached name of a binary blob, if and when it exists.'''
- abs_ref = self.get_git_commit_id(repo, ref)
+ if repo and ref:
+ abs_ref = morphlib.git.get_commit_id(repo, ref)
+ else:
+ abs_ref = ''
dict_key = {
'name': name,
'kind': kind,
@@ -173,16 +176,6 @@ class Builder(object):
}
return self.cachedir.name(dict_key)
- def get_git_commit_id(self, repo, ref):
- '''Return the full SHA-1 commit id for a repo+ref.'''
- if repo and ref:
- path = self.get_repo_dir(repo)
- ex = morphlib.execute.Execute(path, self.msg)
- out = ex.runv(['git', 'rev-list', '-n1', ref])
- return out.strip()
- else:
- return ''
-
def get_morph_from_git(self, repo, ref):
'''Return a morphology from a git repository.'''
# FIXME: This implementation assume a local repo.
diff --git a/morphlib/git.py b/morphlib/git.py
index 47eb7ffe..f3403e2b 100644
--- a/morphlib/git.py
+++ b/morphlib/git.py
@@ -16,6 +16,7 @@
import gzip
import logging
+import urlparse
import morphlib
@@ -28,3 +29,14 @@ def export_sources(repo, ref, tar_filename):
f.write(tar)
f.close()
+
+def get_commit_id(repo, ref):
+ '''Return the full SHA-1 commit id for a repo+ref.'''
+ # FIXME: This assume repo is a file:/// URL.
+
+ scheme, netlock, path, params, query, frag = urlparse.urlparse(repo)
+ assert scheme == 'file'
+ ex = morphlib.execute.Execute(path, msg=logging.debug)
+ out = ex.runv(['git', 'rev-list', '-n1', ref])
+ return out.strip()
+