All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adam Simpkins <simpkins@facebook.com>
To: <git@vger.kernel.org>, <gitster@pobox.com>
Subject: [PATCH] prune: honor --expire=never
Date: Fri, 26 Feb 2010 13:59:16 -0800	[thread overview]
Message-ID: <20100226215916.GF5116@facebook.com> (raw)

Previously, prune treated an expiration time of 0 to mean that no
expire argument was supplied, and everything should be pruned.  As a
result, "prune --expire=never" would prune all unreachable objects,
regardless of their timestamps.

prune can be called with --expire=never automatically by gc, when the
gc.pruneExpire configuration is set to "never".

Signed-off-by: Adam Simpkins <simpkins@facebook.com>
---
 builtin-prune.c  |    7 +++++--
 t/t5304-prune.sh |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/builtin-prune.c b/builtin-prune.c
index 4675f60..ce43271 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -7,6 +7,8 @@
 #include "parse-options.h"
 #include "dir.h"
 
+#define ALWAYS_EXPIRE ((unsigned int)-1)
+
 static const char * const prune_usage[] = {
 	"git prune [-n] [-v] [--expire <time>] [--] [<head>...]",
 	NULL
@@ -18,7 +20,7 @@ static unsigned long expire;
 static int prune_tmp_object(const char *path, const char *filename)
 {
 	const char *fullpath = mkpath("%s/%s", path, filename);
-	if (expire) {
+	if (expire != ALWAYS_EXPIRE) {
 		struct stat st;
 		if (lstat(fullpath, &st))
 			return error("Could not stat '%s'", fullpath);
@@ -34,7 +36,7 @@ static int prune_tmp_object(const char *path, const char *filename)
 static int prune_object(char *path, const char *filename, const unsigned char *sha1)
 {
 	const char *fullpath = mkpath("%s/%s", path, filename);
-	if (expire) {
+	if (expire != ALWAYS_EXPIRE) {
 		struct stat st;
 		if (lstat(fullpath, &st))
 			return error("Could not stat '%s'", fullpath);
@@ -139,6 +141,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 	};
 	char *s;
 
+	expire = ALWAYS_EXPIRE;
 	save_commit_buffer = 0;
 	read_replace_refs = 0;
 	init_revisions(&revs, prefix);
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index 3c6687a..e2ed13d 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -148,6 +148,38 @@ test_expect_success 'gc --prune=<date>' '
 
 '
 
+test_expect_success 'gc --prune=never' '
+
+	add_blob &&
+	git gc --prune=never &&
+	test -f $BLOB_FILE &&
+	git gc --prune=now &&
+	test ! -f $BLOB_FILE
+
+'
+
+test_expect_success 'gc respects gc.pruneExpire=never' '
+
+	git config gc.pruneExpire never &&
+	add_blob &&
+	git gc &&
+	test -f $BLOB_FILE &&
+	git config gc.pruneExpire now &&
+	git gc &&
+	test ! -f $BLOB_FILE
+
+'
+
+test_expect_success 'prune --expire=never' '
+
+	add_blob &&
+	git prune --expire=never &&
+	test -f $BLOB_FILE &&
+	git prune &&
+	test ! -f $BLOB_FILE
+
+'
+
 test_expect_success 'gc: prune old objects after local clone' '
 	add_blob &&
 	test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
-- 
1.6.3.3

             reply	other threads:[~2010-02-26 23:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-26 21:59 Adam Simpkins [this message]
2010-02-27  0:07 ` [PATCH] prune: honor --expire=never Junio C Hamano
2010-02-27  1:21   ` Adam Simpkins
2010-02-27  3:50     ` [PATCH 1/3] " Adam Simpkins
2010-02-27  3:50       ` [PATCH 2/3] reflog: honor gc.reflogexpire=never Adam Simpkins
2010-02-27  3:50         ` [PATCH 3/3] clean up parsing of expiration dates Adam Simpkins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100226215916.GF5116@facebook.com \
    --to=simpkins@facebook.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.