summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-05-19 11:23:59 -0400
committerEdward Thomson <ethomson@microsoft.com>2015-05-28 09:47:31 -0400
commit9f545b9d71c7bd316be80e5fe8b47135e9deb97e (patch)
treed2cf3279b4fd716fcea963a2a0118dd522a52270 /src
parent2f1080ea04ad1235efcd4b213dbe3a1b847644f7 (diff)
downloadlibgit2-9f545b9d71c7bd316be80e5fe8b47135e9deb97e.tar.gz
introduce `git_index_entry_is_conflict`
It's not always obvious the mapping between stage level and conflict-ness. More importantly, this can lead otherwise sane people to write constructs like `if (!git_index_entry_stage(entry))`, which (while technically correct) is unreadable. Provide a nice method to help avoid such messy thinking.
Diffstat (limited to 'src')
-rw-r--r--src/diff.c15
-rw-r--r--src/index.c7
-rw-r--r--src/iterator.c2
-rw-r--r--src/merge.c4
4 files changed, 17 insertions, 11 deletions
diff --git a/src/diff.c b/src/diff.c
index abe0de0d4..46f339692 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -180,14 +180,14 @@ static int diff_delta__from_two(
GITERR_CHECK_ALLOC(delta);
delta->nfiles = 2;
- if (!git_index_entry_stage(old_entry)) {
+ if (!git_index_entry_is_conflict(old_entry)) {
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;
}
- if (!git_index_entry_stage(new_entry)) {
+ 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;
@@ -765,7 +765,8 @@ static int maybe_modified(
nmode = (nmode & ~MODE_BITS_MASK) | (omode & MODE_BITS_MASK);
/* if one side is a conflict, mark the whole delta as conflicted */
- if (git_index_entry_stage(oitem) > 0 || git_index_entry_stage(nitem) > 0)
+ if (git_index_entry_is_conflict(oitem) ||
+ git_index_entry_is_conflict(nitem))
status = GIT_DELTA_CONFLICTED;
/* support "assume unchanged" (poorly, b/c we still stat everything) */
@@ -923,8 +924,8 @@ static int iterator_advance(
*/
while ((error = git_iterator_advance(entry, iterator)) == 0) {
if (!(iterator->flags & GIT_ITERATOR_INCLUDE_CONFLICTS) ||
- git_index_entry_stage(prev_entry) == 0 ||
- git_index_entry_stage(*entry) == 0)
+ !git_index_entry_is_conflict(prev_entry) ||
+ !git_index_entry_is_conflict(*entry))
break;
cmp = (iterator->flags & GIT_ITERATOR_IGNORE_CASE) ?
@@ -985,7 +986,7 @@ static int handle_unmatched_new_item(
contains_oitem = entry_is_prefixed(diff, info->oitem, nitem);
/* update delta_type if this item is conflicted */
- if (git_index_entry_stage(nitem))
+ if (git_index_entry_is_conflict(nitem))
delta_type = GIT_DELTA_CONFLICTED;
/* update delta_type if this item is ignored */
@@ -1133,7 +1134,7 @@ static int handle_unmatched_old_item(
int error;
/* update delta_type if this item is conflicted */
- if (git_index_entry_stage(info->oitem))
+ if (git_index_entry_is_conflict(info->oitem))
delta_type = GIT_DELTA_CONFLICTED;
if ((error = diff_delta__from_one(diff, delta_type, info->oitem, NULL)) < 0)
diff --git a/src/index.c b/src/index.c
index e37cb1f4d..bd65d924b 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1537,7 +1537,7 @@ int git_index_conflict_next(
while (iterator->cur < iterator->index->entries.length) {
entry = git_index_get_byindex(iterator->index, iterator->cur);
- if (git_index_entry_stage(entry) > 0) {
+ if (git_index_entry_is_conflict(entry)) {
if ((len = index_conflict__get_byindex(
ancestor_out,
our_out,
@@ -2383,6 +2383,11 @@ int git_index_entry_stage(const git_index_entry *entry)
return GIT_IDXENTRY_STAGE(entry);
}
+int git_index_entry_is_conflict(const git_index_entry *entry)
+{
+ return (GIT_IDXENTRY_STAGE(entry) > 0);
+}
+
typedef struct read_tree_data {
git_index *index;
git_vector *old_entries;
diff --git a/src/iterator.c b/src/iterator.c
index 1e946fadc..93303a87d 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -674,7 +674,7 @@ static const git_index_entry *index_iterator__advance_over_conflicts(index_itera
const git_index_entry *ie = index_iterator__index_entry(ii);
if (!iterator__include_conflicts(ii)) {
- while (ie && git_index_entry_stage(ie) != 0) {
+ while (ie && git_index_entry_is_conflict(ie)) {
ii->current++;
ie = index_iterator__index_entry(ii);
}
diff --git a/src/merge.c b/src/merge.c
index 5e7727429..eaf7eee1f 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2492,7 +2492,7 @@ int git_merge__check_result(git_repository *repo, git_index *index_new)
for (i = 0; i < git_index_entrycount(index_new); i++) {
e = git_index_get_byindex(index_new, i);
- if (git_index_entry_stage(e) != 0 &&
+ if (git_index_entry_is_conflict(e) &&
(git_vector_last(&paths) == NULL ||
strcmp(git_vector_last(&paths), e->path) != 0)) {
@@ -2544,7 +2544,7 @@ int git_merge__append_conflicts_to_merge_msg(
for (i = 0; i < git_index_entrycount(index); i++) {
const git_index_entry *e = git_index_get_byindex(index, i);
- if (git_index_entry_stage(e) == 0)
+ if (!git_index_entry_is_conflict(e))
continue;
if (last == NULL || strcmp(e->path, last) != 0)