summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/builder.py5
-rw-r--r--morphlib/git.py30
-rw-r--r--morphlib/morphologyloader.py5
-rwxr-xr-xtests/missing-ref.script11
-rw-r--r--tests/missing-ref.stderr5
5 files changed, 34 insertions, 22 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py
index 88a46633..95374e65 100644
--- a/morphlib/builder.py
+++ b/morphlib/builder.py
@@ -243,7 +243,10 @@ class Chunk(BinaryBlob):
self.dump_memory_profile('before creating source and tarball '
'for chunk')
tarball = self.cache_prefix + '.src.tar'
- morphlib.git.export_sources(self.repo, self.ref, tarball)
+ #FIXME Ugh use treeish everwhere
+ path = urlparse.urlparse(self.repo).path
+ t = morphlib.git.Treeish (path, self.ref)
+ morphlib.git.export_sources(t, tarball)
self.dump_memory_profile('after exporting sources')
os.mkdir(self.builddir)
self.ex.runv(['tar', '-C', self.builddir, '-xf', tarball])
diff --git a/morphlib/git.py b/morphlib/git.py
index e8c9eb70..234c4ce3 100644
--- a/morphlib/git.py
+++ b/morphlib/git.py
@@ -19,6 +19,7 @@ import urlparse
import binascii
import morphlib
import os
+import cliapp
class NoMorphs(Exception):
@@ -36,7 +37,7 @@ class TooManyMorphs(Exception):
'Too many morphologies at %s:%s: %s' %
(repo, ref, ', '.join(morphs)))
-class InvalidTreeish(Exception):
+class InvalidTreeish(cliapp.AppException):
def __init__(self, repo, ref):
Exception.__init__(self,
@@ -60,20 +61,18 @@ class Treeish:
self.sha1 = refs[0]
self.ref = refs[1]
except morphlib.execute.CommandFailure:
- self._is_treeish(ref)
+ self._is_sha(ref)
+
+ def _is_sha(self, ref):
+ if len(ref)!=40:
+ raise InvalidTreeish(self.repo,ref)
- def _is_treeish(self, ref):
try:
- if len(ref)==40:
binascii.unhexlify(ref)
ex = morphlib.execute.Execute(self.repo, self.msg)
- try:
- refs = ex.runv(['git', 'rev-list', '--no-walk', ref])
- self.sha1=ref
- except morphlib.execute.CommandFailure:
- raise InvalidTreeish(self.repo,ref)
-
- except TypeError:
+ refs = ex.runv(['git', 'rev-list', '--no-walk', ref])
+ self.sha1=ref
+ except (TypeError, morphlib.execute.CommandFailure):
raise InvalidTreeish(self.repo,ref)
def export_sources(treeish, tar_filename):
@@ -107,3 +106,12 @@ def add_remote(gitdir, name, url):
ex = morphlib.execute.Execute(gitdir, msg=logging.debug)
return ex.runv(['git', 'remote', 'add', '-f', name, url])
+# FIXME: All usage of this must die and Treeishes should be used
+def get_commit_id(repo, ref):
+ '''Return the full SHA-1 commit id for a repo+ref.'''
+ 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()
+
diff --git a/morphlib/morphologyloader.py b/morphlib/morphologyloader.py
index a227214f..a1d972e0 100644
--- a/morphlib/morphologyloader.py
+++ b/morphlib/morphologyloader.py
@@ -21,6 +21,7 @@ import urlparse
import morphlib
+#FIXME should use Treeishes everywhere and get stuff from the SourceManager
class MorphologyLoader(object):
'''Load morphologies from git and parse them into Morphology objects.'''
@@ -45,7 +46,9 @@ class MorphologyLoader(object):
return morph
def _get_morph_text(self, repo, ref, filename): # pragma: no cover
- return morphlib.git.get_morph_text(repo, ref, filename)
+ path = urlparse.urlparse(repo).path
+ t = morphlib.git.Treeish(path, ref)
+ return morphlib.git.get_morph_text(t, filename)
def _get_morph_from_git(self, repo, ref, filename):
morph_text = self._get_morph_text(repo, ref, filename)
diff --git a/tests/missing-ref.script b/tests/missing-ref.script
index 0c4f29f7..f70715f1 100755
--- a/tests/missing-ref.script
+++ b/tests/missing-ref.script
@@ -2,7 +2,7 @@
#
# Test building with a bad reference.
#
-# Copyright (C) 2011 Codethink Limited
+# Copyright (C) 2011,2012 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,10 +17,11 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-set -e
-
+#tempdirs make script diffing cry
cache="$DATADIR/build-chunk-cache"
./morph --no-default-configs build chunk-repo non-existent-branch hello.morph \
--git-base-url="file://$DATADIR" \
- --cachedir="$cache" --keep-path --no-distcc
-
+ --cachedir="$cache" --keep-path --no-distcc 2> "$DATADIR/build-chunk-cache.stderr"
+err=$?
+cat "$DATADIR/build-chunk-cache.stderr" | sed "s%$DATADIR%%" 1>&2
+exit $?
diff --git a/tests/missing-ref.stderr b/tests/missing-ref.stderr
index 5cf767b3..cd72eec2 100644
--- a/tests/missing-ref.stderr
+++ b/tests/missing-ref.stderr
@@ -1,4 +1 @@
-ERROR: Command failed: git cat-file blob non-existent-branch:hello.morph
-Output from command:
-fatal: Not a valid object name non-existent-branch:hello.morph
-
+ERROR: non-existent-branch is an invalid reference for repo /chunk-repo