summaryrefslogtreecommitdiff
path: root/copy.c
diff options
context:
space:
mode:
authorClemens Buchacher <drizzd@aon.at>2009-09-12 09:03:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-09-13 08:32:26 (GMT)
commitf7835a251c2c98df152792b15793b03e22bf078e (patch)
tree0fd7e28732e775adfd11b511ab226dc76a8fdb33 /copy.c
parent41698375ada57d51cf6db5cf25970ccd1b918180 (diff)
downloadgit-f7835a251c2c98df152792b15793b03e22bf078e.zip
git-f7835a251c2c98df152792b15793b03e22bf078e.tar.gz
git-f7835a251c2c98df152792b15793b03e22bf078e.tar.bz2
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>
Diffstat (limited to 'copy.c')
-rw-r--r--copy.c21
1 files changed, 21 insertions, 0 deletions
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;
+}