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

5 messages from 2008-01-29 to 2008-01-30. Participants: Brandon Casey, Rafael Garcia-Suarez, Junio C Hamano.
Thread: https://gitlist.dev/t/11789

## Brandon Casey, 2008-01-29 22:41

Subject: [PATCH] git-relink: avoid hard linking in objects/info directory
Message-ID: <479FAB9A.9040009@nrlssc.navy.mil>
URL: https://gitlist.dev/e/479FAB9A.9040009%40nrlssc.navy.mil

```
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);
 
 foreach my $repo (@dirs) {
 	$linked = 0;
-- 
1.5.4.rc5.3.gb953

```

## Rafael Garcia-Suarez, 2008-01-30 07:34

Subject: Re: [PATCH] git-relink: avoid hard linking in objects/info directory
Message-ID: <b77c1dce0801292334p7c348744re6a7fdbb0f17d5b3@mail.gmail.com>
URL: https://gitlist.dev/e/b77c1dce0801292334p7c348744re6a7fdbb0f17d5b3%40mail.gmail.com
In-Reply-To: <479FAB9A.9040009@nrlssc.navy.mil>

```
On 29/01/2008, Brandon Casey <casey@nrlssc.navy.mil> wrote:
> 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, 2008-01-30 08:01

Subject: Re: [PATCH] git-relink: avoid hard linking in objects/info directory
Message-ID: <7vd4rjivy5.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd4rjivy5.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <b77c1dce0801292334p7c348744re6a7fdbb0f17d5b3@mail.gmail.com>

```
"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com> writes:

>>  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(-)

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, 2008-01-30 08:08

Subject: Re: [PATCH] git-relink: avoid hard linking in objects/info directory
Message-ID: <b77c1dce0801300008r7c6c38f5i97ffd30d022d533b@mail.gmail.com>
URL: https://gitlist.dev/e/b77c1dce0801300008r7c6c38f5i97ffd30d022d533b%40mail.gmail.com
In-Reply-To: <7vd4rjivy5.fsf@gitster.siamese.dyndns.org>

```
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);

```

## Brandon Casey, 2008-01-30 16:19

Subject: Re: [PATCH] git-relink: avoid hard linking in objects/info directory
Message-ID: <47A0A38A.7050600@nrlssc.navy.mil>
URL: https://gitlist.dev/e/47A0A38A.7050600%40nrlssc.navy.mil
In-Reply-To: <b77c1dce0801300008r7c6c38f5i97ffd30d022d533b@mail.gmail.com>

```
Rafael Garcia-Suarez wrote:
> 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

```
