login
Header Space

 
 

Re: [PATCH] prune: --expire=time

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Matthias Lederhofer <matled@...>
Cc: <git@...>
Date: Sunday, January 21, 2007 - 2:55 am

Matthias Lederhofer <matled@gmx.net> writes:


I am considering to commit the attached instead.

The command "prune" is about expiring loose objects that are
unreachable, and the option introduces a grace period for the
expiration process.  Other places that we do use the word
'expire' to specify the time do mean the expiration timeout.

As long as you do not rewind/rebase too much, there is not much
you can gain from 'git-prune' ('git-repack -a -d' would give you
much more disk savings and performance gain).  I do not think it
makes sense to run uncontrolled 'git-prune' from automated cron
jobs.  Even if you rewind/rebase often, 1.5.0 will protect the
objects reflog entries refer to, so there will be even less to
be gained from 'git-prune'.  I am having a feeling that it might
even make sense not to run 'git-prune' from 'git-gc'.

While I sympathize with what Simon says to certain degree, I
tend to think the complication it needs to introduce is really
not worth it.  Perfect is the enemy of the good.

By the way.

While updating the documentation, I noticed that we lost the
'extra heads' support when git-prune was rewritten as a built-in
in commit ba84a797 (July 6th 2006).  The example (commented out
in the patch) is a valid way to safely prune a repository whose
objects are borrowed via the alternates mechanism by some other
repository, albeit not really scalable.

The way we might want to address this would be when 'clone -s'
makes a new repository that borrows from an existing repository,
we could make a symlink under .git/refs/borrowers/ in the
original repository that points at .git/refs directory of the
cloned repository -- you can do that by hand today and it would
be much nicer than having to specify the other repository when
running 'git prune' as the example suggests.

For this reason, I would say losing that 'extra heads' support
from git-prune, which happened half year ago, was Ok.

So far, we have been telling not to rewind refs in repositories
whose objects are borrowed by other repositories via the
alternates mechanism, and I think that advice is still a very
reasonable one to give, but we probably should make it more
prominent.  As long as we do that, we would not even need the
'refs/borrowers/*' symlinks.

-- >8 --
From: Matthias Lederhofer <matled@gmx.net>
[PATCH] prune: --grace=time

This option gives grace period to objects that are unreachable
from the refs from getting pruned.

The default value is 24 hours and may be changed using
gc.prunegrace.

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 Documentation/git-prune.txt |    9 ++++++++-
 builtin-prune.c             |   31 ++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt
index a11e303..fbd344d 100644
--- a/Documentation/git-prune.txt
+++ b/Documentation/git-prune.txt
@@ -8,7 +8,7 @@ git-prune - Prunes all unreachable objects from the object database
 
 SYNOPSIS
 --------
-'git-prune' [-n] [--] [<head>...]
+'git-prune' [-n] [--grace=<time>]
 
 DESCRIPTION
 -----------
@@ -28,6 +28,12 @@ OPTIONS
 	Do not remove anything; just report what it would
 	remove.
 
+--grace=<time>::
+	Do not prune loose objects that are younger than the
+	specified time.  This gives a grace period to newly
+	created objects from getting pruned.
+
+////////////////////////////////////////////
 \--::
 	Do not interpret any more arguments as options.
 
@@ -46,6 +52,7 @@ borrows from your repository via its
 ------------
 $ git prune $(cd ../another && $(git-rev-parse --all))
 ------------
+////////////////////////////////////////////
 
 Author
 ------
diff --git a/builtin-prune.c b/builtin-prune.c
index 6f0ba0d..7929af1 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -5,8 +5,9 @@
 #include "builtin.h"
 #include "reachable.h"
 
-static const char prune_usage[] = "git-prune [-n]";
+static const char prune_usage[] = "git-prune [-n] [--grace=time]";
 static int show_only;
+static int prune_grace_period;
 
 static int prune_object(char *path, const char *filename, const unsigned char *sha1)
 {
@@ -38,6 +39,7 @@ static int prune_dir(int i, char *path)
 		char name[100];
 		unsigned char sha1[20];
 		int len = strlen(de->d_name);
+		struct stat st;
 
 		switch (len) {
 		case 2:
@@ -60,6 +62,11 @@ static int prune_dir(int i, char *path)
 			if (lookup_object(sha1))
 				continue;
 
+			if (prune_grace_period > 0 &&
+			    !stat(mkpath("%s/%s", path, de->d_name), &st) &&
+			    st.st_mtime > prune_grace_period)
+				continue;
+
 			prune_object(path, de->d_name, sha1);
 			continue;
 		}
@@ -79,10 +86,25 @@ static void prune_object_dir(const char *path)
 	}
 }
 
