Hi,
a call to git-cvsimport after a 'git-pack-refs --all' seems to mess up
the origin branch, because the first new change is committed with no
parent (git-cvsimport reports 'Parent ID (empty)').
It does not happen if I disable loose refs pruning with --no-prune. A
tiny test repo you can use to reproduce the problem is
mextli.tomaw.net/~exg/lzf.tar. Is it expected?
Thanks,
Emanuele Giaquinta
From: Jeff King <hidden> Date: 2016-06-15 22:43:54
On Tue, Nov 27, 2007 at 04:01:36PM +0100, Emanuele Giaquinta wrote:
a call to git-cvsimport after a 'git-pack-refs --all' seems to mess up
the origin branch, because the first new change is committed with no
parent (git-cvsimport reports 'Parent ID (empty)').
It does not happen if I disable loose refs pruning with --no-prune. A
tiny test repo you can use to reproduce the problem is
mextli.tomaw.net/~exg/lzf.tar. Is it expected?
Some of git-cvsimport is quite old, and it accesses the ref files
directly. It should be fairly easy to fix; I will post a patch in a few
minutes.
-Peff
From: Jeff King <hidden> Date: 2016-06-15 22:43:54
We weren't even testing basic things before, so let's at
least try importing and updating a trivial repository, which
will catch total breakage.
Signed-off-by: Jeff King <redacted>
---
t/t9600-cvsimport.sh | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 99 insertions(+), 0 deletions(-)
create mode 100755 t/t9600-cvsimport.sh
From: Jeff King <hidden> Date: 2016-06-15 22:43:54
On Wed, Nov 28, 2007 at 11:57:46AM -0500, Jeff King wrote:
Some of git-cvsimport is quite old, and it accesses the ref files
directly. It should be fairly easy to fix; I will post a patch in a few
minutes.
The patch series is:
1/3: Add basic cvsimport tests
We had no tests before, so this at least gives a sanity check. I
added a t9600 series, though perhaps the cvs-related tests
(cvsserver and exportcommit) should collapse to a single t9[0-9]*
series.
2/3: cvsimport: use show-ref to support packed refs
This fix is hopefully obvious, and the included test fails
without it (and this should probably fix Emanuele's problem).
3/3: cvsimport: miscellaneous packed-ref fixes
This fixes all of the packed-ref problem spots I could find.
However, I have no tests that show the problems or that verify
that the fixes are sane. So apply with caution.
Probably cvsimport would benefit greatly from a conversion to
Git.pm, but that is likely to involve a lot of rewriting, and I
have neither the time nor the inclination for that right now.
-Peff
From: Jeff King <hidden> Date: 2016-06-15 22:43:54
Previously, if refs were packed, git-cvsimport would assume
that particular refs did not exist. This could lead to, for
example, overwriting previous 'origin' commits that were
packed.
Signed-off-by: Jeff King <redacted>
---
git-cvsimport.perl | 24 +++++++++---------------
t/t9600-cvsimport.sh | 2 ++
2 files changed, 11 insertions(+), 15 deletions(-)
@@ -527,18 +527,12 @@ sub is_sha1 {return$s=~ /^[a-f0-9]{40}$/;}-subget_headref($$){-my$name=shift;-my$git_dir=shift;--my$f="$git_dir/$remote/$name";-if(open(my$fh,$f)){-chomp(my$r=<$fh>);-is_sha1($r)ordie"Cannot get head id for $name ($r): $!";-return$r;-}-die"unable to open $f: $!"unless$!==POSIX::ENOENT;-returnundef;+subget_headref($){+my$name=shift;+my$r=`git show-ref -s '$name'`;+returnundefunless$?==0;+chomp$r;+return$r;}-d$git_tree
@@ -698,7 +692,7 @@ my (@old,@new,@skipped,%ignorebranch);$ignorebranch{'#CVSPS_NO_BRANCH'}=1;subcommit{-if($brancheq$opt_o&&!$index{branch}&&!get_headref($branch,$git_dir)){+if($brancheq$opt_o&&!$index{branch}&&!get_headref($branch)){# looks like an initial commit# use the index primed by git-init$ENV{GIT_INDEX_FILE}="$git_dir/index";
@@ -722,7 +716,7 @@ sub commit {update_index(@old,@new);@old=@new=();my$tree=write_tree();-my$parent=get_headref($last_branch,$git_dir);+my$parent=get_headref($last_branch);print"Parent ID ".($parent?$parent:"(empty)")."\n"if$opt_v;my@commit_args;
@@ -733,7 +727,7 @@ sub commit {foreachmy$rx(@mergerx){nextunless$logmsg=~$rx&&$1;my$mparent=$1eq'HEAD'?$opt_o:$1;-if(my$sha1=get_headref($mparent,$git_dir)){+if(my$sha1=get_headref($mparent)){push@commit_args,'-p',$mparent;print"Merge parent branch: $mparent\n"if$opt_v;}
From: Jeff King <hidden> Date: 2016-06-15 22:43:54
These were found with a grep for '$git_dir'; they all
replace a direct access of "$git_dir/refs/..." with a call
to git-show-ref or git-update-ref.
Signed-off-by: Jeff King <redacted>
---
git-cvsimport.perl | 20 +++++++++-----------
1 files changed, 9 insertions(+), 11 deletions(-)
@@ -527,18 +527,12 @@ sub is_sha1 {return$s=~ /^[a-f0-9]{40}$/;}-subget_headref($$){-my$name=shift;-my$git_dir=shift;--my$f="$git_dir/$remote/$name";-if(open(my$fh,$f)){-chomp(my$r=<$fh>);-is_sha1($r)ordie"Cannot get head id for $name ($r): $!";-return$r;-}-die"unable to open $f: $!"unless$!==POSIX::ENOENT;-returnundef;+subget_headref($){+my$name=shift;+my$r=`git show-ref -s '$name'`;+returnundefunless$?==0;+chomp$r;+return$r;}
From: Jeff King <hidden> Date: 2016-06-15 22:43:54
On Wed, Nov 28, 2007 at 07:16:36PM +0000, Johannes Schindelin wrote:
quoted
-sub get_headref ($$) {
- my $name = shift;
- my $git_dir = shift;
-
- my $f = "$git_dir/$remote/$name";
- if (open(my $fh, $f)) {
- chomp(my $r = <$fh>);
- is_sha1($r) or die "Cannot get head id for $name ($r): $!";
- return $r;
- }
- die "unable to open $f: $!" unless $! == POSIX::ENOENT;
- return undef;
+sub get_headref ($) {
+ my $name = shift;
+ my $r = `git show-ref -s '$name'`;
+ return undef unless $? == 0;
+ chomp $r;
+ return $r;
}
Where has $remote gone?
Gah, thank you. Obviously I deleted it without looking when I removed
the now-unnecessary $git_dir. However, let me put a curse on whoever is
responsible for randomly using "$remote" as a global in this function,
when all of the other parameters (including the
obvious-candidate-for-a-global $git_dir) are passed in.
Since get_headref is useful in contexts where "$remote" is not always
prepended (see patch 3/3), I think the best solution is:
@@ -692,7 +692,8 @@ my (@old,@new,@skipped,%ignorebranch);$ignorebranch{'#CVSPS_NO_BRANCH'}=1;subcommit{-if($brancheq$opt_o&&!$index{branch}&&!get_headref($branch)){+if($brancheq$opt_o&&!$index{branch}&&+!get_headref("$remote/$branch")){# looks like an initial commit# use the index primed by git-init$ENV{GIT_INDEX_FILE}="$git_dir/index";
@@ -716,7 +717,7 @@ sub commit {update_index(@old,@new);@old=@new=();my$tree=write_tree();-my$parent=get_headref($last_branch);+my$parent=get_headref("$remote/$last_branch");print"Parent ID ".($parent?$parent:"(empty)")."\n"if$opt_v;my@commit_args;
@@ -727,7 +728,7 @@ sub commit {foreachmy$rx(@mergerx){nextunless$logmsg=~$rx&&$1;my$mparent=$1eq'HEAD'?$opt_o:$1;-if(my$sha1=get_headref($mparent)){+if(my$sha1=get_headref("$remote/$mparent")){push@commit_args,'-p',$mparent;print"Merge parent branch: $mparent\n"if$opt_v;}
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:43:54
Hi,
On Wed, 28 Nov 2007, Jeff King wrote:
Since get_headref is useful in contexts where "$remote" is not always
prepended (see patch 3/3), I think the best solution is:
[PATCH prefixing the argument to get_headref() with "$remote/"]
On Wed, Nov 28, 2007 at 01:55:04PM -0500, Jeff King wrote:
2/3: cvsimport: use show-ref to support packed refs
This fix is hopefully obvious, and the included test fails
without it (and this should probably fix Emanuele's problem).