threads / patch / 11789

patchgit-relink: avoid hard linking in objects/info directory

Subject: [PATCH] git-relink: avoid hard linking in objects/info directory

## tl;dr

5 messages between Jan 29, 2008 and Jan 30, 2008. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Brandon Casey· Jan 29, 2008, 22:41 UTC · lore

git-relink is intended to search for packs and loose objects in common between two repositories and to replace the one set with hard links to the other. Files other than packs and loose objects should not be touched, so add the "info" sub-directory to the pattern of directory excludes.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 git-relink.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to git-relink.perl +1 −1
diff --git a/git-relink.perl b/git-relink.perl
index f6b4f6a..d267404 100755
--- a/git-relink.perl
+++ b/git-relink.perl
@@ -40,7 +40,7 @@ my $master_dir = pop @dirs;
 opendir(D,$master_dir . "objects/")
 	or die "Failed to open $master_dir/objects/ : $!";
 
-my @hashdirs = grep !/^\.{1,2}$/, readdir(D);
+my @hashdirs = grep !/^(\.{1,2}|info)$/, readdir(D);
 
 foreach my $repo (@dirs) {
 	$linked = 0;
-- 
1.5.4.rc5.3.gb953
Rafael Garcia-Suarez· Jan 30, 2008, 07:34 UTC · re: Brandon Casey · lore

Re: [PATCH] git-relink: avoid hard linking in objects/info directory

On 29/01/2008, Brandon Casey <casey@nrlssc.navy.mil> wrote:
Show 21 quoted lines
> git-relink is intended to search for packs and loose objects in
> common between two repositories and to replace the one set with
> hard links to the other. Files other than packs and loose objects
> should not be touched, so add the "info" sub-directory to the
> pattern of directory excludes.
>
> Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
> ---
>  git-relink.perl |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/git-relink.perl b/git-relink.perl
> index f6b4f6a..d267404 100755
> --- a/git-relink.perl
> +++ b/git-relink.perl
> @@ -40,7 +40,7 @@ my $master_dir = pop @dirs;
>  opendir(D,$master_dir . "objects/")
>         or die "Failed to open $master_dir/objects/ : $!";
>
> -my @hashdirs = grep !/^\.{1,2}$/, readdir(D);
> +my @hashdirs = grep !/^(\.{1,2}|info)$/, readdir(D);

That looks a bit fragile. If the intent is to get a list of files in $master_dir, why not simply say:

my @hashdirs = grep -f, readdir(D);
That will appropriately skip ., .. and any other dirs.
Junio C Hamano· Jan 30, 2008, 08:01 UTC · re: Rafael Garcia-Suarez · lore

Re: [PATCH] git-relink: avoid hard linking in objects/info directory

"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com> writes:
Show 12 quoted lines
>>  opendir(D,$master_dir . "objects/")
>>         or die "Failed to open $master_dir/objects/ : $!";
>>
>> -my @hashdirs = grep !/^\.{1,2}$/, readdir(D);
>> +my @hashdirs = grep !/^(\.{1,2}|info)$/, readdir(D);
>
> That looks a bit fragile. If the intent is to get a list of files in
> $master_dir, why not simply say:
>
> my @hashdirs = grep -f, readdir(D);
>
> That will appropriately skip ., .. and any other dirs.

The statement is trying to find directories whose names match /^[0-9a-f]{2}$/ (two hexdigits) or /^pack$/.

But I do agree that listing things to skip is a fragile approach than listing things you know are safe to relink.

How about doing it this way instead?
 git-relink.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to git-relink.perl +1 −1
diff --git a/git-relink.perl b/git-relink.perl
index f6b4f6a..9101926 100755
--- a/git-relink.perl
+++ b/git-relink.perl
@@ -40,7 +40,7 @@ my $master_dir = pop @dirs;
 opendir(D,$master_dir . "objects/")
 	or die "Failed to open $master_dir/objects/ : $!";
 
-my @hashdirs = grep !/^\.{1,2}$/, readdir(D);
+my @hashdirs = grep { ($_ eq 'pack') || /^[0-9a-f]{2}$/ } readdir(D);
 
 foreach my $repo (@dirs) {
 	$linked = 0;
Rafael Garcia-Suarez· Jan 30, 2008, 08:08 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-relink: avoid hard linking in objects/info directory

On 30/01/2008, Junio C Hamano <gitster@pobox.com> wrote:
> The statement is trying to find directories whose names match
> /^[0-9a-f]{2}$/ (two hexdigits) or /^pack$/.
Ah, I see better now.
Show 18 quoted lines
> But I do agree that listing things to skip is a fragile approach
> than listing things you know are safe to relink.
>
> How about doing it this way instead?
>
>  git-relink.perl |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/git-relink.perl b/git-relink.perl
> index f6b4f6a..9101926 100755
> --- a/git-relink.perl
> +++ b/git-relink.perl
> @@ -40,7 +40,7 @@ my $master_dir = pop @dirs;
>  opendir(D,$master_dir . "objects/")
>         or die "Failed to open $master_dir/objects/ : $!";
>
> -my @hashdirs = grep !/^\.{1,2}$/, readdir(D);
> +my @hashdirs = grep { ($_ eq 'pack') || /^[0-9a-f]{2}$/ } readdir(D);
Fine, except that one can factorize one step further:
    grep /^(pack|[0-9a-f]{2})$/, readdir(D);
Brandon Casey· Jan 30, 2008, 16:19 UTC · re: Rafael Garcia-Suarez · lore

Re: [PATCH] git-relink: avoid hard linking in objects/info directory

Rafael Garcia-Suarez wrote:
Show 27 quoted lines
> On 30/01/2008, Junio C Hamano <gitster@pobox.com> wrote:
>> The statement is trying to find directories whose names match
>> /^[0-9a-f]{2}$/ (two hexdigits) or /^pack$/.
> 
> Ah, I see better now.
> 
>> But I do agree that listing things to skip is a fragile approach
>> than listing things you know are safe to relink.
>>
>> How about doing it this way instead?
>>
>>  git-relink.perl |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/git-relink.perl b/git-relink.perl
>> index f6b4f6a..9101926 100755
>> --- a/git-relink.perl
>> +++ b/git-relink.perl
>> @@ -40,7 +40,7 @@ my $master_dir = pop @dirs;
>>  opendir(D,$master_dir . "objects/")
>>         or die "Failed to open $master_dir/objects/ : $!";
>>
>> -my @hashdirs = grep !/^\.{1,2}$/, readdir(D);
>> +my @hashdirs = grep { ($_ eq 'pack') || /^[0-9a-f]{2}$/ } readdir(D);
> 
> Fine, except that one can factorize one step further:
>     grep /^(pack|[0-9a-f]{2})$/, readdir(D);
Looks fine to me.
-brandon

← back to recent threads