提交 1d4710d0 编写于 作者: M martin@catalyst.net.nz 提交者: Junio C Hamano

[PATCH] archimport - use GIT_DIR instead of hardcoded ".git"

Use GIT_DIR from the environment instead of a hardcoded '.git' string.
Signed-off-by: NMartin Langhoff <martin@catalyst.net.nz>
Signed-off-by: NJunio C Hamano <junkio@cox.net>
上级 241b5967
...@@ -24,7 +24,6 @@ =head1 TODO ...@@ -24,7 +24,6 @@ =head1 TODO
- create tag objects instead of ref tags - create tag objects instead of ref tags
- audit shell-escaping of filenames - audit shell-escaping of filenames
- better handling of temp directories - better handling of temp directories
- use GIT_DIR instead of hardcoded ".git"
- hide our private tags somewhere smarter - hide our private tags somewhere smarter
- find a way to make "cat *patches | patch" safe even when patchfiles are missing newlines - find a way to make "cat *patches | patch" safe even when patchfiles are missing newlines
...@@ -52,6 +51,9 @@ =head1 Devel tricks ...@@ -52,6 +51,9 @@ =head1 Devel tricks
$SIG{'PIPE'}="IGNORE"; $SIG{'PIPE'}="IGNORE";
$ENV{'TZ'}="UTC"; $ENV{'TZ'}="UTC";
my $git_dir = $ENV{"GIT_DIR"} || ".git";
$ENV{"GIT_DIR"} = $git_dir;
our($opt_h,$opt_v, $opt_T, our($opt_h,$opt_v, $opt_T,
$opt_C,$opt_t); $opt_C,$opt_t);
...@@ -179,7 +181,7 @@ END ...@@ -179,7 +181,7 @@ END
## and put an initial import ## and put an initial import
## or a full tag ## or a full tag
my $import = 0; my $import = 0;
unless (-d '.git') { # initial import unless (-d $git_dir) { # initial import
if ($psets[0]{type} eq 'i' || $psets[0]{type} eq 't') { if ($psets[0]{type} eq 'i' || $psets[0]{type} eq 't') {
print "Starting import from $psets[0]{id}\n"; print "Starting import from $psets[0]{id}\n";
`git-init-db`; `git-init-db`;
...@@ -190,11 +192,11 @@ END ...@@ -190,11 +192,11 @@ END
} }
} else { # progressing an import } else { # progressing an import
# load the rptags # load the rptags
opendir(DIR, ".git/archimport/tags") opendir(DIR, "$git_dir/archimport/tags")
|| die "can't opendir: $!"; || die "can't opendir: $!";
while (my $file = readdir(DIR)) { while (my $file = readdir(DIR)) {
# skip non-interesting-files # skip non-interesting-files
next unless -f ".git/archimport/tags/$file"; next unless -f "$git_dir/archimport/tags/$file";
next if $file =~ m/--base-0$/; # don't care for base-0 next if $file =~ m/--base-0$/; # don't care for base-0
my $sha = ptag($file); my $sha = ptag($file);
chomp $sha; chomp $sha;
...@@ -238,7 +240,7 @@ END ...@@ -238,7 +240,7 @@ END
} }
unless ($import) { # skip for import unless ($import) { # skip for import
if ( -e ".git/refs/heads/$ps->{branch}") { if ( -e "$git_dir/refs/heads/$ps->{branch}") {
# we know about this branch # we know about this branch
`git checkout $ps->{branch}`; `git checkout $ps->{branch}`;
} else { } else {
...@@ -291,7 +293,7 @@ END ...@@ -291,7 +293,7 @@ END
# imports don't give us good info # imports don't give us good info
# on added files. Shame on them # on added files. Shame on them
if ($ps->{type} eq 'i' || $ps->{type} eq 't') { if ($ps->{type} eq 'i' || $ps->{type} eq 't') {
`find . -type f -print0 | grep -zv '^./.git' | xargs -0 -l100 git-update-index --add`; `find . -type f -print0 | grep -zv '^./$git_dir' | xargs -0 -l100 git-update-index --add`;
`git-ls-files --deleted -z | xargs --no-run-if-empty -0 -l100 git-update-index --remove`; `git-ls-files --deleted -z | xargs --no-run-if-empty -0 -l100 git-update-index --remove`;
} }
...@@ -355,8 +357,8 @@ END ...@@ -355,8 +357,8 @@ END
# Who's your daddy? # Who's your daddy?
# #
my @par; my @par;
if ( -e ".git/refs/heads/$ps->{branch}") { if ( -e "$git_dir/refs/heads/$ps->{branch}") {
if (open HEAD, "<.git/refs/heads/$ps->{branch}") { if (open HEAD, "<$git_dir/refs/heads/$ps->{branch}") {
my $p = <HEAD>; my $p = <HEAD>;
close HEAD; close HEAD;
chomp $p; chomp $p;
...@@ -403,11 +405,11 @@ END ...@@ -403,11 +405,11 @@ END
# #
# Update the branch # Update the branch
# #
open HEAD, ">.git/refs/heads/$ps->{branch}"; open HEAD, ">$git_dir/refs/heads/$ps->{branch}";
print HEAD $commitid; print HEAD $commitid;
close HEAD; close HEAD;
unlink ('.git/HEAD'); unlink ("$git_dir/HEAD");
symlink("refs/heads/$ps->{branch}",".git/HEAD"); symlink("refs/heads/$ps->{branch}","$git_dir/HEAD");
# tag accordingly # tag accordingly
ptag($ps->{id}, $commitid); # private tag ptag($ps->{id}, $commitid); # private tag
...@@ -436,7 +438,7 @@ sub apply_import { ...@@ -436,7 +438,7 @@ sub apply_import {
`tla get -s --no-pristine -A $ps->{repo} $ps->{id} $tmp/import`; `tla get -s --no-pristine -A $ps->{repo} $ps->{id} $tmp/import`;
die "Cannot get import: $!" if $?; die "Cannot get import: $!" if $?;
`rsync -v --archive --delete --exclude '.git' --exclude '.arch-ids' --exclude '{arch}' $tmp/import/* ./`; `rsync -v --archive --delete --exclude '$git_dir' --exclude '.arch-ids' --exclude '{arch}' $tmp/import/* ./`;
die "Cannot rsync import:$!" if $?; die "Cannot rsync import:$!" if $?;
`rm -fr $tmp/import`; `rm -fr $tmp/import`;
...@@ -482,7 +484,7 @@ sub apply_cset { ...@@ -482,7 +484,7 @@ sub apply_cset {
} }
# bring in new files # bring in new files
`rsync --archive --exclude '.git' --exclude '.arch-ids' --exclude '{arch}' $tmp/changeset/new-files-archive/* ./`; `rsync --archive --exclude '$git_dir' --exclude '.arch-ids' --exclude '{arch}' $tmp/changeset/new-files-archive/* ./`;
# deleted files are hinted from the commitlog processing # deleted files are hinted from the commitlog processing
...@@ -577,7 +579,7 @@ sub tag { ...@@ -577,7 +579,7 @@ sub tag {
$tag = shell_quote($tag); $tag = shell_quote($tag);
if ($commit) { if ($commit) {
open(C,">.git/refs/tags/$tag") open(C,">$git_dir/refs/tags/$tag")
or die "Cannot create tag $tag: $!\n"; or die "Cannot create tag $tag: $!\n";
print C "$commit\n" print C "$commit\n"
or die "Cannot write tag $tag: $!\n"; or die "Cannot write tag $tag: $!\n";
...@@ -585,7 +587,7 @@ sub tag { ...@@ -585,7 +587,7 @@ sub tag {
or die "Cannot write tag $tag: $!\n"; or die "Cannot write tag $tag: $!\n";
print " * Created tag ' $tag' on '$commit'\n" if $opt_v; print " * Created tag ' $tag' on '$commit'\n" if $opt_v;
} else { # read } else { # read
open(C,"<.git/refs/tags/$tag") open(C,"<$git_dir/refs/tags/$tag")
or die "Cannot read tag $tag: $!\n"; or die "Cannot read tag $tag: $!\n";
$commit = <C>; $commit = <C>;
chomp $commit; chomp $commit;
...@@ -603,12 +605,12 @@ sub ptag { ...@@ -603,12 +605,12 @@ sub ptag {
$tag =~ s|/|--|g; $tag =~ s|/|--|g;
$tag = shell_quote($tag); $tag = shell_quote($tag);
unless (-d '.git/archimport/tags') { unless (-d "$git_dir/archimport/tags") {
mkpath('.git/archimport/tags'); mkpath("$git_dir/archimport/tags");
} }
if ($commit) { # write if ($commit) { # write
open(C,">.git/archimport/tags/$tag") open(C,">$git_dir/archimport/tags/$tag")
or die "Cannot create tag $tag: $!\n"; or die "Cannot create tag $tag: $!\n";
print C "$commit\n" print C "$commit\n"
or die "Cannot write tag $tag: $!\n"; or die "Cannot write tag $tag: $!\n";
...@@ -618,10 +620,10 @@ sub ptag { ...@@ -618,10 +620,10 @@ sub ptag {
unless $tag =~ m/--base-0$/; unless $tag =~ m/--base-0$/;
} else { # read } else { # read
# if the tag isn't there, return 0 # if the tag isn't there, return 0
unless ( -s ".git/archimport/tags/$tag") { unless ( -s "$git_dir/archimport/tags/$tag") {
return 0; return 0;
} }
open(C,"<.git/archimport/tags/$tag") open(C,"<$git_dir/archimport/tags/$tag")
or die "Cannot read tag $tag: $!\n"; or die "Cannot read tag $tag: $!\n";
$commit = <C>; $commit = <C>;
chomp $commit; chomp $commit;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册