git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] preserve mtime of local clone

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 13, 2009, 03:06 UTC
Message-ID
<7vvdjn4k6s.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20090912090348.GB9654@localhost>
Clemens Buchacher <drizzd@aon.at> writes:
Show 18 quoted lines
> 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.
Thanks.

This new feature is not wanted by most of the callers of copy_file(), and it is not like they may want to conditionally pass 1 in preserve_times someday. I'd limit the damage like this replacement patch, instead.

Is it unreasonable to have a test for this one, by the way?
 builtin-clone.c |    2 +-
 cache.h         |    1 +
 copy.c          |   21 +++++++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index ad04808..bab2d84 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_with_time(dest->buf, src->buf, 0666))
 			die_errno("failed to copy file to '%s'", dest->buf);
 	}
 	closedir(dir);
diff --git a/cache.h b/cache.h
index 867918d..1668f28 100644
--- a/cache.h
+++ b/cache.h
@@ -923,6 +923,7 @@ extern const char *git_mailmap_file;
 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_with_time(const char *dst, const char *src, int mode);
 extern void write_or_die(int fd, const void *buf, size_t count);
 extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
 extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
diff --git a/copy.c b/copy.c
index e54d15a..a7f58fd 100644
--- a/copy.c
+++ b/copy.c
@@ -35,6 +35,19 @@ int copy_fd(int ifd, int ofd)
 	return 0;
 }
 
+static 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 fdi, fdo, status;
@@ -55,3 +68,11 @@ int copy_file(const char *dst, const char *src, int mode)
 
 	return status;
 }
+
+int copy_file_with_time(const char *dst, const char *src, int mode)
+{
+	int status = copy_file(dst, src, mode);
+	if (!status)
+		return copy_times(dst, src);
+	return status;
+}
Previous: Clemens BuchacherNext: Clemens Buchacher
Message 5 of 13 in “preserve mtime of local clone”
  1. preserve mtime of local cloneClemens Buchacher, Sep 9, 2009
  2. Junio C HamanoSep 12, 2009
  3. Clemens BuchacherSep 12, 2009
  4. preserve mtime of local cloneClemens Buchacher, Sep 12, 2009
  5. Junio C HamanoSep 13, 2009
  6. preserve mtime of local cloneClemens Buchacher, Sep 13, 2009
  7. git-gui: suggest gc only when counting at least 2 objectsClemens Buchacher, Sep 13, 2009
  8. Junio C HamanoSep 13, 2009
  9. Clemens BuchacherSep 13, 2009
  10. Jeff KingSep 13, 2009
  11. Clemens BuchacherSep 13, 2009
  12. git-gui: search 4 directories to improve statistic of gc hintClemens Buchacher, Sep 13, 2009
  13. Shawn O. PearceSep 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.