summaryrefslogtreecommitdiff
path: root/src/reader.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-07-01 13:42:53 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2018-11-05 15:53:33 +0000
commit5b8d5a22e702e4862ebfc56e37d18ca11bfebf02 (patch)
tree5cce9ba92dbed70e6506a040f07d79cb0208a420 /src/reader.c
parent4ff829e96deadcd0d0a11c5d0f3e989cace0056a (diff)
downloadlibgit2-5b8d5a22e702e4862ebfc56e37d18ca11bfebf02.tar.gz
apply: use preimage as the checkout baseline
Use the preimage as the checkout's baseline. This allows us to support applying patches to files that are modified in the working directory (those that differ from the HEAD and index). Without this, files will be reported as (checkout) conflicts. With this, we expect the on-disk data when we began the patch application (the "preimage") to be on-disk during checkout. We could have also simply used the `FORCE` flag to checkout to accomplish a similar mechanism. However, `FORCE` ignores all differences, while providing a preimage ensures that we will only overwrite the file contents that we actually read. Modify the reader interface to provide the OID to support this.
Diffstat (limited to 'src/reader.c')
-rw-r--r--src/reader.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/reader.c b/src/reader.c
index 754b90a3b..32900dfab 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -24,6 +24,7 @@ typedef struct {
static int tree_reader_read(
git_buf *out,
+ git_oid *out_id,
git_reader *_reader,
const char *filename)
{
@@ -37,6 +38,9 @@ static int tree_reader_read(
(error = git_buf_set(out, git_blob_rawcontent(blob), git_blob_rawsize(blob))) < 0)
goto done;
+ if (out_id)
+ git_oid_cpy(out_id, git_tree_entry_id(tree_entry));
+
done:
git_blob_free(blob);
git_tree_entry_free(tree_entry);
@@ -74,6 +78,7 @@ typedef struct {
static int workdir_reader_read(
git_buf *out,
+ git_oid *out_id,
git_reader *_reader,
const char *filename)
{
@@ -86,7 +91,11 @@ static int workdir_reader_read(
goto done;
/* TODO: should we read the filtered data? */
- error = git_futils_readbuffer(out, path.ptr);
+ if ((error = git_futils_readbuffer(out, path.ptr)) < 0)
+ goto done;
+
+ if (out_id)
+ error = git_odb_hash(out_id, out->ptr, out->size, GIT_OBJ_BLOB);
done:
git_buf_dispose(&path);
@@ -125,6 +134,7 @@ typedef struct {
static int index_reader_read(
git_buf *out,
+ git_oid *out_id,
git_reader *_reader,
const char *filename)
{
@@ -139,6 +149,9 @@ static int index_reader_read(
if ((error = git_blob_lookup(&blob, reader->repo, &entry->id)) < 0)
goto done;
+ if (out_id)
+ git_oid_cpy(out_id, &entry->id);
+
error = git_blob__getbuf(out, blob);
done:
@@ -185,11 +198,15 @@ int git_reader_for_index(
/* generic */
-int git_reader_read(git_buf *out, git_reader *reader, const char *filename)
+int git_reader_read(
+ git_buf *out,
+ git_oid *out_id,
+ git_reader *reader,
+ const char *filename)
{
assert(out && reader && filename);
- return reader->read(out, reader, filename);
+ return reader->read(out, out_id, reader, filename);
}
void git_reader_free(git_reader *reader)