Re: More gitweb queries..
- From
- Thomas Glanzmann <sithglan@stud.uni-erlangen.de>
- Date
- May 29, 2005, 23:56 UTC
- Message-ID
- <20050529235630.GG12290@cip.informatik.uni-erlangen.de>
- In-Reply-To
- <20050529234606.GF12290@cip.informatik.uni-erlangen.de>
Hello, here is the actual version of my merge function. However I have a question left over: When I do an automatic merge or a threeway merge should I set the head for the next round to the remote one or just let it be the current one (this is the current behaviour) or maybe make it configurable? Note: At the moment the *local* head for the merge-base is only modified during the set of the first head *or* on a head forward condition. I have no clue. I am going to write the 'more on merging chapter' after I have figured this out. ;-)
sub merge {
my $message = undef; my $head = undef; my $last_tree = undef; my $fh; my @heads = ();
foreach my $r (@_) {
my $current_head = @{$r}[0];
my $current_url = @{$r}[1];print "current_head => $current_head\ncurrent_url => $current_url\n";
push(@heads, '-p', ${current_head}); if (! defined($last_tree)) {
$message = "=> ${current_url}\n";
$head = $current_head;
$last_tree = $current_head;
if (@_ == 1) {
head($head);
return;
}next; }
my $merge_base = gitcmdout('git-merge-base', $head, $current_head)
|| die ("no merge-base");
chomp($merge_base); print "head => $head\nremote => $current_head\nbase => $merge_base\n";
if ($merge_base eq $current_head) {
$message .= "<= ${current_url} (nothing to merge)\n";$#heads -= 2;
next; }
if ($merge_base eq $head) {
$message .= "<= ${current_url} (bringing head ahead)\n";
$head = ${current_head};
$last_tree = ${current_head};$#heads -= 4; push(@heads, '-p', $current_head);
next; }
gitcmd('git-read-tree', '-m', $merge_base, $last_tree, $current_head);
if (! defined($last_tree = write_tree())) {
system('git-merge-cache', '-o', 'git-merge-one-file-script', '-a');
if (! defined($last_tree = write_tree())) {
# FIXME: Make manual intervention possible
# --tg 23:11 05-05-29
die("Couldn't merge automatically: Call 'git resolve'");
}
$message .= "<= ${current_url} (threeway merge)\n"; } else {
$message .= "<= ${current_url} (automatic merge)\n";
}
} if (@heads == 1) {
head(@head[0]);
return;
}open($fh, "+>", undef); print $fh $message; seek($fh, 0, 0); $head = gitcmdinout($fh, 'git-commit-tree', $last_tree, @heads); chomp($head); close $fh;
head($head); return; }
Thomas