Merge branch 'pb/gitpm' into next

* pb/gitpm:
  annotate: Fix bug when parsing merges with differing real and logical parents.
  log-tree: show_log() should respect the setting of diffopt->line_termination
  handle https:// protocol in git-clone
This commit is contained in:
Junio C Hamano
2006-08-07 17:22:30 -07:00
3 changed files with 112 additions and 10 deletions

View File

@@ -107,7 +107,7 @@ init_claim( defined $starting_rev ? $head : 'dirty');
unless (defined $starting_rev) {
my %ident;
@ident{'author', 'author_email', 'author_date'} = $repo->ident('author');
my $diff = $repo->command_output_pipe('diff', 'HEAD', '--', $filename);
my $diff = $repo->command_output_pipe('diff', '-R', 'HEAD', '--', $filename);
_git_diff_parse($diff, [$head], "dirty", %ident);
$repo->command_close_pipe($diff);
}
@@ -146,7 +146,7 @@ sub init_claim {
sub handle_rev {
my $i = 0;
my $revseen = 0;
my %seen;
while (my $rev = shift @revqueue) {
next if $seen{$rev}++;
@@ -239,22 +239,115 @@ sub git_find_parent {
return $parent;
}
sub git_find_all_parents {
my ($rev) = @_;
my $parentline = $repo->command_oneline("rev-list","--remove-empty", "--parents","--max-count=1","$rev");
my ($origrev, @parents) = split m/\s+/, $parentline;
return @parents;
}
sub git_merge_base {
my ($rev1, $rev2) = @_;
my $base = $repo->command_oneline("merge-base", $rev1, $rev2);
return $base;
}
# Construct a set of pseudo parents that are in the same order,
# and the same quantity as the real parents,
# but whose SHA1s are as similar to the logical parents
# as possible.
sub get_pseudo_parents {
my ($all, $fake) = @_;
my @all = @$all;
my @fake = @$fake;
my @pseudo;
my %fake = map {$_ => 1} @fake;
my %seenfake;
my $fakeidx = 0;
foreach my $p (@all) {
if (exists $fake{$p}) {
if ($fake[$fakeidx] ne $p) {
die sprintf("parent mismatch: %s != %s\nall:%s\nfake:%s\n",
$fake[$fakeidx], $p,
join(", ", @all),
join(", ", @fake),
);
}
push @pseudo, $p;
$fakeidx++;
$seenfake{$p}++;
} else {
my $base = git_merge_base($fake[$fakeidx], $p);
if ($base ne $fake[$fakeidx]) {
die sprintf("Result of merge-base doesn't match fake: %s,%s != %s\n",
$fake[$fakeidx], $p, $base);
}
# The details of how we parse the diffs
# mean that we cannot have a duplicate
# revision in the list, so if we've already
# seen the revision we would normally add, just use
# the actual revision.
if ($seenfake{$base}) {
push @pseudo, $p;
} else {
push @pseudo, $base;
$seenfake{$base}++;
}
}
}
return @pseudo;
}
# Get a diff between the current revision and a parent.
# Record the commit information that results.
sub git_diff_parse {
my ($parents, $rev, %revinfo) = @_;
my @pseudo_parents;
my @command = ("diff-tree");
my $revision_spec;
if (scalar @$parents == 1) {
$revision_spec = join("..", $parents->[0], $rev);
@pseudo_parents = @$parents;
} else {
my @all_parents = git_find_all_parents($rev);
if (@all_parents != @$parents) {
@pseudo_parents = get_pseudo_parents(\@all_parents, $parents);
} else {
@pseudo_parents = @$parents;
}
$revision_spec = $rev;
push @command, "-c";
}
my @filenames = ( $revs{$rev}{'filename'} );
foreach my $parent (@$parents) {
push @filenames, $revs{$parent}{'filename'};
}
my $diff = $repo->command_output_pipe('diff-tree', '-M', '-p', '-c',
$rev, '--', @filenames )
or die "Failed to call git-diff for annotation: $!";
push @command, "-p", "-M", $revision_spec, "--", @filenames;
_git_diff_parse($diff, $parents, $rev, %revinfo);
my $diff = $repo->command_output_pipe(@command);
_git_diff_parse($diff, \@pseudo_parents, $rev, %revinfo);
$repo->command_close_pipe($diff);
}
@@ -275,6 +368,7 @@ sub _git_diff_parse {
$diff_header_regexp .= "@" x @$parents;
$diff_header_regexp .= ' -\d+,\d+' x @$parents;
$diff_header_regexp .= ' \+(\d+),\d+';
$diff_header_regexp .= " " . ("@" x @$parents);
my %claim_regexps;
my $allparentplus = '^' . '\\+' x @$parents . '(.*)$';
@@ -303,6 +397,7 @@ sub _git_diff_parse {
DIFF:
while(<$diff>) {
chomp;
#printf("%d:%s:\n", $gotheader, $_);
if (m/$diff_header_regexp/) {
$remstart = $1 - 1;
# (0-based arrays)
@@ -383,10 +478,17 @@ sub _git_diff_parse {
printf("parent %s is on line %d\n", $parent, $pi{$parent});
}
my @context;
for (my $i = -2; $i < 2; $i++) {
push @context, get_line($slines, $ri + $i);
}
my $context = join("\n", @context);
my $justline = substr($_, scalar @$parents);
die sprintf("Line %d, does not match:\n|%s|\n|%s|\n%s\n",
$ri,
substr($_,scalar @$parents),
get_line($slines,$ri), $rev);
$justline,
$context);
}
foreach my $parent (@$parents) {
$plines{$parent}[$pi{$parent}++] = $slines->[$ri];

View File

@@ -298,7 +298,7 @@ yes,yes)
fi
git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1
;;
http://*)
https://*|http://*)
if test -z "@@NO_CURL@@"
then
clone_dumb_http "$repo" "$D"

View File

@@ -59,7 +59,7 @@ void show_log(struct rev_info *opt, const char *sep)
fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
if (opt->parents)
show_parents(commit, abbrev_commit);
putchar('\n');
putchar(opt->diffopt.line_termination);
return;
}