Skip to content

Commit

Permalink
Improve compression format detection
Browse files Browse the repository at this point in the history
by checking if a version is already on the pristine-tar branch and use
it's compression type if found.

LP: #615212
  • Loading branch information
agx committed Sep 14, 2010
1 parent af97781 commit 70c5b22
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 12 additions & 0 deletions gbp/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ def show(self, id):
for line in commit:
yield line

def grep_log(self, regex, where=None):
args = ['--pretty=format:%H']
args.append("--grep=%s" % regex)
if where:
args.append(where)
args.append('--')

commits, ret = self.__git_getoutput('log', args)
if ret:
raise GitRepositoryError, "Error grepping log for %s" % regex
return [ commit.strip() for commit in commits[::-1] ]

def get_subject(self, commit):
"""Gets the subject of a commit"""
self.__check_path()
Expand Down
12 changes: 9 additions & 3 deletions git-buildpackage
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def extract_orig(orig_tarball, dest_dir):
os.rmdir(tar_topdir)


def guess_comp_type(repo, comp_type):
def guess_comp_type(repo, comp_type, srcpkg, upstream_version):
"""Guess compression type"""

if comp_type != 'auto':
Expand All @@ -188,7 +188,13 @@ def guess_comp_type(repo, comp_type):
if not repo.has_branch(PristineTar.branch):
comp_type = 'gzip'
else:
tarball = repo.get_subject(PristineTar.branch)
regex = 'pristine-tar .* %s_%s\.orig.tar\.' % (srcpkg, upstream_version)
commits = repo.grep_log(regex, PristineTar.branch)
if commits:
commit = commits[0]
else:
commit = PristineTar.branch
tarball = repo.get_subject(commit)
comp_type = du.get_compression(tarball)
if not comp_type:
comp_type = 'gzip'
Expand Down Expand Up @@ -341,9 +347,9 @@ def main(argv):
else:
tarball_dir = output_dir

options.comp_type = guess_comp_type (repo, options.comp_type)
# Get/build the orig.tar.gz if necessary:
if not du.is_native(cp):
options.comp_type = guess_comp_type(repo, options.comp_type, cp['Source'], major)
orig_file = du.orig_file(cp, options.comp_type)

# look in tarball_dir first, if found force a symlink to it
Expand Down

0 comments on commit 70c5b22

Please sign in to comment.