git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Clemens Buchacher <drizzd@aon.at>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, msysgit@googlegroups.com,
	"Shawn O. Pearce" <spearce@spearce.org>
Subject: [PATCH] preserve mtime of local clone
Date: Sat, 12 Sep 2009 11:03:48 +0200	[thread overview]
Message-ID: <20090912090348.GB9654@localhost> (raw)
In-Reply-To: <20090912082624.GA9654@localhost>

A local clone without hardlinks copies all objects, including dangling
ones, to the new repository. Since the mtimes are renewed, those
dangling objects cannot be pruned by "git gc --prune", even if they
would have been old enough for pruning in the original repository.

Instead, preserve mtime during copy. "git gc --prune" will then work
in the clone just like it did in the original.

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---

On Sat, Sep 12, 2009 at 10:26:24AM +0200, Clemens Buchacher wrote:

> If it's a problem we can use utime() instead. I was just trying to use the
> file descriptors, since they were available. But the patch would be a little
> smaller if I didn't touch copy_fd().

Here we go.

 builtin-clone.c   |    2 +-
 builtin-init-db.c |    2 +-
 cache.h           |    4 +++-
 copy.c            |   18 +++++++++++++++++-
 rerere.c          |    2 +-
 5 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/builtin-clone.c b/builtin-clone.c
index ad04808..cb3c895 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -269,7 +269,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
 				die_errno("failed to create link '%s'", dest->buf);
 			option_no_hardlinks = 1;
 		}
-		if (copy_file(dest->buf, src->buf, 0666))
+		if (copy_file(dest->buf, src->buf, 0666, 1))
 			die_errno("failed to copy file to '%s'", dest->buf);
 	}
 	closedir(dir);
diff --git a/builtin-init-db.c b/builtin-init-db.c
index dd84cae..5deb81d 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -100,7 +100,7 @@ static void copy_templates_1(char *path, int baselen,
 				die_errno("cannot symlink '%s' '%s'", lnk, path);
 		}
 		else if (S_ISREG(st_template.st_mode)) {
-			if (copy_file(path, template, st_template.st_mode))
+			if (copy_file(path, template, st_template.st_mode, 0))
 				die_errno("cannot copy '%s' to '%s'", template,
 					  path);
 		}
diff --git a/cache.h b/cache.h
index 5fad24c..ac692d0 100644
--- a/cache.h
+++ b/cache.h
@@ -922,7 +922,9 @@ extern const char *git_mailmap_file;
 /* IO helper functions */
 extern void maybe_flush_or_die(FILE *, const char *);
 extern int copy_fd(int ifd, int ofd);
-extern int copy_file(const char *dst, const char *src, int mode);
+extern int copy_file(const char *dst, const char *src, int mode, int
+		preserve_times);
+extern int copy_times(const char *dst, const char *src);
 extern ssize_t read_in_full(int fd, void *buf, size_t count);
 extern ssize_t write_in_full(int fd, const void *buf, size_t count);
 extern void write_or_die(int fd, const void *buf, size_t count);
diff --git a/copy.c b/copy.c
index e54d15a..fb5e946 100644
--- a/copy.c
+++ b/copy.c
@@ -35,7 +35,21 @@ int copy_fd(int ifd, int ofd)
 	return 0;
 }
 
-int copy_file(const char *dst, const char *src, int mode)
+int copy_times(const char *dst, const char *src)
+{
+	struct stat st;
+	struct utimbuf times;
+	if (stat(src, &st) < 0)
+		return -1;
+	times.actime = st.st_atime;
+	times.modtime = st.st_mtime;
+	if (utime(dst, &times) < 0)
+		return -1;
+	return 0;
+}
+
+int copy_file(const char *dst, const char *src, int mode,
+		int preserve_times)
 {
 	int fdi, fdo, status;
 
@@ -52,6 +66,8 @@ int copy_file(const char *dst, const char *src, int mode)
 
 	if (!status && adjust_shared_perm(dst))
 		return -1;
+	if (!status && preserve_times && copy_times(dst, src))
+		return -1;
 
 	return status;
 }
diff --git a/rerere.c b/rerere.c
index 87360dc..d25f5f1 100644
--- a/rerere.c
+++ b/rerere.c
@@ -326,7 +326,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
 			continue;
 
 		fprintf(stderr, "Recorded resolution for '%s'.\n", path);
-		copy_file(rerere_path(name, "postimage"), path, 0666);
+		copy_file(rerere_path(name, "postimage"), path, 0666, 0);
 	mark_resolved:
 		rr->items[i].util = NULL;
 	}
-- 
1.6.5.rc0.164.g5f6b0

  reply	other threads:[~2009-09-12  9:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-09 19:51 [PATCH] preserve mtime of local clone Clemens Buchacher
2009-09-12  5:09 ` Junio C Hamano
2009-09-12  8:26   ` Clemens Buchacher
2009-09-12  9:03     ` Clemens Buchacher [this message]
2009-09-13  3:06       ` Junio C Hamano
2009-09-13 10:49         ` [PATCH v3] " Clemens Buchacher
2009-09-13 16:06 ` [PATCH] git-gui: suggest gc only when counting at least 2 objects Clemens Buchacher
2009-09-13 17:58   ` Junio C Hamano
2009-09-13 18:41     ` Clemens Buchacher
2009-09-13 20:44       ` Jeff King
2009-09-13 21:19         ` Clemens Buchacher
2009-09-13 22:20           ` [PATCH] git-gui: search 4 directories to improve statistic of gc hint Clemens Buchacher
2009-09-14  3:39           ` [PATCH] git-gui: suggest gc only when counting at least 2 objects Shawn O. Pearce

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=20090912090348.GB9654@localhost \
    --to=drizzd@aon.at \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=msysgit@googlegroups.com \
    --cc=spearce@spearce.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).