- if (prefix) {
- if (prefix->prev)
- print_path_prefix(prefix->prev);
- fputs(prefix->name, stdout);
- putchar('/');
- }
-}
-
-static void list_recursive(void *buffer,
- const unsigned char *type,
- unsigned long size,
- struct path_prefix *prefix)
-{
- struct path_prefix this_prefix;
- this_prefix.prev = prefix;
-
- if (strcmp(type, "tree"))
- die("expected a 'tree' node");
-
- while (size) {
- int namelen = strlen(buffer)+1;
- void *eltbuf;
- char elttype[20];
- unsigned long eltsize;
- unsigned char *sha1 = buffer + namelen;
- char *path = strchr(buffer, ' ') + 1;
- unsigned int mode;
-
- if (size < namelen + 20 || sscanf(buffer, "%o", &mode) != 1)
- die("corrupt 'tree' file");
- buffer = sha1 + 20;
- size -= namelen + 20;
-
- printf("%06o\t%s\t%s\t", mode,
- S_ISDIR(mode) ? "tree" : "blob",
- sha1_to_hex(sha1));
- print_path_prefix(prefix);
- fputs(path, stdout);
- putchar(line_termination);
-
- if (! recursive || ! S_ISDIR(mode))
- continue;
-
- if (! (eltbuf = read_sha1_file(sha1, elttype, &eltsize)) ) {
- error("cannot read %s", sha1_to_hex(sha1));
- continue;
+ const char *type = "blob";
+
+ if (S_ISDIR(mode)) {
+ const char **s;
+ if (ls_options & LS_RECURSIVE)
+ return READ_TREE_RECURSIVE;
+ s = pathspec;
+ if (s) {
+ for (;;) {
+ const char *spec = *s++;
+ int len, speclen;
+
+ if (!spec)
+ break;
+ if (strncmp(base, spec, baselen))
+ continue;
+ len = strlen(pathname);
+ spec += baselen;
+ speclen = strlen(spec);
+ if (speclen <= len)
+ continue;
+ if (memcmp(pathname, spec, len))
+ continue;
+ return READ_TREE_RECURSIVE;
+ }