@@ -87,67 +87,80 @@ static struct cache_file cache_file;
8787
8888int 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