Commit e1bcc19110eb7d540dee92af489440dd2953b5d5

Russell Belfer 2012-03-01T11:45:00

Revert GIT_STATUS constants to avoid issues This reverts the changes to the GIT_STATUS constants and adds a new enumeration to describe the type of change in a git_diff_delta. I don't love this solution, but it should prevent strange errors from occurring for now. Eventually, I would like to unify the various status constants, but it needs a larger plan and I just wanted to eliminate this breakage quickly.

diff --git a/include/git2/diff.h b/include/git2/diff.h
index 413de8d..0e7c02f 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -75,6 +75,20 @@ enum {
 };
 
 /**
+ * What type of change is described by a git_diff_delta?
+ */
+typedef enum {
+	GIT_DELTA_UNMODIFIED = 0,
+	GIT_DELTA_ADDED = 1,
+	GIT_DELTA_DELETED = 2,
+	GIT_DELTA_MODIFIED = 3,
+	GIT_DELTA_RENAMED = 4,
+	GIT_DELTA_COPIED = 5,
+	GIT_DELTA_IGNORED = 6,
+	GIT_DELTA_UNTRACKED = 7
+} git_delta_t;
+
+/**
  * Description of one side of a diff.
  */
 typedef struct {
@@ -101,7 +115,7 @@ typedef struct {
 typedef struct {
 	git_diff_file old;
 	git_diff_file new;
-	git_status_t status;     /**< value from tree.h */
+	git_delta_t   status;
 	unsigned int similarity; /**< for RENAMED and COPIED, value from 0 to 100 */
 	int binary;
 } git_diff_delta;
diff --git a/include/git2/status.h b/include/git2/status.h
index 31823c6..5c45dae 100644
--- a/include/git2/status.h
+++ b/include/git2/status.h
@@ -31,7 +31,7 @@ GIT_BEGIN_DECL
 #define GIT_STATUS_WT_MODIFIED		(1 << 4)
 #define GIT_STATUS_WT_DELETED		(1 << 5)
 
-#define GIT_STATUS_WT_IGNORED		(1 << 6)
+#define GIT_STATUS_IGNORED		(1 << 6)
 
 /**
  * Gather file statuses and run a callback for each one.
diff --git a/include/git2/tree.h b/include/git2/tree.h
index 95be1d3..972c379 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -314,15 +314,9 @@ enum git_treewalk_mode {
 GIT_EXTERN(int) git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payload);
 
 typedef enum {
-	GIT_STATUS_UNMODIFIED = 0,
 	GIT_STATUS_ADDED = 1,
 	GIT_STATUS_DELETED = 2,
 	GIT_STATUS_MODIFIED = 3,
-	/* the following will only be generated by git_diff functions */
-	GIT_STATUS_RENAMED = 4,
-	GIT_STATUS_COPIED = 5,
-	GIT_STATUS_IGNORED = 6,
-	GIT_STATUS_UNTRACKED = 7
 } git_status_t;
 
 typedef struct {
diff --git a/src/diff.c b/src/diff.c
index dcc0aef..a0fd5fd 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -29,7 +29,7 @@ static void diff_delta__free(git_diff_delta *delta)
 
 static git_diff_delta *diff_delta__alloc(
 	git_diff_list *diff,
-	git_status_t status,
+	git_delta_t status,
 	const char *path)
 {
 	git_diff_delta *delta = git__calloc(1, sizeof(git_diff_delta));
@@ -46,8 +46,8 @@ static git_diff_delta *diff_delta__alloc(
 
 	if (diff->opts.flags & GIT_DIFF_REVERSE) {
 		switch (status) {
-		case GIT_STATUS_ADDED:   status = GIT_STATUS_DELETED; break;
-		case GIT_STATUS_DELETED: status = GIT_STATUS_ADDED; break;
+		case GIT_DELTA_ADDED:   status = GIT_DELTA_DELETED; break;
+		case GIT_DELTA_DELETED: status = GIT_DELTA_ADDED; break;
 		default: break; /* leave other status values alone */
 		}
 	}
@@ -112,16 +112,16 @@ static git_diff_delta *diff_delta__merge_like_cgit(
 	 * those choices so we can emulate the type of diff.
 	 */
 	if (git_oid_cmp(&dup->old.oid, &dup->new.oid) == 0) {
-		if (dup->status == GIT_STATUS_DELETED)
+		if (dup->status == GIT_DELTA_DELETED)
 			/* preserve pending delete info */;
-		else if (b->status == GIT_STATUS_UNTRACKED ||
-				 b->status == GIT_STATUS_IGNORED)
+		else if (b->status == GIT_DELTA_UNTRACKED ||
+				 b->status == GIT_DELTA_IGNORED)
 			dup->status = b->status;
 		else
-			dup->status = GIT_STATUS_UNMODIFIED;
+			dup->status = GIT_DELTA_UNMODIFIED;
 	}
-	else if (dup->status == GIT_STATUS_UNMODIFIED ||
-			 b->status == GIT_STATUS_DELETED)
+	else if (dup->status == GIT_DELTA_UNMODIFIED ||
+			 b->status == GIT_DELTA_DELETED)
 		dup->status = b->status;
 
 	return dup;
@@ -129,7 +129,7 @@ static git_diff_delta *diff_delta__merge_like_cgit(
 
 static int diff_delta__from_one(
 	git_diff_list *diff,
-	git_status_t   status,
+	git_delta_t   status,
 	const git_index_entry *entry)
 {
 	int error;
@@ -138,9 +138,9 @@ static int diff_delta__from_one(
 		return git__rethrow(GIT_ENOMEM, "Could not allocate diff record");
 
 	/* This fn is just for single-sided diffs */
-	assert(status != GIT_STATUS_MODIFIED);
+	assert(status != GIT_DELTA_MODIFIED);
 
-	if (delta->status == GIT_STATUS_DELETED) {
+	if (delta->status == GIT_DELTA_DELETED) {
 		delta->old.mode = entry->mode;
 		delta->old.size = entry->file_size;
 		git_oid_cpy(&delta->old.oid, &entry->oid);
@@ -161,7 +161,7 @@ static int diff_delta__from_one(
 
 static int diff_delta__from_two(
 	git_diff_list *diff,
-	git_status_t   status,
+	git_delta_t   status,
 	const git_index_entry *old,
 	const git_index_entry *new,
 	git_oid *new_oid)
@@ -333,9 +333,9 @@ static int maybe_modified(
 		return GIT_SUCCESS;
 
 	if (GIT_MODE_TYPE(oitem->mode) != GIT_MODE_TYPE(nitem->mode)) {
-		error = diff_delta__from_one(diff, GIT_STATUS_DELETED, oitem);
+		error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem);
 		if (error == GIT_SUCCESS)
-			error = diff_delta__from_one(diff, GIT_STATUS_ADDED, nitem);
+			error = diff_delta__from_one(diff, GIT_DELTA_ADDED, nitem);
 		return error;
 	}
 
@@ -370,7 +370,7 @@ static int maybe_modified(
 	}
 
 	return diff_delta__from_two(
-		diff, GIT_STATUS_MODIFIED, oitem, nitem, use_noid);
+		diff, GIT_DELTA_MODIFIED, oitem, nitem, use_noid);
 }
 
 static int diff_from_iterators(
@@ -401,7 +401,7 @@ static int diff_from_iterators(
 
 		/* create DELETED records for old items not matched in new */
 		if (oitem && (!nitem || strcmp(oitem->path, nitem->path) < 0)) {
-			error = diff_delta__from_one(diff, GIT_STATUS_DELETED, oitem);
+			error = diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem);
 			if (error == GIT_SUCCESS)
 				error = git_iterator_advance(old, &oitem);
 			continue;
@@ -412,7 +412,7 @@ static int diff_from_iterators(
 		 */
 		if (nitem && (!oitem || strcmp(oitem->path, nitem->path) > 0)) {
 			int is_ignored;
-			git_status_t use_status = GIT_STATUS_ADDED;
+			git_delta_t delta_type = GIT_DELTA_ADDED;
 
 			/* contained in ignored parent directory, so this can be skipped. */
 			if (ignore_prefix != NULL &&
@@ -431,14 +431,14 @@ static int diff_from_iterators(
 					error = git_iterator_advance_into_directory(new, &nitem);
 					continue;
 				}
-				use_status = GIT_STATUS_UNTRACKED;
+				delta_type = GIT_DELTA_UNTRACKED;
 			}
 			else if (is_ignored)
-				use_status = GIT_STATUS_IGNORED;
+				delta_type = GIT_DELTA_IGNORED;
 			else if (new->type == GIT_ITERATOR_WORKDIR)
-				use_status = GIT_STATUS_UNTRACKED;
+				delta_type = GIT_DELTA_UNTRACKED;
 
-			error = diff_delta__from_one(diff, use_status, nitem);
+			error = diff_delta__from_one(diff, delta_type, nitem);
 			if (error == GIT_SUCCESS)
 				error = git_iterator_advance(new, &nitem);
 			continue;
diff --git a/src/diff_output.c b/src/diff_output.c
index b800be9..8493518 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -309,14 +309,14 @@ int git_diff_foreach(
 		git_blob *old_blob = NULL, *new_blob = NULL;
 		git_map old_data, new_data;
 
-		if (delta->status == GIT_STATUS_UNMODIFIED)
+		if (delta->status == GIT_DELTA_UNMODIFIED)
 			continue;
 
-		if (delta->status == GIT_STATUS_IGNORED &&
+		if (delta->status == GIT_DELTA_IGNORED &&
 			(diff->opts.flags & GIT_DIFF_INCLUDE_IGNORED) == 0)
 			continue;
 
-		if (delta->status == GIT_STATUS_UNTRACKED &&
+		if (delta->status == GIT_DELTA_UNTRACKED &&
 			(diff->opts.flags & GIT_DIFF_INCLUDE_UNTRACKED) == 0)
 			continue;
 
@@ -337,8 +337,8 @@ int git_diff_foreach(
 		/* map files */
 		if (delta->binary != 1 &&
 			(hunk_cb || line_cb) &&
-			(delta->status == GIT_STATUS_DELETED ||
-			 delta->status == GIT_STATUS_MODIFIED))
+			(delta->status == GIT_DELTA_DELETED ||
+			 delta->status == GIT_DELTA_MODIFIED))
 		{
 			if (diff->old_src == GIT_ITERATOR_WORKDIR)
 				error = get_workdir_content(diff->repo, &delta->old, &old_data);
@@ -351,8 +351,8 @@ int git_diff_foreach(
 
 		if (delta->binary != 1 &&
 			(hunk_cb || line_cb || git_oid_iszero(&delta->new.oid)) &&
-			(delta->status == GIT_STATUS_ADDED ||
-			 delta->status == GIT_STATUS_MODIFIED))
+			(delta->status == GIT_DELTA_ADDED ||
+			 delta->status == GIT_DELTA_MODIFIED))
 		{
 			if (diff->new_src == GIT_ITERATOR_WORKDIR)
 				error = get_workdir_content(diff->repo, &delta->new, &new_data);
@@ -372,7 +372,7 @@ int git_diff_foreach(
 				 * incorrect status and need to skip this item.
 				 */
 				if (git_oid_cmp(&delta->old.oid, &delta->new.oid) == 0) {
-					delta->status = GIT_STATUS_UNMODIFIED;
+					delta->status = GIT_DELTA_UNMODIFIED;
 					goto cleanup;
 				}
 			}
@@ -451,13 +451,13 @@ static int print_compact(void *data, git_diff_delta *delta, float progress)
 	GIT_UNUSED(progress);
 
 	switch (delta->status) {
-	case GIT_STATUS_ADDED: code = 'A'; break;
-	case GIT_STATUS_DELETED: code = 'D'; break;
-	case GIT_STATUS_MODIFIED: code = 'M'; break;
-	case GIT_STATUS_RENAMED: code = 'R'; break;
-	case GIT_STATUS_COPIED: code = 'C'; break;
-	case GIT_STATUS_IGNORED: code = 'I'; break;
-	case GIT_STATUS_UNTRACKED: code = '?'; break;
+	case GIT_DELTA_ADDED: code = 'A'; break;
+	case GIT_DELTA_DELETED: code = 'D'; break;
+	case GIT_DELTA_MODIFIED: code = 'M'; break;
+	case GIT_DELTA_RENAMED: code = 'R'; break;
+	case GIT_DELTA_COPIED: code = 'C'; break;
+	case GIT_DELTA_IGNORED: code = 'I'; break;
+	case GIT_DELTA_UNTRACKED: code = '?'; break;
 	default: code = 0;
 	}
 
@@ -695,8 +695,8 @@ int git_diff_blobs(
 
 	/* populate a "fake" delta record */
 	delta.status = old.ptr ?
-		(new.ptr ? GIT_STATUS_MODIFIED : GIT_STATUS_DELETED) :
-		(new.ptr ? GIT_STATUS_ADDED : GIT_STATUS_UNTRACKED);
+		(new.ptr ? GIT_DELTA_MODIFIED : GIT_DELTA_DELETED) :
+		(new.ptr ? GIT_DELTA_ADDED : GIT_DELTA_UNTRACKED);
 	delta.old.mode = 0100644; /* can't know the truth from a blob alone */
 	delta.new.mode = 0100644;
 	git_oid_cpy(&delta.old.oid, git_object_id((const git_object *)old_blob));
diff --git a/src/status.c b/src/status.c
index 76ae831..106e500 100644
--- a/src/status.c
+++ b/src/status.c
@@ -131,7 +131,7 @@ static int status_entry_update_ignore(struct status_entry *e, git_ignores *ignor
 	if ((error = git_ignore__lookup(ignores, path, &ignored)) == GIT_SUCCESS &&
 		ignored)
 		e->status_flags =
-			(e->status_flags & ~GIT_STATUS_WT_NEW) | GIT_STATUS_WT_IGNORED;
+			(e->status_flags & ~GIT_STATUS_WT_NEW) | GIT_STATUS_IGNORED;
 
 	return error;
 }
diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c
index 67a4f1c..d8eca7d 100644
--- a/tests-clar/diff/diff_helpers.c
+++ b/tests-clar/diff/diff_helpers.c
@@ -30,11 +30,11 @@ int diff_file_fn(
 	(void)progress;
 	e->files++;
 	switch (delta->status) {
-	case GIT_STATUS_ADDED: e->file_adds++; break;
-	case GIT_STATUS_DELETED: e->file_dels++; break;
-	case GIT_STATUS_MODIFIED: e->file_mods++; break;
-	case GIT_STATUS_IGNORED: e->file_ignored++; break;
-	case GIT_STATUS_UNTRACKED: e->file_untracked++; break;
+	case GIT_DELTA_ADDED: e->file_adds++; break;
+	case GIT_DELTA_DELETED: e->file_dels++; break;
+	case GIT_DELTA_MODIFIED: e->file_mods++; break;
+	case GIT_DELTA_IGNORED: e->file_ignored++; break;
+	case GIT_DELTA_UNTRACKED: e->file_untracked++; break;
 	default: break;
 	}
 	return 0;
diff --git a/tests-clar/status/status_data.h b/tests-clar/status/status_data.h
index 719d841..1a68648 100644
--- a/tests-clar/status/status_data.h
+++ b/tests-clar/status/status_data.h
@@ -29,7 +29,7 @@ static const char *entry_paths0[] = {
 
 static const unsigned int entry_statuses0[] = {
 	GIT_STATUS_WT_DELETED,
-	GIT_STATUS_WT_IGNORED,
+	GIT_STATUS_IGNORED,
 	GIT_STATUS_WT_MODIFIED,
 	GIT_STATUS_WT_NEW,
 	GIT_STATUS_INDEX_MODIFIED,
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index f654b8a..132ec1f 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -120,7 +120,7 @@ void test_status_worktree__ignores(void)
 		cl_git_pass(
 			git_status_should_ignore(repo, entry_paths0[i], &ignored)
 		);
-		cl_assert(ignored == (entry_statuses0[i] == GIT_STATUS_WT_IGNORED));
+		cl_assert(ignored == (entry_statuses0[i] == GIT_STATUS_IGNORED));
 	}
 
 	cl_git_pass(
diff --git a/tests/t18-status.c b/tests/t18-status.c
index aeadd5e..2b90ac6 100644
--- a/tests/t18-status.c
+++ b/tests/t18-status.c
@@ -83,7 +83,7 @@ static const char *entry_paths0[] = {
 
 static const unsigned int entry_statuses0[] = {
 	GIT_STATUS_WT_DELETED,
-	GIT_STATUS_WT_IGNORED,
+	GIT_STATUS_IGNORED,
 	GIT_STATUS_WT_MODIFIED,
 	GIT_STATUS_WT_NEW,
 	GIT_STATUS_INDEX_MODIFIED,
@@ -205,7 +205,7 @@ static const char *entry_paths2[] = {
 static const unsigned int entry_statuses2[] = {
 	GIT_STATUS_WT_DELETED,
 	GIT_STATUS_WT_DELETED,
-	GIT_STATUS_WT_IGNORED,
+	GIT_STATUS_IGNORED,
 	GIT_STATUS_WT_DELETED,
 	GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_MODIFIED,
 	GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_MODIFIED,
@@ -291,7 +291,7 @@ static const unsigned int entry_statuses3[] = {
 	GIT_STATUS_WT_NEW,
 	GIT_STATUS_WT_NEW,
 	GIT_STATUS_WT_DELETED,
-	GIT_STATUS_WT_IGNORED,
+	GIT_STATUS_IGNORED,
 	GIT_STATUS_WT_MODIFIED,
 	GIT_STATUS_WT_NEW,
 	GIT_STATUS_INDEX_MODIFIED,