summaryrefslogtreecommitdiff
path: root/builtin-ls-files.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin-ls-files.c')
-rw-r--r--builtin-ls-files.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 8dae9f70e2..11386c432b 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -24,7 +24,6 @@ static int show_valid_bit = 0;
static int line_terminator = '\n';
static int prefix_len = 0, prefix_offset = 0;
-static const char *prefix = NULL;
static const char **pathspec = NULL;
static int error_unmatch = 0;
static char *ps_matched = NULL;
@@ -207,7 +206,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
}
}
-static void show_files(struct dir_struct *dir)
+static void show_files(struct dir_struct *dir, const char *prefix)
{
int i;
@@ -253,7 +252,7 @@ static void show_files(struct dir_struct *dir)
/*
* Prune the index to only contain stuff starting with "prefix"
*/
-static void prune_cache(void)
+static void prune_cache(const char *prefix)
{
int pos = cache_name_pos(prefix, prefix_len);
unsigned int first, last;
@@ -276,7 +275,7 @@ static void prune_cache(void)
active_nr = last;
}
-static void verify_pathspec(void)
+static const char *verify_pathspec(const char *prefix)
{
const char **p, *n, *prev;
char *real_prefix;
@@ -313,7 +312,7 @@ static void verify_pathspec(void)
memcpy(real_prefix, prev, max);
real_prefix[max] = 0;
}
- prefix = real_prefix;
+ return real_prefix;
}
static const char ls_files_usage[] =
@@ -322,14 +321,13 @@ static const char ls_files_usage[] =
"[ --exclude-per-directory=<filename> ] [--full-name] [--abbrev] "
"[--] [<file>]*";
-int cmd_ls_files(int argc, const char **argv, char** envp)
+int cmd_ls_files(int argc, const char **argv, const char *prefix)
{
int i;
int exc_given = 0;
struct dir_struct dir;
memset(&dir, 0, sizeof(dir));
- prefix = setup_git_directory();
if (prefix)
prefix_offset = strlen(prefix);
git_config(git_default_config);
@@ -454,7 +452,7 @@ int cmd_ls_files(int argc, const char **argv, char** envp)
/* Verify that the pathspec matches the prefix */
if (pathspec)
- verify_pathspec();
+ prefix = verify_pathspec(prefix);
/* Treat unmatching pathspec elements as errors */
if (pathspec && error_unmatch) {
@@ -477,8 +475,8 @@ int cmd_ls_files(int argc, const char **argv, char** envp)
read_cache();
if (prefix)
- prune_cache();
- show_files(&dir);
+ prune_cache(prefix);
+ show_files(&dir, prefix);
if (ps_matched) {
/* We need to make sure all pathspec matched otherwise