summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-09-06 14:13:12 -0700
committerRussell Belfer <rb@github.com>2013-09-06 14:13:12 -0700
commit97affdf2134d91c88fca6adbb6eeb0d990d01a31 (patch)
treebd6682f4c713b9a012582a0cffe60137c24b235d /src
parent366bd2f43dd6f74916b995340d62966fcd535b76 (diff)
parent4047950f30618c160cd2fdf5da39fb8e26b031d9 (diff)
downloadlibgit2-97affdf2134d91c88fca6adbb6eeb0d990d01a31.tar.gz
Merge pull request #1815 from libgit2/ntk/topic/stream_write/check_before_overwriting
Ask the odbbackend if the object exists before overwriting it
Diffstat (limited to 'src')
-rw-r--r--src/odb.c4
-rw-r--r--src/odb_loose.c7
2 files changed, 4 insertions, 7 deletions
diff --git a/src/odb.c b/src/odb.c
index e47715f79..dfb252178 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -900,6 +900,10 @@ int git_odb_stream_write(git_odb_stream *stream, const char *buffer, size_t len)
int git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream)
{
git_hash_final(out, stream->hash_ctx);
+
+ if (git_odb_exists(stream->backend->odb, out))
+ return 0;
+
return stream->finalize_write(stream, out);
}
diff --git a/src/odb_loose.c b/src/odb_loose.c
index abf46a118..ce63f4673 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -781,13 +781,6 @@ static int loose_backend__stream_fwrite(git_odb_stream *_stream, const git_oid *
if (object_file_name(&final_path, backend, oid) < 0 ||
object_mkdir(&final_path, backend) < 0)
error = -1;
- /*
- * Don't try to add an existing object to the repository. This
- * is what git does and allows us to sidestep the fact that
- * we're not allowed to overwrite a read-only file on Windows.
- */
- else if (git_path_exists(final_path.ptr) == true)
- git_filebuf_cleanup(&stream->fbuf);
else
error = git_filebuf_commit_at(
&stream->fbuf, final_path.ptr, GIT_OBJECT_FILE_MODE);