relink: really remove the command

The files in contrib/examples are meant to illustrate "you could combine plumbing commands to implement something like these"; this is an opposite and is an example of what not to do, e.g. accessing the object store directly bypassing Git. Remove it. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 25, 2017 at 14:43 UTC e0ae5b67a804463277ab7398f8d7557133e2c3db
2 files changed -203
contrib/examples/git-relink.perl deleted
-173
@@ -1,173 +0,0 @@
1 -#!/usr/bin/perl
2 -# Copyright 2005, Ryan Anderson <ryan@michonline.com>
3 -# Distribution permitted under the GPL v2, as distributed
4 -# by the Free Software Foundation.
5 -# Later versions of the GPL at the discretion of Linus Torvalds
6 -#
7 -# Scan two git object-trees, and hardlink any common objects between them.
8 -
9 -use 5.008;
10 -use strict;
11 -use warnings;
12 -use Getopt::Long;
13 -
14 -sub get_canonical_form($);
15 -sub do_scan_directory($$$);
16 -sub compare_two_files($$);
17 -sub usage();
18 -sub link_two_files($$);
19 -
20 -# stats
21 -my $total_linked = 0;
22 -my $total_already = 0;
23 -my ($linked,$already);
24 -
25 -my $fail_on_different_sizes = 0;
26 -my $help = 0;
27 -GetOptions("safe" => \$fail_on_different_sizes,
28 - "help" => \$help);
29 -
30 -usage() if $help;
31 -
32 -my (@dirs) = @ARGV;
33 -
34 -usage() if (!defined $dirs[0] || !defined $dirs[1]);
35 -
36 -$_ = get_canonical_form($_) foreach (@dirs);
37 -
38 -my $master_dir = pop @dirs;
39 -
40 -opendir(D,$master_dir . "objects/")
41 - or die "Failed to open $master_dir/objects/ : $!";
42 -
43 -my @hashdirs = grep { ($_ eq 'pack') || /^[0-9a-f]{2}$/ } readdir(D);
44 -
45 -foreach my $repo (@dirs) {
46 - $linked = 0;
47 - $already = 0;
48 - printf("Searching '%s' and '%s' for common objects and hardlinking them...\n",
49 - $master_dir,$repo);
50 -
51 - foreach my $hashdir (@hashdirs) {
52 - do_scan_directory($master_dir, $hashdir, $repo);
53 - }
54 -
55 - printf("Linked %d files, %d were already linked.\n",$linked, $already);
56 -
57 - $total_linked += $linked;
58 - $total_already += $already;
59 -}
60 -
61 -printf("Totals: Linked %d files, %d were already linked.\n",
62 - $total_linked, $total_already);
63 -
64 -
65 -sub do_scan_directory($$$) {
66 - my ($srcdir, $subdir, $dstdir) = @_;
67 -
68 - my $sfulldir = sprintf("%sobjects/%s/",$srcdir,$subdir);
69 - my $dfulldir = sprintf("%sobjects/%s/",$dstdir,$subdir);
70 -
71 - opendir(S,$sfulldir)
72 - or die "Failed to opendir $sfulldir: $!";
73 -
74 - foreach my $file (grep(!/\.{1,2}$/, readdir(S))) {
75 - my $sfilename = $sfulldir . $file;
76 - my $dfilename = $dfulldir . $file;
77 -
78 - compare_two_files($sfilename,$dfilename);
79 -
80 - }
81 - closedir(S);
82 -}
83 -
84 -sub compare_two_files($$) {
85 - my ($sfilename, $dfilename) = @_;
86 -
87 - # Perl's stat returns relevant information as follows:
88 - # 0 = dev number
89 - # 1 = inode number
90 - # 7 = size
91 - my @sstatinfo = stat($sfilename);
92 - my @dstatinfo = stat($dfilename);
93 -
94 - if (@sstatinfo == 0 && @dstatinfo == 0) {
95 - die sprintf("Stat of both %s and %s failed: %s\n",$sfilename, $dfilename, $!);
96 -
97 - } elsif (@dstatinfo == 0) {
98 - return;
99 - }
100 -
101 - if ( ($sstatinfo[0] == $dstatinfo[0]) &&
102 - ($sstatinfo[1] != $dstatinfo[1])) {
103 - if ($sstatinfo[7] == $dstatinfo[7]) {
104 - link_two_files($sfilename, $dfilename);
105 -
106 - } else {
107 - my $err = sprintf("ERROR: File sizes are not the same, cannot relink %s to %s.\n",
108 - $sfilename, $dfilename);
109 - if ($fail_on_different_sizes) {
110 - die $err;
111 - } else {
112 - warn $err;
113 - }
114 - }
115 -
116 - } elsif ( ($sstatinfo[0] == $dstatinfo[0]) &&
117 - ($sstatinfo[1] == $dstatinfo[1])) {
118 - $already++;
119 - }
120 -}
121 -
122 -sub get_canonical_form($) {
123 - my $dir = shift;
124 - my $original = $dir;
125 -
126 - die "$dir is not a directory." unless -d $dir;
127 -
128 - $dir .= "/" unless $dir =~ m#/$#;
129 - $dir .= ".git/" unless $dir =~ m#\.git/$#;
130 -
131 - die "$original does not have a .git/ subdirectory.\n" unless -d $dir;
132 -
133 - return $dir;
134 -}
135 -
136 -sub link_two_files($$) {
137 - my ($sfilename, $dfilename) = @_;
138 - my $tmpdname = sprintf("%s.old",$dfilename);
139 - rename($dfilename,$tmpdname)
140 - or die sprintf("Failure renaming %s to %s: %s",
141 - $dfilename, $tmpdname, $!);
142 -
143 - if (! link($sfilename,$dfilename)) {
144 - my $failtxt = "";
145 - unless (rename($tmpdname,$dfilename)) {
146 - $failtxt = sprintf(
147 - "Git Repository containing %s is probably corrupted, " .
148 - "please copy '%s' to '%s' to fix.\n",
149 - $tmpdname, $dfilename);
150 - }
151 -
152 - die sprintf("Failed to link %s to %s: %s\n%s" .
153 - $sfilename, $dfilename,
154 - $!, $dfilename, $failtxt);
155 - }
156 -
157 - unlink($tmpdname)
158 - or die sprintf("Unlink of %s failed: %s\n",
159 - $dfilename, $!);
160 -
161 - $linked++;
162 -}
163 -
164 -
165 -sub usage() {
166 - print("usage: git relink [--safe] <dir>... <master_dir> \n");
167 - print("All directories should contain a .git/objects/ subdirectory.\n");
168 - print("Options\n");
169 - print("\t--safe\t" .
170 - "Stops if two objects with the same hash exist but " .
171 - "have different sizes. Default is to warn and continue.\n");
172 - exit(1);
173 -}
contrib/examples/git-relink.txt deleted
-30
@@ -1,30 +0,0 @@
1 -git-relink(1)
2 -=============
3 -
4 -NAME
5 -----
6 -git-relink - Hardlink common objects in local repositories
7 -
8 -SYNOPSIS
9 ---------
10 -[verse]
11 -'git relink' [--safe] <dir>... <master_dir>
12 -
13 -DESCRIPTION
14 ------------
15 -This will scan 1 or more object repositories and look for objects in common
16 -with a master repository. Objects not already hardlinked to the master
17 -repository will be replaced with a hardlink to the master repository.
18 -
19 -OPTIONS
20 --------
21 ---safe::
22 - Stops if two objects with the same hash exist but have different sizes.
23 - Default is to warn and continue.
24 -
25 -<dir>::
26 - Directories containing a .git/objects/ subdirectory.
27 -
28 -GIT
29 ----
30 -Part of the linkgit:git[1] suite