@matheusbsbs / matheus-bagliano / commits / 3bd348aeea
Fork 0

checkout-index: allow checking out from higher stages.

The new option, --stage=<n>, lets you copy out from an unmerged, higher stage. This is to help the new merge world order during a nontrivial merge. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 7, 2005 at 00:29 UTC 3bd348aeea24709cd9be4b9d741f79b6014cd7e3
2 files changed +48 -19
Documentation/git-checkout-index.txt
+5 -1
@@ -9,7 +9,7 @@ git-checkout-index - Copy files from the index to the working directory
9 SYNOPSIS
10 --------
11 'git-checkout-index' [-u] [-q] [-a] [-f] [-n] [--prefix=<string>]
12 - [--] <file>...
12 + [--stage=<number>] [--] <file>...
13
14 DESCRIPTION
15 -----------
@@ -40,6 +40,10 @@ OPTIONS
40 When creating files, prepend <string> (usually a directory
41 including a trailing /)
42
43 +--stage=<number>::
44 + Instead of checking out unmerged entries, copy out the
45 + files from named stage. <number> must be between 1 and 3.
46 +
47 --::
48 Do not interpret any more arguments as options.
49
checkout-index.c
+43 -18
@@ -36,6 +36,7 @@
36
37 static const char *prefix;
38 static int prefix_length;
39 +static int checkout_stage; /* default to checkout stage0 */
40
41 static struct checkout state = {
42 .base_dir = "",
@@ -48,20 +49,36 @@ static struct checkout state = {
49
50 static int checkout_file(const char *name)
51 {
51 - int pos = cache_name_pos(name, strlen(name));
52 - if (pos < 0) {
53 - if (!state.quiet) {
54 - pos = -pos - 1;
55 - fprintf(stderr,
56 - "git-checkout-index: %s is %s.\n",
57 - name,
58 - (pos < active_nr &&
59 - !strcmp(active_cache[pos]->name, name)) ?
60 - "unmerged" : "not in the cache");
61 - }
62 - return -1;
52 + int namelen = strlen(name);
53 + int pos = cache_name_pos(name, namelen);
54 + int has_same_name = 0;
55 +
56 + if (pos < 0)
57 + pos = -pos - 1;
58 +
59 + while (pos < active_nr) {
60 + struct cache_entry *ce = active_cache[pos];
61 + if (ce_namelen(ce) != namelen &&
62 + memcmp(ce->name, name, namelen))
63 + break;
64 + has_same_name = 1;
65 + if (checkout_stage == ce_stage(ce))
66 + return checkout_entry(ce, &state);
67 + pos++;
68 }
64 - return checkout_entry(active_cache[pos], &state);
69 +
70 + if (!state.quiet) {
71 + fprintf(stderr, "git-checkout-index: %s ", name);
72 + if (!has_same_name)
73 + fprintf(stderr, "is not in the cache");
74 + else if (checkout_stage)
75 + fprintf(stderr, "does not exist at stage %d",
76 + checkout_stage);
77 + else
78 + fprintf(stderr, "is unmerged");
79 + fputc('\n', stderr);
80 + }
81 + return -1;
82 }
83
84 static int checkout_all(void)
@@ -70,11 +87,11 @@ static int checkout_all(void)
87
88 for (i = 0; i < active_nr ; i++) {
89 struct cache_entry *ce = active_cache[i];
73 - if (ce_stage(ce))
90 + if (ce_stage(ce) != checkout_stage)
91 continue;
92 if (prefix && *prefix &&
76 - ( ce_namelen(ce) <= prefix_length ||
77 - memcmp(prefix, ce->name, prefix_length) ))
93 + (ce_namelen(ce) <= prefix_length ||
94 + memcmp(prefix, ce->name, prefix_length)))
95 continue;
96 if (checkout_entry(ce, &state) < 0)
97 errs++;
@@ -88,7 +105,7 @@ static int checkout_all(void)
105 }
106
107 static const char checkout_cache_usage[] =
91 -"git-checkout-index [-u] [-q] [-a] [-f] [-n] [--prefix=<string>] [--] <file>...";
108 +"git-checkout-index [-u] [-q] [-a] [-f] [-n] [--stage=[123]] [--prefix=<string>] [--] <file>...";
109
110 static struct cache_file cache_file;
111
@@ -138,11 +155,19 @@ int main(int argc, char **argv)
155 die("cannot open index.lock file.");
156 continue;
157 }
141 - if (!memcmp(arg, "--prefix=", 9)) {
158 + if (!strncmp(arg, "--prefix=", 9)) {
159 state.base_dir = arg+9;
160 state.base_dir_len = strlen(state.base_dir);
161 continue;
162 }
163 + if (!strncmp(arg, "--stage=", 8)) {
164 + int ch = arg[8];
165 + if ('1' <= ch && ch <= '3')
166 + checkout_stage = arg[8] - '0';
167 + else
168 + die("stage should be between 1 and 3");
169 + continue;
170 + }
171 if (arg[0] == '-')
172 usage(checkout_cache_usage);
173 break;