+static int git_prune_config(const char *var, const char *value)
+{
+	if (!strcmp(var, "gc.prunegrace")) {
+		if (!strcmp(value, "off"))
+			prune_grace_period = 0;
+		else
+			prune_grace_period = approxidate(value);
+		return 0;
+	}
+	return git_default_config(var, value);
+}
+
 int cmd_prune(int argc, const char **argv, const char *prefix)
 {
 	int i;
 	struct rev_info revs;
+	prune_grace_period = time(NULL)-24*60*60;
+
+	git_config(git_prune_config);
 
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
@@ -90,6 +112,13 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 			show_only = 1;
 			continue;
 		}
+		if (!strncmp(arg, "--grace=", 8)) {
+			if (!strcmp(arg+8, "off"))
+				prune_grace_period = 0;
+			else
+				prune_grace_period = approxidate(arg+8);
+			continue;
+		}
 		usage(prune_usage);
 	}
 
-- 
1.5.0.rc1.g40ab


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] prune-packed: new option --min-age=N, Matthias Lederhofer, (Thu Jan 18, 1:18 pm)
Re: [PATCH] prune-packed: new option --min-age=N, Shawn O. Pearce, (Thu Jan 18, 1:24 pm)
Re: [PATCH] prune-packed: new option --min-age=N, Matthias Lederhofer, (Thu Jan 18, 1:42 pm)
Re: [PATCH] prune-packed: new option --min-age=N, Shawn O. Pearce, (Thu Jan 18, 1:51 pm)
[RFC] prune: --expire=seconds, Matthias Lederhofer, (Thu Jan 18, 6:29 pm)
Re: [RFC] prune: --expire=seconds, Junio C Hamano, (Thu Jan 18, 6:32 pm)
Re: [RFC] prune: --expire=seconds, Shawn O. Pearce, (Thu Jan 18, 11:44 pm)
[PATCH] prune: --expire=time, Matthias Lederhofer, (Fri Jan 19, 6:49 am)
Re: [PATCH] prune: --expire=time, Junio C Hamano, (Fri Jan 19, 3:18 pm)
Re: [PATCH] prune: --expire=time, Simon 'corecode' Schubert..., (Sat Jan 20, 8:06 am)
Re: [PATCH] prune: --expire=time, Matthias Lederhofer, (Sat Jan 20, 7:18 am)
Re: [PATCH] prune: --expire=time, Junio C Hamano, (Sun Jan 21, 2:55 am)
Re: [PATCH] prune: --expire=time, Matthias Lederhofer, (Sun Jan 21, 6:37 am)
Re: [PATCH] prune: --expire=time, Junio C Hamano, (Sun Jan 21, 7:17 am)
Re: [PATCH] prune: --expire=time, Jeff King, (Sun Jan 21, 6:01 pm)
Re: [PATCH] prune: --expire=time, Steven Grimm, (Sun Jan 21, 9:38 pm)
Re: [PATCH] prune: --expire=time, Junio C Hamano, (Sun Jan 21, 10:03 pm)
Re: [PATCH] prune: --expire=time, Jeff King, (Sun Jan 21, 9:52 pm)
Re: [PATCH] prune: --expire=time, Junio C Hamano, (Sun Jan 21, 10:06 pm)
Re: [PATCH] prune: --expire=time, Linus Torvalds, (Sun Jan 21, 10:23 pm)
Re: [PATCH] prune: --expire=time, Junio C Hamano, (Sun Jan 21, 10:40 pm)
[PATCH] v1.5.0.txt: update description of git-gc, Jeff King, (Sun Jan 21, 11:26 pm)
Re: [PATCH] prune: --expire=time, Linus Torvalds, (Sun Jan 21, 10:58 pm)
Re: [PATCH] prune: --expire=time, Junio C Hamano, (Mon Jan 22, 1:17 am)
Re: [PATCH] prune: --expire=time, Linus Torvalds, (Mon Jan 22, 2:26 am)
Re: [PATCH] prune: --expire=time, Junio C Hamano, (Mon Jan 22, 3:12 am)
Re: [PATCH] prune: --expire=time, Shawn O. Pearce, (Mon Jan 22, 2:57 am)
Re: [PATCH] prune: --expire=time, Shawn O. Pearce, (Sun Jan 21, 3:53 am)
Re: [PATCH] prune: --expire=time, Nicolas Pitre, (Fri Jan 19, 11:41 am)
speck-geostationary