i18n: unpack-trees: avoid substituting only a verb in sentences
[gitweb.git] / builtin / ls-tree.c
index de88563edfdae562321bad7a91e8c5fe286e8922..0e30d862303b67ace2c7accf2e7c9346d8f63264 100644 (file)
@@ -10,6 +10,7 @@
 #include "quote.h"
 #include "builtin.h"
 #include "parse-options.h"
+#include "pathspec.h"
 
 static int line_termination = '\n';
 #define LS_RECURSIVE 1
@@ -35,7 +36,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
        if (ls_options & LS_RECURSIVE)
                return 1;
 
-       s = pathspec.raw;
+       s = pathspec._raw;
        if (!s)
                return 0;
 
@@ -60,10 +61,11 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
        }
 }
 
-static int show_tree(const unsigned char *sha1, const char *base, int baselen,
+static int show_tree(const unsigned char *sha1, struct strbuf *base,
                const char *pathname, unsigned mode, int stage, void *context)
 {
        int retval = 0;
+       int baselen;
        const char *type = blob_type;
 
        if (S_ISGITLINK(mode)) {
@@ -78,7 +80,7 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
                 */
                type = commit_type;
        } else if (S_ISDIR(mode)) {
-               if (show_recursive(base, baselen, pathname)) {
+               if (show_recursive(base->buf, base->len, pathname)) {
                        retval = READ_TREE_RECURSIVE;
                        if (!(ls_options & LS_SHOW_TREES))
                                return retval;
@@ -88,22 +90,19 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
        else if (ls_options & LS_TREE_ONLY)
                return 0;
 
-       if (chomp_prefix &&
-           (baselen < chomp_prefix || memcmp(ls_tree_prefix, base, chomp_prefix)))
-               return 0;
-
        if (!(ls_options & LS_NAME_ONLY)) {
                if (ls_options & LS_SHOW_SIZE) {
                        char size_text[24];
                        if (!strcmp(type, blob_type)) {
                                unsigned long size;
                                if (sha1_object_info(sha1, &size) == OBJ_BAD)
-                                       strcpy(size_text, "BAD");
+                                       xsnprintf(size_text, sizeof(size_text),
+                                                 "BAD");
                                else
-                                       snprintf(size_text, sizeof(size_text),
-                                                "%lu", size);
+                                       xsnprintf(size_text, sizeof(size_text),
+                                                 "%lu", size);
                        } else
-                               strcpy(size_text, "-");
+                               xsnprintf(size_text, sizeof(size_text), "-");
                        printf("%06o %s %s %7s\t", mode, type,
                               find_unique_abbrev(sha1, abbrev),
                               size_text);
@@ -111,8 +110,12 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
                        printf("%06o %s %s\t", mode, type,
                               find_unique_abbrev(sha1, abbrev));
        }
-       write_name_quotedpfx(base + chomp_prefix, baselen - chomp_prefix,
-                         pathname, stdout, line_termination);
+       baselen = base->len;
+       strbuf_addstr(base, pathname);
+       write_name_quoted_relative(base->buf,
+                                  chomp_prefix ? ls_tree_prefix : NULL,
+                                  stdout, line_termination);
+       strbuf_setlen(base, baselen);
        return retval;
 }
 
@@ -166,7 +169,16 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
        if (get_sha1(argv[0], sha1))
                die("Not a valid object name %s", argv[0]);
 
-       init_pathspec(&pathspec, get_pathspec(prefix, argv + 1));
+       /*
+        * show_recursive() rolls its own matching code and is
+        * generally ignorant of 'struct pathspec'. The magic mask
+        * cannot be lifted until it is converted to use
+        * match_pathspec() or tree_entry_interesting()
+        */
+       parse_pathspec(&pathspec, PATHSPEC_GLOB | PATHSPEC_ICASE |
+                                 PATHSPEC_EXCLUDE,
+                      PATHSPEC_PREFER_CWD,
+                      prefix, argv + 1);
        for (i = 0; i < pathspec.nr; i++)
                pathspec.items[i].nowildcard_len = pathspec.items[i].len;
        pathspec.has_wildcard = 0;