1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# Copyright (C) 2011 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import logging
import urlparse
import morphlib
class NoMorphs(Exception):
def __init__(self, repo, ref):
Exception.__init__(self,
'Cannot find any morpologies at %s:%s' %
(repo, ref))
class TooManyMorphs(Exception):
def __init__(self, repo, ref, morphs):
Exception.__init__(self,
'Too many morphologies at %s:%s: %s' %
(repo, ref, ', '.join(morphs)))
def export_sources(repo, ref, tar_filename):
'''Export the contents of a specific commit into a compressed tarball.'''
ex = morphlib.execute.Execute('.', msg=logging.debug)
ex.runv(['git', 'archive', '-o', tar_filename, '--remote', repo, ref])
def get_commit_id(repo, ref):
'''Return the full SHA-1 commit id for a repo+ref.'''
# FIXME: This assumes 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()
def get_morph_text(repo, ref, filename):
'''Return a morphology from a git repository.'''
# FIXME: This implementation assumes a local repo.
scheme, netlock, path, params, query, frag = urlparse.urlparse(repo)
assert scheme == 'file'
ex = morphlib.execute.Execute(path, msg=logging.debug)
return ex.runv(['git', 'cat-file', 'blob', '%s:%s' % (ref, filename)])
|