summaryrefslogtreecommitdiff
path: root/src/odb_loose.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-07-14 16:23:24 -0400
committerEdward Thomson <ethomson@github.com>2016-08-04 15:12:04 -0400
commit8f09a98e1809dcdfd9d25b8268657bac4d942e6a (patch)
tree25f4b977d9a9055569d95a5ba5b038dfbfb01d6a /src/odb_loose.c
parentd2794b0e37e98206b991ba4c8639ddf53c03bdb9 (diff)
downloadlibgit2-8f09a98e1809dcdfd9d25b8268657bac4d942e6a.tar.gz
odb: freshen existing objects when writing
When writing an object, we calculate its OID and see if it exists in the object database. If it does, we need to freshen the file that contains it.
Diffstat (limited to 'src/odb_loose.c')
-rw-r--r--src/odb_loose.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 228d4c334..1653e2783 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -918,6 +918,23 @@ cleanup:
return error;
}
+static int loose_backend__freshen(
+ git_odb_backend *_backend,
+ const git_oid *oid)
+{
+ loose_backend *backend = (loose_backend *)_backend;
+ git_buf path = GIT_BUF_INIT;
+ int error;
+
+ if (object_file_name(&path, backend, oid) < 0)
+ return -1;
+
+ error = git_futils_touch(path.ptr);
+ git_buf_free(&path);
+
+ return error;
+}
+
static void loose_backend__free(git_odb_backend *_backend)
{
loose_backend *backend;
@@ -975,6 +992,7 @@ int git_odb_backend_loose(
backend->parent.exists = &loose_backend__exists;
backend->parent.exists_prefix = &loose_backend__exists_prefix;
backend->parent.foreach = &loose_backend__foreach;
+ backend->parent.freshen = &loose_backend__freshen;
backend->parent.free = &loose_backend__free;
*backend_out = (git_odb_backend *)backend;