Skip to content

Commit 3e04228

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
Fix up some fallout from "setup_git_directory()" cleanups
git-ls-files was broken by the setup_git_directory() calling changes, because I had missed the fact that the "prefix" variable in that file was static to the whole file, and unlike git-ls-tree (where I had fixed it up), it ended up using two different variables with the same name depending on what the scoping happened to be. This fixes it up properly (by just removing the static variable, and passing the automatic one around properly), and git-ls-files should work again. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 7f8508e commit 3e04228

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

builtin-ls-files.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ static int show_valid_bit = 0;
2424
static int line_terminator = '\n';
2525

2626
static int prefix_len = 0, prefix_offset = 0;
27-
static const char *prefix = NULL;
2827
static const char **pathspec = NULL;
2928
static int error_unmatch = 0;
3029
static char *ps_matched = NULL;
@@ -207,7 +206,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
207206
}
208207
}
209208

210-
static void show_files(struct dir_struct *dir)
209+
static void show_files(struct dir_struct *dir, const char *prefix)
211210
{
212211
int i;
213212

@@ -253,7 +252,7 @@ static void show_files(struct dir_struct *dir)
253252
/*
254253
* Prune the index to only contain stuff starting with "prefix"
255254
*/
256-
static void prune_cache(void)
255+
static void prune_cache(const char *prefix)
257256
{
258257
int pos = cache_name_pos(prefix, prefix_len);
259258
unsigned int first, last;
@@ -276,7 +275,7 @@ static void prune_cache(void)
276275
active_nr = last;
277276
}
278277

279-
static void verify_pathspec(void)
278+
static const char *verify_pathspec(const char *prefix)
280279
{
281280
const char **p, *n, *prev;
282281
char *real_prefix;
@@ -313,7 +312,7 @@ static void verify_pathspec(void)
313312
memcpy(real_prefix, prev, max);
314313
real_prefix[max] = 0;
315314
}
316-
prefix = real_prefix;
315+
return real_prefix;
317316
}
318317

319318
static const char ls_files_usage[] =
@@ -453,7 +452,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
453452

454453
/* Verify that the pathspec matches the prefix */
455454
if (pathspec)
456-
verify_pathspec();
455+
prefix = verify_pathspec(prefix);
457456

458457
/* Treat unmatching pathspec elements as errors */
459458
if (pathspec && error_unmatch) {
@@ -476,8 +475,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
476475

477476
read_cache();
478477
if (prefix)
479-
prune_cache();
480-
show_files(&dir);
478+
prune_cache(prefix);
479+
show_files(&dir, prefix);
481480

482481
if (ps_matched) {
483482
/* We need to make sure all pathspec matched otherwise

0 commit comments

Comments
 (0)