Skip to contentSkip to conversation

enum for diff status

PATCH New Pavel Roskin 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 enum for diff status

Hello!

Readability of the sources could be improved by replacing one-char diff status with more verbose keywords. This patch converts diff status to enum.

diff-helper.c +4 -2
@@ -54,7 +54,8 @@ int main(int ac, const char **av) {
 		unsigned old_mode, new_mode;
 		unsigned char old_sha1[20], new_sha1[20];
 		char old_path[PATH_MAX];
-		int status, score, two_paths;
+		enum diff_status status;
+		int score, two_paths;
 		char new_path[PATH_MAX];
 
 		int ch;
@@ -94,7 +95,8 @@ int main(int ac, const char **av) {
 			if (!strchr("MCRNDU", status))
 				break;
 			two_paths = score = 0;
-			if (status == 'R' || status == 'C')
+			if (status == DIFF_STATUS_RENAMED ||
+			    status == DIFF_STATUS_COPIED)
 				two_paths = 1;
 
 			/* pick up score if exists */
diff.c +27 -23

145 lines not on this page · raw message

diff.h +13 -1
@@ -8,6 +8,18 @@
 	(S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \
 	S_ISLNK(mode) ? S_IFLNK : S_IFDIR)
 
+enum diff_status {
+	DIFF_STATUS_UNKNOWN = 0,
+	DIFF_STATUS_COPIED = 'C',
+	DIFF_STATUS_DELETED = 'D',
+	DIFF_STATUS_MODIFIED = 'M',
+	DIFF_STATUS_NEW = 'N',
+	DIFF_STATUS_RENAMED = 'R',
+	DIFF_STATUS_TYPE_CHANGED = 'T',
+	DIFF_STATUS_UNMERGED = 'U',
+	DIFF_STATUS_UNCHANGED = 'X',
+};
+
 extern void diff_addremove(int addremove,
 			   unsigned mode,
 			   const unsigned char *sha1,
@@ -24,7 +36,7 @@ extern void diff_helper_input(unsigned m
 			      const unsigned char *sha1,
 			      const unsigned char *sha2,
 			      const char *path1,
-			      int status,
+			      enum diff_status status,
 			      int score,
 			      const char *path2);
 
diffcore.h +1 -1
@@ -49,7 +49,7 @@ struct diff_filepair {
 	struct diff_filespec *one;
 	struct diff_filespec *two;
 	unsigned short int score;
-	char status; /* M C R N D U (see Documentation/diff-format.txt) */
+	enum diff_status status; /* (see Documentation/diff-format.txt) */
 	unsigned source_stays : 1; /* all of R/C are copies */
 	unsigned broken_pair : 1;
 };
Signature · 2 lines
Regards,
Pavel Roskin