Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit f7835a2

Browse files
Clemens Buchachergitster
Clemens Buchacher
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4169837 commit f7835a2

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

builtin-clone.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
269269
die_errno("failed to create link '%s'", dest->buf);
270270
option_no_hardlinks = 1;
271271
}
272-
if (copy_file(dest->buf, src->buf, 0666))
272+
if (copy_file_with_time(dest->buf, src->buf, 0666))
273273
die_errno("failed to copy file to '%s'", dest->buf);
274274
}
275275
closedir(dir);

cache.h

+1
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ extern const char *git_mailmap_file;
923923
extern void maybe_flush_or_die(FILE *, const char *);
924924
extern int copy_fd(int ifd, int ofd);
925925
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);
926927
extern void write_or_die(int fd, const void *buf, size_t count);
927928
extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
928929
extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);

copy.c

+21
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ int copy_fd(int ifd, int ofd)
3535
return 0;
3636
}
3737

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+
3851
int copy_file(const char *dst, const char *src, int mode)
3952
{
4053
int fdi, fdo, status;
@@ -55,3 +68,11 @@ int copy_file(const char *dst, const char *src, int mode)
5568

5669
return status;
5770
}
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+
}

0 commit comments

Comments
 (0)