@matheusbsbs / matheus-bagliano / commits / f7835a251c
Fork 0

preserve mtime of local clone

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clemens Buchacher committed Sep 12, 2009 at 11:03 UTC f7835a251c2c98df152792b15793b03e22bf078e
3 files changed +23 -1
builtin-clone.c
+1 -1
@@ -269,7 +269,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
269 die_errno("failed to create link '%s'", dest->buf);
270 option_no_hardlinks = 1;
271 }
272 - if (copy_file(dest->buf, src->buf, 0666))
272 + if (copy_file_with_time(dest->buf, src->buf, 0666))
273 die_errno("failed to copy file to '%s'", dest->buf);
274 }
275 closedir(dir);
cache.h
+1
@@ -923,6 +923,7 @@ extern const char *git_mailmap_file;
923 extern void maybe_flush_or_die(FILE *, const char *);
924 extern int copy_fd(int ifd, int ofd);
925 extern int copy_file(const char *dst, const char *src, int mode);
926 +extern int copy_file_with_time(const char *dst, const char *src, int mode);
927 extern void write_or_die(int fd, const void *buf, size_t count);
928 extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
929 extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
copy.c
+21
@@ -35,6 +35,19 @@ int copy_fd(int ifd, int ofd)
35 return 0;
36 }
37
38 +static int copy_times(const char *dst, const char *src)
39 +{
40 + struct stat st;
41 + struct utimbuf times;
42 + if (stat(src, &st) < 0)
43 + return -1;
44 + times.actime = st.st_atime;
45 + times.modtime = st.st_mtime;
46 + if (utime(dst, &times) < 0)
47 + return -1;
48 + return 0;
49 +}
50 +
51 int copy_file(const char *dst, const char *src, int mode)
52 {
53 int fdi, fdo, status;
@@ -55,3 +68,11 @@ int copy_file(const char *dst, const char *src, int mode)
68
69 return status;
70 }
71 +
72 +int copy_file_with_time(const char *dst, const char *src, int mode)
73 +{
74 + int status = copy_file(dst, src, mode);
75 + if (!status)
76 + return copy_times(dst, src);
77 + return status;
78 +}