@matheusbsbs / matheus-bagliano / commits / a65a686f49
Fork 0

make checkout-index '-a' flag saner.

The original semantics of pretending as if all files were specified where '-a' appeared and using only the flags given so far was too confusing. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Oct 17, 2005 at 17:32 UTC a65a686f4967ecba0759289d0e918f652980e8a2
1 file changed +61 -48
checkout-index.c
+61 -48
@@ -82,8 +82,9 @@ static struct cache_file cache_file;
82
83 int main(int argc, char **argv)
84 {
85 - int i, force_filename = 0;
85 + int i;
86 int newfd = -1;
87 + int all = 0;
88
89 if (read_cache() < 0) {
90 die("invalid cache");
@@ -91,58 +92,70 @@ int main(int argc, char **argv)
92
93 for (i = 1; i < argc; i++) {
94 const char *arg = argv[i];
94 - if (!force_filename) {
95 - if (!strcmp(arg, "-a")) {
96 - checkout_all();
97 - continue;
98 - }
99 - if (!strcmp(arg, "--")) {
100 - force_filename = 1;
101 - continue;
102 - }
103 - if (!strcmp(arg, "-f")) {
104 - state.force = 1;
105 - continue;
106 - }
107 - if (!strcmp(arg, "-q")) {
108 - state.quiet = 1;
109 - continue;
110 - }
111 - if (!strcmp(arg, "-n")) {
112 - state.not_new = 1;
113 - continue;
114 - }
115 - if (!strcmp(arg, "-u")) {
116 - state.refresh_cache = 1;
117 - if (newfd < 0)
118 - newfd = hold_index_file_for_update
119 - (&cache_file,
120 - get_index_file());
121 - if (newfd < 0)
122 - die("cannot open index.lock file.");
123 - continue;
124 - }
125 - if (!memcmp(arg, "--prefix=", 9)) {
126 - state.base_dir = arg+9;
127 - state.base_dir_len = strlen(state.base_dir);
128 - continue;
129 - }
130 - if (arg[0] == '-')
131 - usage(checkout_cache_usage);
95 +
96 + if (!strcmp(arg, "--")) {
97 + i++;
98 + break;
99 + }
100 + if (!strcmp(arg, "-a") || !strcmp(arg, "--all")) {
101 + all = 1;
102 + continue;
103 + }
104 + if (!strcmp(arg, "-f") || !strcmp(arg, "--force")) {
105 + state.force = 1;
106 + continue;
107 }
133 - if (state.base_dir_len) {
134 - /* when --prefix is specified we do not
135 - * want to update cache.
136 - */
137 - if (state.refresh_cache) {
138 - close(newfd); newfd = -1;
139 - rollback_index_file(&cache_file);
140 - }
141 - state.refresh_cache = 0;
108 + if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet")) {
109 + state.quiet = 1;
110 + continue;
111 + }
112 + if (!strcmp(arg, "-n") || !strcmp(arg, "--no-create")) {
113 + state.not_new = 1;
114 + continue;
115 + }
116 + if (!strcmp(arg, "-u") || !strcmp(arg, "--index")) {
117 + state.refresh_cache = 1;
118 + if (newfd < 0)
119 + newfd = hold_index_file_for_update
120 + (&cache_file,
121 + get_index_file());
122 + if (newfd < 0)
123 + die("cannot open index.lock file.");
124 + continue;
125 }
126 + if (!memcmp(arg, "--prefix=", 9)) {
127 + state.base_dir = arg+9;
128 + state.base_dir_len = strlen(state.base_dir);
129 + continue;
130 + }
131 + if (arg[0] == '-')
132 + usage(checkout_cache_usage);
133 + break;
134 + }
135 +
136 + if (state.base_dir_len) {
137 + /* when --prefix is specified we do not
138 + * want to update cache.
139 + */
140 + if (state.refresh_cache) {
141 + close(newfd); newfd = -1;
142 + rollback_index_file(&cache_file);
143 + }
144 + state.refresh_cache = 0;
145 + }
146 +
147 + /* Check out named files first */
148 + for ( ; i < argc; i++) {
149 + const char *arg = argv[i];
150 +
151 + if (all)
152 + die("git-checkout-index: don't mix '--all' and explicit filenames");
153 checkout_file(arg);
154 }
155
156 + if (all)
157 + checkout_all();
158 +
159 if (0 <= newfd &&
160 (write_cache(newfd, active_cache, active_nr) ||
161 commit_index_file(&cache_file)))