Documentation: update tutorial's discussion of origin
[gitweb.git] / git-rerere.perl
index b2550bb2ef8ec04c34ab6c3207de3e88f6b63608..4f692091e73bf633cf986ba2c9bed38bc2c78538 100755 (executable)
@@ -154,7 +154,7 @@ sub find_conflict {
 sub merge {
        my ($name, $path) = @_;
        record_preimage($path, "$rr_dir/$name/thisimage");
-       unless (system('merge', map { "$rr_dir/$name/${_}image" }
+       unless (system('git', 'merge-file', map { "$rr_dir/$name/${_}image" }
                       qw(this pre post))) {
                my $in;
                open $in, "<$rr_dir/$name/thisimage" or
@@ -169,6 +169,28 @@ sub merge {
        return 0;
 }
 
+sub garbage_collect_rerere {
+       # We should allow specifying these from the command line and
+       # that is why the caller gives @ARGV to us, but I am lazy.
+
+       my $cutoff_noresolve = 15; # two weeks
+       my $cutoff_resolve = 60; # two months
+       my @to_remove;
+       while (<$rr_dir/*/preimage>) {
+               my ($dir) = /^(.*)\/preimage$/;
+               my $cutoff = ((-f "$dir/postimage")
+                             ? $cutoff_resolve
+                             : $cutoff_noresolve);
+               my $age = -M "$_";
+               if ($cutoff <= $age) {
+                       push @to_remove, $dir;
+               }
+       }
+       if (@to_remove) {
+               rmtree(\@to_remove);
+       }
+}
+
 -d "$rr_dir" || exit(0);
 
 read_rr();
@@ -198,6 +220,9 @@ sub merge {
                                "$rr_dir/$name/preimage", $path);
                }
        }
+       elsif ($arg eq 'gc') {
+               garbage_collect_rerere(@ARGV);
+       }
        else {
                die "$0 unknown command: $arg\n";
        }