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

Subsystems: the rest

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:44:09

"Rafael Garcia-Suarez" [off-list ref] writes:
quoted
 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;

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

From: Rafael Garcia-Suarez <hidden>
Date: 2016-06-15 22:44:09

On 30/01/2008, Junio C Hamano [off-list ref] wrote:
The statement is trying to find directories whose names match
/^[0-9a-f]{2}$/ (two hexdigits) or /^pack$/.
Ah, I see better now.
quoted hunk
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);

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

From: Brandon Casey <hidden>
Date: 2016-06-15 22:44:09

Rafael Garcia-Suarez wrote:
On 30/01/2008, Junio C Hamano [off-list ref] wrote:
quoted
The statement is trying to find directories whose names match
/^[0-9a-f]{2}$/ (two hexdigits) or /^pack$/.
Ah, I see better now.
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help