From: Joey Hess Date: Fri, 1 Feb 2008 18:35:08 +0000 (-0500) Subject: * Improve search for upstream branch. Default to looking for first X-Git-Tag: 0.6~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7db77c1c2627bef16e3c427f52a38fb07a44dd0d;p=tools%2Fpristine-tar.git * Improve search for upstream branch. Default to looking for first refs/heads/upstream, and failing that, anything with "upstream" in its name. This way if there is a local upstream branch and a remote one, it will use the local one. If there's only a remote one, it'll use that. Closes: #463566 --- diff --git a/debian/changelog b/debian/changelog index 886ea7f..ad75ce1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +pristine-tar (0.6) UNRELEASED; urgency=low + + * Improve search for upstream branch. Default to looking for first + refs/heads/upstream, and failing that, anything with "upstream" in its + name. This way if there is a local upstream branch and a remote one, it + will use the local one. If there's only a remote one, it'll use that. + Closes: #463566 + + -- Joey Hess Fri, 01 Feb 2008 13:33:04 -0500 + pristine-tar (0.5) unstable; urgency=low * Moved to git, and added a Vcs-Browser field. diff --git a/pristine-tar b/pristine-tar index b4e7f8b..4ee9141 100755 --- a/pristine-tar +++ b/pristine-tar @@ -57,7 +57,8 @@ on the information stored in version control. For B to work, you also need to store the precise contents of the tarball in version control. To specify in which tag (or branch or other treeish object) it's stored, use the B parameter. -This defaults to "upstream". The name of the tree it points to will be +This defaults to "refs/heads/upstream", or if there's no such branch, any +branch matching "upstream". The name of the tree it points to will be recorded for later use by B. The delta files are stored in a branch named "pristine-tar", with filenames @@ -430,20 +431,33 @@ sub export { my $vcs=vcstype(); if ($vcs eq "git") { - if ($upstream =~ /[A-Za-z0-9]{40}/) { + if (defined $upstream && $upstream =~ /[A-Za-z0-9]{40}/) { $id=$upstream; } else { - # Convert $upstream into an object id. - my @reflines=map { chomp; $_ } `git show-ref \Q$upstream\E`; - if (! @reflines) { - error "failed to find ref using: git show-ref $upstream" + my @totry; + if (! defined $upstream) { + # try a specific name first, if that's not + # present fall back to any upstream branch + @totry=("refs/heads/upstream", "upstream") } - if (@reflines > 1) { - error "more than one ref matches \"$upstream\":\n". - join("\n", @reflines); + else { + @totry=($upstream); + } + foreach my $branch (@totry) { + my @reflines=map { chomp; $_ } `git show-ref \Q$branch\E`; + if (@reflines > 1) { + error "more than one ref matches \"$branch\":\n". + join("\n", @reflines); + } + elsif (@reflines) { + ($id)=$reflines[0]=~/^([A-Za-z0-9]+)\s/; + last; + } + } + if (! defined $id) { + error "failed to find ref using: git show-ref @totry"; } - ($id)=$reflines[0]=~/^([A-Za-z0-9]+)\s/; } doit("git archive --format=tar \Q$id\E | (cd '$dest' && tar x)"); @@ -558,7 +572,7 @@ sub commitdelta { sub commit { my $tarball=shift; - my $upstream=(@_ ? shift : "upstream"); + my $upstream=shift; my $tempdir=tempdir(); my ($sourcedir, $id)=export($upstream);