{"thread":{"id":"2765","subject":"[PATCH 1/3] checkout-index: allow checking out from higher stages.","startedAt":"2005-12-07T10:01:39Z","lastAt":"2005-12-07T10:01:39Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"13310","messageId":"7vwtihted8.fsf@assigned-by-dhcp.cox.net","threadId":"2765","inReplyTo":null,"subject":"[PATCH 1/3] checkout-index: allow checking out from higher stages.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-07T10:01:39Z","receivedAt":"2005-12-07T10:01:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The new option, --stage=<n>, lets you copy out from an unmerged,\nhigher stage.  This is to help the new merge world order during\na nontrivial merge.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n Documentation/git-checkout-index.txt |    6 +++\n checkout-index.c                     |   61 ++++++++++++++++++++++++----------\n 2 files changed, 48 insertions(+), 19 deletions(-)\n\n3bd348aeea24709cd9be4b9d741f79b6014cd7e3\ndiff --git a/Documentation/git-checkout-index.txt b/Documentation/git-checkout-index.txt\nindex 97eef22..9f32c65 100644\n--- a/Documentation/git-checkout-index.txt\n+++ b/Documentation/git-checkout-index.txt\n@@ -9,7 +9,7 @@ git-checkout-index - Copy files from the\n SYNOPSIS\n --------\n 'git-checkout-index' [-u] [-q] [-a] [-f] [-n] [--prefix=<string>]\n-\t           [--] <file>...\n+\t[--stage=<number>] [--] <file>...\n \n DESCRIPTION\n -----------\n@@ -40,6 +40,10 @@ OPTIONS\n \tWhen creating files, prepend <string> (usually a directory\n \tincluding a trailing /)\n \n+--stage=<number>::\n+\tInstead of checking out unmerged entries, copy out the\n+\tfiles from named stage.  <number> must be between 1 and 3.\n+\n --::\n \tDo not interpret any more arguments as options.\n \ndiff --git a/checkout-index.c b/checkout-index.c\nindex f1e716d..1e1c972 100644\n--- a/checkout-index.c\n+++ b/checkout-index.c\n@@ -36,6 +36,7 @@\n \n static const char *prefix;\n static int prefix_length;\n+static int checkout_stage; /* default to checkout stage0 */\n \n static struct checkout state = {\n \t.base_dir = \"\",\n@@ -48,20 +49,36 @@ static struct checkout state = {\n \n static int checkout_file(const char *name)\n {\n-\tint pos = cache_name_pos(name, strlen(name));\n-\tif (pos < 0) {\n-\t\tif (!state.quiet) {\n-\t\t\tpos = -pos - 1;\n-\t\t\tfprintf(stderr,\n-\t\t\t\t\"git-checkout-index: %s is %s.\\n\",\n-\t\t\t\tname,\n-\t\t\t\t(pos < active_nr &&\n-\t\t\t\t !strcmp(active_cache[pos]->name, name)) ?\n-\t\t\t\t\"unmerged\" : \"not in the cache\");\n-\t\t}\n-\t\treturn -1;\n+\tint namelen = strlen(name);\n+\tint pos = cache_name_pos(name, namelen);\n+\tint has_same_name = 0;\n+\n+\tif (pos < 0)\n+\t\tpos = -pos - 1;\n+\n+\twhile (pos < active_nr) {\n+\t\tstruct cache_entry *ce = active_cache[pos];\n+\t\tif (ce_namelen(ce) != namelen &&\n+\t\t    memcmp(ce->name, name, namelen))\n+\t\t\tbreak;\n+\t\thas_same_name = 1;\n+\t\tif (checkout_stage == ce_stage(ce))\n+\t\t\treturn checkout_entry(ce, &state);\n+\t\tpos++;\n+\t}\n+\n+\tif (!state.quiet) {\n+\t\tfprintf(stderr, \"git-checkout-index: %s \", name);\n+\t\tif (!has_same_name)\n+\t\t\tfprintf(stderr, \"is not in the cache\");\n+\t\telse if (checkout_stage)\n+\t\t\tfprintf(stderr, \"does not exist at stage %d\",\n+\t\t\t\tcheckout_stage);\n+\t\telse\n+\t\t\tfprintf(stderr, \"is unmerged\");\n+\t\tfputc('\\n', stderr);\n \t}\n-\treturn checkout_entry(active_cache[pos], &state);\n+\treturn -1;\n }\n \n static int checkout_all(void)\n@@ -70,11 +87,11 @@ static int checkout_all(void)\n \n \tfor (i = 0; i < active_nr ; i++) {\n \t\tstruct cache_entry *ce = active_cache[i];\n-\t\tif (ce_stage(ce))\n+\t\tif (ce_stage(ce) != checkout_stage)\n \t\t\tcontinue;\n \t\tif (prefix && *prefix &&\n-\t\t    ( ce_namelen(ce) <= prefix_length ||\n-\t\t      memcmp(prefix, ce->name, prefix_length) ))\n+\t\t    (ce_namelen(ce) <= prefix_length ||\n+\t\t     memcmp(prefix, ce->name, prefix_length)))\n \t\t\tcontinue;\n \t\tif (checkout_entry(ce, &state) < 0)\n \t\t\terrs++;\n@@ -88,7 +105,7 @@ static int checkout_all(void)\n }\n \n static const char checkout_cache_usage[] =\n-\"git-checkout-index [-u] [-q] [-a] [-f] [-n] [--prefix=<string>] [--] <file>...\";\n+\"git-checkout-index [-u] [-q] [-a] [-f] [-n] [--stage=[123]] [--prefix=<string>] [--] <file>...\";\n \n static struct cache_file cache_file;\n \n@@ -138,11 +155,19 @@ int main(int argc, char **argv)\n \t\t\t\tdie(\"cannot open index.lock file.\");\n \t\t\tcontinue;\n \t\t}\n-\t\tif (!memcmp(arg, \"--prefix=\", 9)) {\n+\t\tif (!strncmp(arg, \"--prefix=\", 9)) {\n \t\t\tstate.base_dir = arg+9;\n \t\t\tstate.base_dir_len = strlen(state.base_dir);\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strncmp(arg, \"--stage=\", 8)) {\n+\t\t\tint ch = arg[8];\n+\t\t\tif ('1' <= ch && ch <= '3')\n+\t\t\t\tcheckout_stage = arg[8] - '0';\n+\t\t\telse\n+\t\t\t\tdie(\"stage should be between 1 and 3\");\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (arg[0] == '-')\n \t\t\tusage(checkout_cache_usage);\n \t\tbreak;\n-- \n0.99.9.GIT\n"}]}