aboutsummaryrefslogtreecommitdiff
path: root/git-import-dsc
diff options
context:
space:
mode:
authorGuido Guenther <agx@sigxcpu.org>2008-02-29 16:08:00 +0100
committerGuido Guenther <agx@sigxcpu.org>2008-02-29 16:08:00 +0100
commit71d209fa202b3828a1eb7e8518a127a7a0a08596 (patch)
tree704ca6d61854d0c9415a68b722e1b43375aef4ea /git-import-dsc
parent5632aafe16c6760aabd940eb0d3b26c852ed455a (diff)
make dsc import repeatable (Closes: #468120)
Diffstat (limited to 'git-import-dsc')
-rwxr-xr-xgit-import-dsc96
1 files changed, 62 insertions, 34 deletions
diff --git a/git-import-dsc b/git-import-dsc
index 222af646..b94879f5 100755
--- a/git-import-dsc
+++ b/git-import-dsc
@@ -24,8 +24,8 @@ import tempfile
import glob
import pipes
import gbp.command_wrappers as gbpc
-from gbp.deb_utils import debian_version_chars
-from gbp.git_utils import build_tag, GitRepository
+from gbp.deb_utils import debian_version_chars, unpack_orig
+from gbp.git_utils import build_tag, GitRepository, GitRepositoryError, replace_source_tree
from gbp.config import GbpOptionParser
from gbp.errors import GbpError
@@ -88,40 +88,25 @@ def parse_dsc(dscfile):
return dsc
-def import_initial(src, dirs, options, tagger, filters):
+def import_initial(src, dirs, options):
"""
import the intial version and (in the case of a non native package) create
the 'upstream' branch. Tag everything appropriately.
"""
try:
- unpackTGZ = gbpc.UnpackTarArchive(src.tgz, dirs['tmp'], filters=filters)
- unpackTGZ()
- except gbpc.CommandExecFailed:
- print >>sys.stderr, "Unpacking of %s failed" % src.tgz
- gbpc.RemoveTree(dirs['tmp'])()
- return False
-
- try:
- dirs['git'] = glob.glob('%s/*' % unpackTGZ.dir)[0]
os.chdir(dirs['git'])
gbpc.GitInitDB()()
gbpc.GitAdd()(['.'])
gbpc.GitCommitAll()(
- msg="Imported %s version %s" % (['upstream', 'Debian'][src.native],
+ msg="Imported %s version %s" % (['Upstream', 'Debian'][src.native],
src.upstream_version))
- format = [options.upstream_tag, options.debian_tag][src.native]
- tagger(build_tag(format, src.upstream_version),
- msg="Upstream version %s" % src.upstream_version)
-
if not src.native:
gbpc.GitBranch()(options.upstream_branch)
if options.pristine_tar:
gbpc.PristineTar().commit(os.path.join(dirs['top'], src.tgz),
options.upstream_branch)
-
except gbpc.CommandExecFailed:
print >>sys.stderr, "Creation of git repository failed"
- gbpc.RemoveTree(unpackTGZ.dir)()
return False
return True
@@ -142,9 +127,10 @@ def git_apply_patch(diff):
return True
-def apply_debian_patch(src, dirs, options, tagger):
+def apply_debian_patch(src, dirs, options):
"""apply the debian patch and tag appropriately"""
version = "%s-%s" % (src.upstream_version, src.debian_version)
+ gitTag = gbpc.GitTag(options.sign_tags, options.keyid)
try:
os.chdir(dirs['git'])
repo = GitRepository('.')
@@ -155,7 +141,7 @@ def apply_debian_patch(src, dirs, options, tagger):
gbpc.GitCommitAll()(msg="Imported Debian patch %s" % version)
else:
print "Nothing to commit, nothing imported."
- tagger(build_tag(options.debian_tag, version),
+ gitTag(build_tag(options.debian_tag, version),
msg="Debian release %s" % version)
except gbpc.CommandExecFailed:
print >>sys.stderr, "Failed to import Debian package"
@@ -170,12 +156,11 @@ def move_tree(src, dirs):
print >>sys.stderr, "Cannot move git repository '%s' to it's final location '%s': %s" % (dirs['git'],
os.path.abspath(src.pkg), err)
return False
- else:
- gbpc.RemoveTree(dirs['tmp'])()
return True
def create_debian_branch(debian_branch, dirs):
+ """create the debian branch if necessary"""
os.chdir(dirs['git'])
repo = GitRepository('.')
if repo.get_branch() != debian_branch:
@@ -228,22 +213,65 @@ def main(argv):
if not src:
raise GbpError
- dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='.'))
- if not import_initial(src, dirs, options, gitTag, options.filters):
- raise GbpError
+ try:
+ repo = GitRepository('.')
+ (clean, out) = repo.is_clean()
+ if not clean:
+ print >>sys.stderr, "Repository has uncommitted changes, commit these first: "
+ raise GbpError, out
+ dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
+ initial = False
+ except GitRepositoryError:
+ # The initial import is different:
+ print "No git repository found, creating one."
+ dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='.'))
+ initial = True
- os.chdir(dirs['top'])
- if not src.native:
- apply_debian_patch(src, dirs, options, gitTag)
- create_debian_branch(options.debian_branch, dirs)
- os.chdir(dirs['top'])
- if not move_tree(src, dirs):
- raise GbpError
+ unpack_dir = unpack_orig(src.tgz, dirs['tmp'], options.filters)
+
+ format = [(options.upstream_tag, "Upstream"), (options.debian_tag, "Debian")][src.native]
+ tag = build_tag(format[0], src.upstream_version)
+ msg = "%s version %s" % (format[1], src.upstream_version)
+
+ if initial:
+ dirs['git'] = glob.glob('%s/*' % unpack_dir)[0]
+ if not import_initial(src, dirs, options):
+ raise GbpError
+ gitTag(tag, msg=msg)
+ os.chdir(dirs['top'])
+ if not src.native:
+ apply_debian_patch(src, dirs, options)
+ create_debian_branch(options.debian_branch, dirs)
+ os.chdir(dirs['top'])
+ if not move_tree(src, dirs):
+ raise GbpError
+ else: # not the initial import
+ dirs['git'] = dirs['top']
+ unpack_dir = glob.glob('%s/*' % unpack_dir)[0]
+ if not repo.has_tag(tag):
+ print "tag %s not found, importing %s tarball" % (tag, format[1])
+ # FIXME: this is what import-orig does - merge
+ if not src.native:
+ gbpc.GitCheckoutBranch(options.upstream_branch)()
+ replace_source_tree(repo, unpack_dir, options.filters, verbose=True)
+ gbpc.GitCommitAll()(msg="Imported %s" % msg)
+ gitTag(tag, msg=msg)
+ if options.pristine_tar and not src.native:
+ gbpc.PristineTar().commit(src.tgz, options.upstream_branch)
+ if not src.native:
+ gbpc.GitCheckoutBranch(options.debian_branch)()
+ replace_source_tree(repo, unpack_dir, options.filters)
+ apply_debian_patch(src, dirs, options)
+ except gbpc.CommandExecFailed:
+ raise GbpError
except GbpError, err:
if len(err.__str__()):
print >>sys.stderr, err
- ret = 1
os.chdir(dirs['top'])
+ ret = 1
+
+ if dirs.has_key('tmp'):
+ gbpc.RemoveTree(dirs['tmp'])()
if not ret:
print 'Everything imported under %s' % src.pkg