Skip to content

Commit 2b2dabc

Browse files
author
Junio C Hamano
committed
Merge branch 'fixes'
2 parents 622ef9d + fd25c82 commit 2b2dabc

File tree

2 files changed

+68
-61
lines changed

2 files changed

+68
-61
lines changed

Documentation/git-checkout-index.txt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ OPTIONS
2929
forces overwrite of existing files
3030

3131
-a::
32-
checks out all files in the cache (will then continue to
33-
process listed files).
32+
checks out all files in the cache. Cannot be used
33+
together with explicit filenames.
3434

3535
-n::
3636
Don't checkout new files, only refresh files already checked
@@ -43,15 +43,9 @@ OPTIONS
4343
--::
4444
Do not interpret any more arguments as options.
4545

46-
Note that the order of the flags matters:
46+
The order of the flags used to matter, but not anymore.
4747

48-
git-checkout-index -a -f file.c
49-
50-
will first check out all files listed in the cache (but not overwrite
51-
any old ones), and then force-checkout `file.c` a second time (ie that
52-
one *will* overwrite any old contents with the same filename).
53-
54-
Also, just doing "git-checkout-index" does nothing. You probably meant
48+
Just doing "git-checkout-index" does nothing. You probably meant
5549
"git-checkout-index -a". And if you want to force it, you want
5650
"git-checkout-index -f -a".
5751

@@ -77,12 +71,12 @@ scripting!).
7771
The prefix ability basically makes it trivial to use
7872
git-checkout-index as an "export as tree" function. Just read the
7973
desired tree into the index, and do a
80-
74+
8175
git-checkout-index --prefix=git-export-dir/ -a
82-
76+
8377
and git-checkout-index will "export" the cache into the specified
8478
directory.
85-
79+
8680
NOTE The final "/" is important. The exported name is literally just
8781
prefixed with the specified string, so you can also do something like
8882

checkout-index.c

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -87,67 +87,80 @@ static struct cache_file cache_file;
8787

8888
int main(int argc, char **argv)
8989
{
90-
int i, force_filename = 0;
90+
int i;
9191
int newfd = -1;
92+
int all = 0;
9293

9394
if (read_cache() < 0) {
9495
die("invalid cache");
9596
}
9697

9798
for (i = 1; i < argc; i++) {
9899
const char *arg = argv[i];
99-
if (!force_filename) {
100-
if (!strcmp(arg, "-a")) {
101-
checkout_all();
102-
continue;
103-
}
104-
if (!strcmp(arg, "--")) {
105-
force_filename = 1;
106-
continue;
107-
}
108-
if (!strcmp(arg, "-f")) {
109-
state.force = 1;
110-
continue;
111-
}
112-
if (!strcmp(arg, "-q")) {
113-
state.quiet = 1;
114-
continue;
115-
}
116-
if (!strcmp(arg, "-n")) {
117-
state.not_new = 1;
118-
continue;
119-
}
120-
if (!strcmp(arg, "-u")) {
121-
state.refresh_cache = 1;
122-
if (newfd < 0)
123-
newfd = hold_index_file_for_update
124-
(&cache_file,
125-
get_index_file());
126-
if (newfd < 0)
127-
die("cannot open index.lock file.");
128-
continue;
129-
}
130-
if (!memcmp(arg, "--prefix=", 9)) {
131-
state.base_dir = arg+9;
132-
state.base_dir_len = strlen(state.base_dir);
133-
continue;
134-
}
135-
if (arg[0] == '-')
136-
usage(checkout_cache_usage);
100+
101+
if (!strcmp(arg, "--")) {
102+
i++;
103+
break;
104+
}
105+
if (!strcmp(arg, "-a") || !strcmp(arg, "--all")) {
106+
all = 1;
107+
continue;
137108
}
138-
if (state.base_dir_len) {
139-
/* when --prefix is specified we do not
140-
* want to update cache.
141-
*/
142-
if (state.refresh_cache) {
143-
close(newfd); newfd = -1;
144-
rollback_index_file(&cache_file);
145-
}
146-
state.refresh_cache = 0;
109+
if (!strcmp(arg, "-f") || !strcmp(arg, "--force")) {
110+
state.force = 1;
111+
continue;
112+
}
113+
if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet")) {
114+
state.quiet = 1;
115+
continue;
147116
}
117+
if (!strcmp(arg, "-n") || !strcmp(arg, "--no-create")) {
118+
state.not_new = 1;
119+
continue;
120+
}
121+
if (!strcmp(arg, "-u") || !strcmp(arg, "--index")) {
122+
state.refresh_cache = 1;
123+
if (newfd < 0)
124+
newfd = hold_index_file_for_update
125+
(&cache_file,
126+
get_index_file());
127+
if (newfd < 0)
128+
die("cannot open index.lock file.");
129+
continue;
130+
}
131+
if (!memcmp(arg, "--prefix=", 9)) {
132+
state.base_dir = arg+9;
133+
state.base_dir_len = strlen(state.base_dir);
134+
continue;
135+
}
136+
if (arg[0] == '-')
137+
usage(checkout_cache_usage);
138+
break;
139+
}
140+
141+
if (state.base_dir_len) {
142+
/* when --prefix is specified we do not
143+
* want to update cache.
144+
*/
145+
if (state.refresh_cache) {
146+
close(newfd); newfd = -1;
147+
rollback_index_file(&cache_file);
148+
}
149+
state.refresh_cache = 0;
150+
}
151+
152+
/* Check out named files first */
153+
for ( ; i < argc; i++) {
154+
const char *arg = argv[i];
155+
156+
if (all)
157+
die("git-checkout-index: don't mix '--all' and explicit filenames");
148158
checkout_file(arg);
149159
}
150160

161+
if (all)
162+
checkout_all();
163+
151164
if (0 <= newfd &&
152165
(write_cache(newfd, active_cache, active_nr) ||
153166
commit_index_file(&cache_file)))

0 commit comments

Comments
 (0)