[PATCH] archimport - use GIT_DIR instead of hardcoded ".git"
Use GIT_DIR from the environment instead of a hardcoded '.git' string. Signed-off-by: Martin Langhoff <martin@catalyst.net.nz> Signed-off-by: Junio C Hamano <junkio@cox.net>
martin@catalyst.net.nz committed
Sep 11, 2005 at 21:26 UTC
1d4710d06ccf6911b42a3a7b4a4bf148008f32a5
1 file changed
+22
-20
git-archimport.perl
+22
-20
@@ -24,7 +24,6 @@ See man (1) git-archimport for more details.
24
- create tag objects instead of ref tags
25
- audit shell-escaping of filenames
26
- better handling of temp directories
27
- - use GIT_DIR instead of hardcoded ".git"
27
- hide our private tags somewhere smarter
28
- find a way to make "cat *patches | patch" safe even when patchfiles are missing newlines
29
@@ -52,6 +51,9 @@ use IPC::Open2;
51
$SIG{'PIPE'}="IGNORE";
52
$ENV{'TZ'}="UTC";
53
54
+my $git_dir = $ENV{"GIT_DIR"} || ".git";
55
+$ENV{"GIT_DIR"} = $git_dir;
56
+
57
our($opt_h,$opt_v, $opt_T,
58
$opt_C,$opt_t);
59
@@ -179,7 +181,7 @@ foreach my $root (@arch_roots) {
181
## and put an initial import
182
## or a full tag
183
my $import = 0;
182
-unless (-d '.git') { # initial import
184
+unless (-d $git_dir) { # initial import
185
if ($psets[0]{type} eq 'i' || $psets[0]{type} eq 't') {
186
print "Starting import from $psets[0]{id}\n";
187
`git-init-db`;
@@ -190,11 +192,11 @@ unless (-d '.git') { # initial import
192
}
193
} else { # progressing an import
194
# load the rptags
193
- opendir(DIR, ".git/archimport/tags")
195
+ opendir(DIR, "$git_dir/archimport/tags")
196
|| die "can't opendir: $!";
197
while (my $file = readdir(DIR)) {
198
# skip non-interesting-files
197
- next unless -f ".git/archimport/tags/$file";
199
+ next unless -f "$git_dir/archimport/tags/$file";
200
next if $file =~ m/--base-0$/; # don't care for base-0
201
my $sha = ptag($file);
202
chomp $sha;
@@ -238,7 +240,7 @@ foreach my $ps (@psets) {
240
}
241
242
unless ($import) { # skip for import
241
- if ( -e ".git/refs/heads/$ps->{branch}") {
243
+ if ( -e "$git_dir/refs/heads/$ps->{branch}") {
244
# we know about this branch
245
`git checkout $ps->{branch}`;
246
} else {
@@ -291,7 +293,7 @@ foreach my $ps (@psets) {
293
# imports don't give us good info
294
# on added files. Shame on them
295
if ($ps->{type} eq 'i' || $ps->{type} eq 't') {
294
- `find . -type f -print0 | grep -zv '^./.git' | xargs -0 -l100 git-update-index --add`;
296
+ `find . -type f -print0 | grep -zv '^./$git_dir' | xargs -0 -l100 git-update-index --add`;
297
`git-ls-files --deleted -z | xargs --no-run-if-empty -0 -l100 git-update-index --remove`;
298
}
299
@@ -355,8 +357,8 @@ foreach my $ps (@psets) {
357
# Who's your daddy?
358
#
359
my @par;
358
- if ( -e ".git/refs/heads/$ps->{branch}") {
359
- if (open HEAD, "<.git/refs/heads/$ps->{branch}") {
360
+ if ( -e "$git_dir/refs/heads/$ps->{branch}") {
361
+ if (open HEAD, "<$git_dir/refs/heads/$ps->{branch}") {
362
my $p = <HEAD>;
363
close HEAD;
364
chomp $p;
@@ -403,11 +405,11 @@ foreach my $ps (@psets) {
405
#
406
# Update the branch
407
#
406
- open HEAD, ">.git/refs/heads/$ps->{branch}";
408
+ open HEAD, ">$git_dir/refs/heads/$ps->{branch}";
409
print HEAD $commitid;
410
close HEAD;
409
- unlink ('.git/HEAD');
410
- symlink("refs/heads/$ps->{branch}",".git/HEAD");
411
+ unlink ("$git_dir/HEAD");
412
+ symlink("refs/heads/$ps->{branch}","$git_dir/HEAD");
413
414
# tag accordingly
415
ptag($ps->{id}, $commitid); # private tag
@@ -436,7 +438,7 @@ sub apply_import {
438
439
`tla get -s --no-pristine -A $ps->{repo} $ps->{id} $tmp/import`;
440
die "Cannot get import: $!" if $?;
439
- `rsync -v --archive --delete --exclude '.git' --exclude '.arch-ids' --exclude '{arch}' $tmp/import/* ./`;
441
+ `rsync -v --archive --delete --exclude '$git_dir' --exclude '.arch-ids' --exclude '{arch}' $tmp/import/* ./`;
442
die "Cannot rsync import:$!" if $?;
443
444
`rm -fr $tmp/import`;
@@ -482,7 +484,7 @@ sub apply_cset {
484
}
485
486
# bring in new files
485
- `rsync --archive --exclude '.git' --exclude '.arch-ids' --exclude '{arch}' $tmp/changeset/new-files-archive/* ./`;
487
+ `rsync --archive --exclude '$git_dir' --exclude '.arch-ids' --exclude '{arch}' $tmp/changeset/new-files-archive/* ./`;
488
489
# deleted files are hinted from the commitlog processing
490
@@ -577,7 +579,7 @@ sub tag {
579
$tag = shell_quote($tag);
580
581
if ($commit) {
580
- open(C,">.git/refs/tags/$tag")
582
+ open(C,">$git_dir/refs/tags/$tag")
583
or die "Cannot create tag $tag: $!\n";
584
print C "$commit\n"
585
or die "Cannot write tag $tag: $!\n";
@@ -585,7 +587,7 @@ sub tag {
587
or die "Cannot write tag $tag: $!\n";
588
print " * Created tag ' $tag' on '$commit'\n" if $opt_v;
589
} else { # read
588
- open(C,"<.git/refs/tags/$tag")
590
+ open(C,"<$git_dir/refs/tags/$tag")
591
or die "Cannot read tag $tag: $!\n";
592
$commit = <C>;
593
chomp $commit;
@@ -603,12 +605,12 @@ sub ptag {
605
$tag =~ s|/|--|g;
606
$tag = shell_quote($tag);
607
606
- unless (-d '.git/archimport/tags') {
607
- mkpath('.git/archimport/tags');
608
+ unless (-d "$git_dir/archimport/tags") {
609
+ mkpath("$git_dir/archimport/tags");
610
}
611
612
if ($commit) { # write
611
- open(C,">.git/archimport/tags/$tag")
613
+ open(C,">$git_dir/archimport/tags/$tag")
614
or die "Cannot create tag $tag: $!\n";
615
print C "$commit\n"
616
or die "Cannot write tag $tag: $!\n";
@@ -618,10 +620,10 @@ sub ptag {
620
unless $tag =~ m/--base-0$/;
621
} else { # read
622
# if the tag isn't there, return 0
621
- unless ( -s ".git/archimport/tags/$tag") {
623
+ unless ( -s "$git_dir/archimport/tags/$tag") {
624
return 0;
625
}
624
- open(C,"<.git/archimport/tags/$tag")
626
+ open(C,"<$git_dir/archimport/tags/$tag")
627
or die "Cannot read tag $tag: $!\n";
628
$commit = <C>;
629
chomp $commit;