174 lines
4.0 KiB
Perl
Executable File
174 lines
4.0 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
# Copyright 2005, Ryan Anderson <ryan@michonline.com>
|
|
# Distribution permitted under the GPL v2, as distributed
|
|
# by the Free Software Foundation.
|
|
# Later versions of the GPL at the discretion of Linus Torvalds
|
|
#
|
|
# Scan two git object-trees, and hardlink any common objects between them.
|
|
|
|
use 5.008;
|
|
use strict;
|
|
use warnings;
|
|
use Getopt::Long;
|
|
|
|
sub get_canonical_form($);
|
|
sub do_scan_directory($$$);
|
|
sub compare_two_files($$);
|
|
sub usage();
|
|
sub link_two_files($$);
|
|
|
|
# stats
|
|
my $total_linked = 0;
|
|
my $total_already = 0;
|
|
my ($linked,$already);
|
|
|
|
my $fail_on_different_sizes = 0;
|
|
my $help = 0;
|
|
GetOptions("safe" => \$fail_on_different_sizes,
|
|
"help" => \$help);
|
|
|
|
usage() if $help;
|
|
|
|
my (@dirs) = @ARGV;
|
|
|
|
usage() if (!defined $dirs[0] || !defined $dirs[1]);
|
|
|
|
$_ = get_canonical_form($_) foreach (@dirs);
|
|
|
|
my $master_dir = pop @dirs;
|
|
|
|
opendir(D,$master_dir . "objects/")
|
|
or die "Failed to open $master_dir/objects/ : $!";
|
|
|
|
my @hashdirs = grep { ($_ eq 'pack') || /^[0-9a-f]{2}$/ } readdir(D);
|
|
|
|
foreach my $repo (@dirs) {
|
|
$linked = 0;
|
|
$already = 0;
|
|
printf("Searching '%s' and '%s' for common objects and hardlinking them...\n",
|
|
$master_dir,$repo);
|
|
|
|
foreach my $hashdir (@hashdirs) {
|
|
do_scan_directory($master_dir, $hashdir, $repo);
|
|
}
|
|
|
|
printf("Linked %d files, %d were already linked.\n",$linked, $already);
|
|
|