Skip to content

Commit

Permalink
preserve mtime of local clone
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Clemens Buchacher authored and gitster committed Sep 13, 2009
1 parent 4169837 commit f7835a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin-clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

0 comments on commit f7835a2

Please sign in to comment.