{"thread":{"id":"20329","subject":"[PATCH v2 2/5] pick: simplify \"error(...)\" followed by \"return -1\"","startedAt":"2009-08-01T15:46:03Z","lastAt":"2009-08-01T15:46:03Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":2,"patchTotal":5},"messages":[{"id":"119338","messageId":"20090801154607.20922.88131.chriscool@tuxfamily.org","threadId":"20329","inReplyTo":null,"subject":"[PATCH v2 2/5] pick: simplify \"error(...)\" followed by \"return -1\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-08-01T15:46:03Z","receivedAt":"2009-08-01T15:46:03Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"into \"return error(...)\", as suggested by Junio.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n pick.c |   62 ++++++++++++++++++++++++--------------------------------------\n 1 files changed, 24 insertions(+), 38 deletions(-)\n\ndiff --git a/pick.c b/pick.c\nindex 77c7169..6fea39c 100644\n--- a/pick.c\n+++ b/pick.c\n@@ -93,24 +93,18 @@ int pick(struct commit *pick_commit, int mainline, int flags,\n \t * that represents the \"current\" state for merge-recursive\n \t * to work on.\n \t */\n-\tif (write_cache_as_tree(head, 0, NULL)) {\n-\t\terror(\"Your index file is unmerged.\");\n-\t\treturn -1;\n-\t}\n+\tif (write_cache_as_tree(head, 0, NULL))\n+\t\treturn error(\"Your index file is unmerged.\");\n \tdiscard_cache();\n \n \tindex_fd = hold_locked_index(&index_lock, 0);\n-\tif (index_fd < 0) {\n-\t\terror(\"Unable to create locked index: %s\",\n-\t\t\t\t\t\tstrerror(errno));\n-\t\treturn -1;\n-\t}\n+\tif (index_fd < 0)\n+\t\treturn error(\"Unable to create locked index: %s\",\n+\t\t\t     strerror(errno));\n \n \tif (!commit->parents) {\n-\t\tif (flags & PICK_REVERSE) {\n-\t\t\terror(\"Cannot revert a root commit\");\n-\t\t\treturn -1;\n-\t\t}\n+\t\tif (flags & PICK_REVERSE)\n+\t\t\treturn error(\"Cannot revert a root commit\");\n \t\tparent = NULL;\n \t}\n \telse if (commit->parents->next) {\n@@ -118,40 +112,32 @@ int pick(struct commit *pick_commit, int mainline, int flags,\n \t\tint cnt;\n \t\tstruct commit_list *p;\n \n-\t\tif (!mainline) {\n-\t\t\terror(\"Commit %s is a merge but no mainline was given.\",\n-\t\t\t    sha1_to_hex(commit->object.sha1));\n-\t\t\treturn -1;\n-\t\t}\n+\t\tif (!mainline)\n+\t\t\treturn error(\"Commit %s is a merge but no mainline was given.\",\n+\t\t\t\t     sha1_to_hex(commit->object.sha1));\n \n \t\tfor (cnt = 1, p = commit->parents;\n \t\t     cnt != mainline && p;\n \t\t     cnt++)\n \t\t\tp = p->next;\n-\t\tif (cnt != mainline || !p) {\n-\t\t\terror(\"Commit %s does not have parent %d\",\n-\t\t\t    sha1_to_hex(commit->object.sha1), mainline);\n-\t\t\treturn -1;\n-\t\t}\n+\t\tif (cnt != mainline || !p)\n+\t\t\treturn error(\"Commit %s does not have parent %d\",\n+\t\t\t\t     sha1_to_hex(commit->object.sha1),\n+\t\t\t\t     mainline);\n \t\tparent = p->item;\n-\t} else if (0 < mainline) {\n-\t\terror(\"Mainline was specified but commit %s is not a merge.\",\n-\t\t    sha1_to_hex(commit->object.sha1));\n-\t\treturn -1;\n-\t} else\n+\t} else if (0 < mainline)\n+\t\treturn error(\"Mainline was specified but commit %s is not a merge.\",\n+\t\t\t     sha1_to_hex(commit->object.sha1));\n+\telse\n \t\tparent = commit->parents->item;\n \n-\tif (!(message = commit->buffer)) {\n-\t\terror(\"Cannot get commit message for %s\",\n-\t\t\t\tsha1_to_hex(commit->object.sha1));\n-\t\treturn -1;\n-\t}\n+\tif (!(message = commit->buffer))\n+\t\treturn error(\"Cannot get commit message for %s\",\n+\t\t\t     sha1_to_hex(commit->object.sha1));\n \n-\tif (parent && parse_commit(parent) < 0) {\n-\t\terror(\"Cannot parse parent commit %s\",\n-\t\t      sha1_to_hex(parent->object.sha1));\n-\t\treturn -1;\n-\t}\n+\tif (parent && parse_commit(parent) < 0)\n+\t\treturn error(\"Cannot parse parent commit %s\",\n+\t\t\t     sha1_to_hex(parent->object.sha1));\n \n \toneline = get_oneline(message);\n \n-- \n1.6.4.133.g8a5c8\n"}]}