{"thread":{"id":"1097","subject":"[PATCH] enum for diff status","startedAt":"2005-07-04T01:18:35Z","lastAt":"2005-07-04T01:18:35Z","messageCount":1,"participants":["Pavel Roskin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"5616","messageId":"1120439915.30987.10.camel@dv","threadId":"1097","inReplyTo":null,"subject":"[PATCH] enum for diff status","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-07-04T01:18:35Z","receivedAt":"2005-07-04T01:18:35Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hello!\n\nReadability of the sources could be improved by replacing one-char diff\nstatus with more verbose keywords.  This patch converts diff status to\nenum.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\ndiff --git a/diff-helper.c b/diff-helper.c\n--- a/diff-helper.c\n+++ b/diff-helper.c\n@@ -54,7 +54,8 @@ int main(int ac, const char **av) {\n \t\tunsigned old_mode, new_mode;\n \t\tunsigned char old_sha1[20], new_sha1[20];\n \t\tchar old_path[PATH_MAX];\n-\t\tint status, score, two_paths;\n+\t\tenum diff_status status;\n+\t\tint score, two_paths;\n \t\tchar new_path[PATH_MAX];\n \n \t\tint ch;\n@@ -94,7 +95,8 @@ int main(int ac, const char **av) {\n \t\t\tif (!strchr(\"MCRNDU\", status))\n \t\t\t\tbreak;\n \t\t\ttwo_paths = score = 0;\n-\t\t\tif (status == 'R' || status == 'C')\n+\t\t\tif (status == DIFF_STATUS_RENAMED ||\n+\t\t\t    status == DIFF_STATUS_COPIED)\n \t\t\t\ttwo_paths = 1;\n \n \t\t\t/* pick up score if exists */\ndiff --git a/diff.c b/diff.c\n--- a/diff.c\n+++ b/diff.c\n@@ -652,7 +652,7 @@ static void run_diff(struct diff_filepai\n \tother = (strcmp(name, p->two->path) ? p->two->path : NULL);\n \tone = p->one; two = p->two;\n \tswitch (p->status) {\n-\tcase 'C':\n+\tcase DIFF_STATUS_COPIED:\n \t\tsprintf(msg_,\n \t\t\t\"similarity index %d%%\\n\"\n \t\t\t\"copy from %s\\n\"\n@@ -661,7 +661,7 @@ static void run_diff(struct diff_filepai\n \t\t\tname, other);\n \t\txfrm_msg = msg_;\n \t\tbreak;\n-\tcase 'R':\n+\tcase DIFF_STATUS_RENAMED:\n \t\tsprintf(msg_,\n \t\t\t\"similarity index %d%%\\n\"\n \t\t\t\"rename from %s\\n\"\n@@ -670,7 +670,7 @@ static void run_diff(struct diff_filepai\n \t\t\tname, other);\n \t\txfrm_msg = msg_;\n \t\tbreak;\n-\tcase 'M':\n+\tcase DIFF_STATUS_MODIFIED:\n \t\tif (p->score) {\n \t\t\tsprintf(msg_,\n \t\t\t\t\"dissimilarity index %d%%\",\n@@ -792,7 +792,7 @@ struct diff_filepair *diff_queue(struct \n \tdp->one = one;\n \tdp->two = two;\n \tdp->score = 0;\n-\tdp->status = 0;\n+\tdp->status = DIFF_STATUS_UNKNOWN;\n \tdp->source_stays = 0;\n \tdp->broken_pair = 0;\n \tdiff_q(queue, dp);\n@@ -831,10 +831,12 @@ static void diff_flush_raw(struct diff_f\n \t\tstatus[1] = 0;\n \t}\n \tswitch (p->status) {\n-\tcase 'C': case 'R':\n+\tcase DIFF_STATUS_COPIED:\n+\tcase DIFF_STATUS_RENAMED:\n \t\ttwo_paths = 1;\n \t\tbreak;\n-\tcase 'N': case 'D':\n+\tcase DIFF_STATUS_NEW:\n+\tcase DIFF_STATUS_DELETED:\n \t\ttwo_paths = 0;\n \t\tbreak;\n \tdefault:\n@@ -955,15 +957,15 @@ static void diff_resolve_rename_copy(voi\n \n \tfor (i = 0; i < q->nr; i++) {\n \t\tp = q->queue[i];\n-\t\tp->status = 0; /* undecided */\n+\t\tp->status = DIFF_STATUS_UNKNOWN;\n \t\tif (DIFF_PAIR_UNMERGED(p))\n-\t\t\tp->status = 'U';\n+\t\t\tp->status = DIFF_STATUS_UNMERGED;\n \t\telse if (!DIFF_FILE_VALID(p->one))\n-\t\t\tp->status = 'N';\n+\t\t\tp->status = DIFF_STATUS_NEW;\n \t\telse if (!DIFF_FILE_VALID(p->two))\n-\t\t\tp->status = 'D';\n+\t\t\tp->status = DIFF_STATUS_DELETED;\n \t\telse if (DIFF_PAIR_TYPE_CHANGED(p))\n-\t\t\tp->status = 'T';\n+\t\t\tp->status = DIFF_STATUS_TYPE_CHANGED;\n \n \t\t/* from this point on, we are dealing with a pair\n \t\t * whose both sides are valid and of the same type, i.e.\n@@ -971,7 +973,7 @@ static void diff_resolve_rename_copy(voi\n \t\t */\n \t\telse if (DIFF_PAIR_RENAME(p)) {\n \t\t\tif (p->source_stays) {\n-\t\t\t\tp->status = 'C';\n+\t\t\t\tp->status = DIFF_STATUS_COPIED;\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\t/* See if there is some other filepair that\n@@ -985,22 +987,22 @@ static void diff_resolve_rename_copy(voi\n \t\t\t\tif (!DIFF_PAIR_RENAME(pp))\n \t\t\t\t\tcontinue; /* not a rename/copy */\n \t\t\t\t/* pp is a rename/copy from the same source */\n-\t\t\t\tp->status = 'C';\n+\t\t\t\tp->status = DIFF_STATUS_COPIED;\n \t\t\t\tbreak;\n \t\t\t}\n \t\t\tif (!p->status)\n-\t\t\t\tp->status = 'R';\n+\t\t\t\tp->status = DIFF_STATUS_RENAMED;\n \t\t}\n \t\telse if (memcmp(p->one->sha1, p->two->sha1, 20) ||\n \t\t\t p->one->mode != p->two->mode)\n-\t\t\tp->status = 'M';\n+\t\t\tp->status = DIFF_STATUS_MODIFIED;\n \t\telse {\n \t\t\t/* This is a \"no-change\" entry and should not\n \t\t\t * happen anymore, but prepare for broken callers.\n \t\t\t */\n \t\t\terror(\"feeding unmodified %s to diffcore\",\n \t\t\t      p->one->path);\n-\t\t\tp->status = 'X';\n+\t\t\tp->status = DIFF_STATUS_UNCHANGED;\n \t\t}\n \t}\n \tdiff_debug_queue(\"resolve-rename-copy done\", q);\n@@ -1019,9 +1021,9 @@ void diff_flush(int diff_output_style)\n \tfor (i = 0; i < q->nr; i++) {\n \t\tstruct diff_filepair *p = q->queue[i];\n \t\tif ((diff_output_style == DIFF_FORMAT_NO_OUTPUT) ||\n-\t\t    (p->status == 'X'))\n+\t\t    (p->status == DIFF_STATUS_UNCHANGED))\n \t\t\tcontinue;\n-\t\tif (p->status == 0)\n+\t\tif (p->status == DIFF_STATUS_UNKNOWN)\n \t\t\tdie(\"internal error in diff-resolve-rename-copy\");\n \t\tswitch (diff_output_style) {\n \t\tcase DIFF_FORMAT_PATCH:\n@@ -1057,10 +1059,11 @@ static void diffcore_apply_filter(const \n \t\tint found;\n \t\tfor (i = found = 0; !found && i < q->nr; i++) {\n \t\t\tstruct diff_filepair *p = q->queue[i];\n-\t\t\tif (((p->status == 'M') &&\n+\t\t\tif (((p->status == DIFF_STATUS_MODIFIED) &&\n \t\t\t     ((p->score && strchr(filter, 'B')) ||\n \t\t\t      (!p->score && strchr(filter, 'M')))) ||\n-\t\t\t    ((p->status != 'M') && strchr(filter, p->status)))\n+\t\t\t    ((p->status != DIFF_STATUS_MODIFIED) &&\n+\t\t\t     strchr(filter, p->status)))\n \t\t\t\tfound++;\n \t\t}\n \t\tif (found)\n@@ -1078,10 +1081,11 @@ static void diffcore_apply_filter(const \n \t\t/* Only the matching ones */\n \t\tfor (i = 0; i < q->nr; i++) {\n \t\t\tstruct diff_filepair *p = q->queue[i];\n-\t\t\tif (((p->status == 'M') &&\n+\t\t\tif (((p->status == DIFF_STATUS_MODIFIED) &&\n \t\t\t     ((p->score && strchr(filter, 'B')) ||\n \t\t\t      (!p->score && strchr(filter, 'M')))) ||\n-\t\t\t    ((p->status != 'M') && strchr(filter, p->status)))\n+\t\t\t    ((p->status != DIFF_STATUS_MODIFIED) &&\n+\t\t\t     strchr(filter, p->status)))\n \t\t\t\tdiff_q(&outq, p);\n \t\t\telse\n \t\t\t\tdiff_free_filepair(p);\n@@ -1170,7 +1174,7 @@ void diff_helper_input(unsigned old_mode\n \t\t       const unsigned char *old_sha1,\n \t\t       const unsigned char *new_sha1,\n \t\t       const char *old_path,\n-\t\t       int status,\n+\t\t       enum diff_status status,\n \t\t       int score,\n \t\t       const char *new_path)\n {\ndiff --git a/diff.h b/diff.h\n--- a/diff.h\n+++ b/diff.h\n@@ -8,6 +8,18 @@\n \t(S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \\\n \tS_ISLNK(mode) ? S_IFLNK : S_IFDIR)\n \n+enum diff_status {\n+\tDIFF_STATUS_UNKNOWN = 0,\n+\tDIFF_STATUS_COPIED = 'C',\n+\tDIFF_STATUS_DELETED = 'D',\n+\tDIFF_STATUS_MODIFIED = 'M',\n+\tDIFF_STATUS_NEW = 'N',\n+\tDIFF_STATUS_RENAMED = 'R',\n+\tDIFF_STATUS_TYPE_CHANGED = 'T',\n+\tDIFF_STATUS_UNMERGED = 'U',\n+\tDIFF_STATUS_UNCHANGED = 'X',\n+};\n+\n extern void diff_addremove(int addremove,\n \t\t\t   unsigned mode,\n \t\t\t   const unsigned char *sha1,\n@@ -24,7 +36,7 @@ extern void diff_helper_input(unsigned m\n \t\t\t      const unsigned char *sha1,\n \t\t\t      const unsigned char *sha2,\n \t\t\t      const char *path1,\n-\t\t\t      int status,\n+\t\t\t      enum diff_status status,\n \t\t\t      int score,\n \t\t\t      const char *path2);\n \ndiff --git a/diffcore.h b/diffcore.h\n--- a/diffcore.h\n+++ b/diffcore.h\n@@ -49,7 +49,7 @@ struct diff_filepair {\n \tstruct diff_filespec *one;\n \tstruct diff_filespec *two;\n \tunsigned short int score;\n-\tchar status; /* M C R N D U (see Documentation/diff-format.txt) */\n+\tenum diff_status status; /* (see Documentation/diff-format.txt) */\n \tunsigned source_stays : 1; /* all of R/C are copies */\n \tunsigned broken_pair : 1;\n };\n\n\n-- \nRegards,\nPavel Roskin\n"}]}