summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-05-19 18:26:04 -0400
committerEdward Thomson <ethomson@microsoft.com>2015-05-28 09:47:47 -0400
commit10549a2df166cd3b951c65ab89c33f7ef21c6b7a (patch)
tree0bf109c7f9cc662b9912970e757c981bfccc68cc
parent666ae188215557fb440b74f6af6e5cfbec27d459 (diff)
downloadlibgit2-10549a2df166cd3b951c65ab89c33f7ef21c6b7a.tar.gz
Introduce `GIT_DIFF_FLAG_EXISTS`
Mark the `old_file` and `new_file` sides of a delta with a new bit, `GIT_DIFF_FLAG_EXISTS`, that introduces that a particular side of the delta exists in the diff. This is useful for indicating whether a working directory item exists or not, in the presence of a conflict. Diff users may have previously used DELETED to determine this information.
-rw-r--r--CHANGELOG.md5
-rw-r--r--include/git2/diff.h1
-rw-r--r--src/diff.c7
3 files changed, 12 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cdd1a5d27..cf65fcfbd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -52,6 +52,11 @@ support for HTTPS connections insead of OpenSSL.
* `git_index_conflict_add()` will remove staged entries that exist for
conflicted paths.
+* The flags for a `git_diff_file` will now have the `GIT_DIFF_FLAG_EXISTS`
+ bit set when a file exists on that side of the diff. This is useful
+ for understanding whether a side of the diff exists in the presence of
+ a conflict.
+
### API additions
* The `git_merge_options` gained a `file_flags` member.
diff --git a/include/git2/diff.h b/include/git2/diff.h
index 7505c08c2..c0d42e30e 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -226,6 +226,7 @@ typedef enum {
GIT_DIFF_FLAG_BINARY = (1u << 0), /**< file(s) treated as binary data */
GIT_DIFF_FLAG_NOT_BINARY = (1u << 1), /**< file(s) treated as text data */
GIT_DIFF_FLAG_VALID_ID = (1u << 2), /**< `id` value is known correct */
+ GIT_DIFF_FLAG_EXISTS = (1u << 3), /**< file exists at this side of the delta */
} git_diff_flag_t;
/**
diff --git a/src/diff.c b/src/diff.c
index d4f7d260c..c9d1d8730 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -127,10 +127,12 @@ static int diff_delta__from_one(
if (has_old) {
delta->old_file.mode = entry->mode;
delta->old_file.size = entry->file_size;
+ delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
git_oid_cpy(&delta->old_file.id, &entry->id);
} else /* ADDED, IGNORED, UNTRACKED */ {
delta->new_file.mode = entry->mode;
delta->new_file.size = entry->file_size;
+ delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS;
git_oid_cpy(&delta->new_file.id, &entry->id);
}
@@ -184,13 +186,16 @@ static int diff_delta__from_two(
delta->old_file.size = old_entry->file_size;
delta->old_file.mode = old_mode;
git_oid_cpy(&delta->old_file.id, old_id);
- delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
+ delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID |
+ GIT_DIFF_FLAG_EXISTS;
}
if (!git_index_entry_is_conflict(new_entry)) {
git_oid_cpy(&delta->new_file.id, new_id);
delta->new_file.size = new_entry->file_size;
delta->new_file.mode = new_mode;
+ delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
+ delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS;
if (!git_oid_iszero(&new_entry->id))
delta->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;