Ignore:
Timestamp:
Jun 23, 2014, 9:45:51 PM (11 years ago)
Author:
dmik
Message:

git: Merge version 2.0.0 from vendor to dmik branch.

Location:
git/branches/dmik
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • git/branches/dmik

  • TabularUnified git/branches/dmik/builtin/ls-files.c

    r626 r782  
    1414#include "resolve-undo.h"
    1515#include "string-list.h"
     16#include "pathspec.h"
    1617
    1718static int abbrev;
     
    3132static int max_prefix_len;
    3233static int prefix_len;
    33 static const char **pathspec;
     34static struct pathspec pathspec;
    3435static int error_unmatch;
    3536static char *ps_matched;
    3637static const char *with_tree;
    3738static int exc_given;
     39static int exclude_args;
    3840
    3941static const char *tag_cached = "";
     
    4648static const char *tag_resolve_undo = "";
    4749
    48 static void write_name(const char* name, size_t len)
    49 {
    50         write_name_quoted_relative(name, len, prefix, prefix_len, stdout,
    51                         line_terminator);
     50static void write_name(const char *name)
     51{
     52        /*
     53         * With "--full-name", prefix_len=0; this caller needs to pass
     54         * an empty string in that case (a NULL is good for "").
     55         */
     56        write_name_quoted_relative(name, prefix_len ? prefix : NULL,
     57                                   stdout, line_terminator);
    5258}
    5359
     
    5965                die("git ls-files: internal error - directory entry not superset of prefix");
    6066
    61         if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))
     67        if (!dir_path_match(ent, &pathspec, len, ps_matched))
    6268                return;
    6369
    6470        fputs(tag, stdout);
    65         write_name(ent->name, ent->len);
     71        write_name(ent->name);
    6672}
    6773
     
    127133}
    128134
    129 static void show_ce_entry(const char *tag, struct cache_entry *ce)
     135static void show_ce_entry(const char *tag, const struct cache_entry *ce)
    130136{
    131137        int len = max_prefix_len;
     
    134140                die("git ls-files: internal error - cache entry not superset of prefix");
    135141
    136         if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched))
     142        if (!match_pathspec(&pathspec, ce->name, ce_namelen(ce),
     143                            len, ps_matched,
     144                            S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)))
    137145                return;
    138146
     
    163171                       ce_stage(ce));
    164172        }
    165         write_name(ce->name, ce_namelen(ce));
     173        write_name(ce->name);
    166174        if (debug_mode) {
    167                 printf("  ctime: %d:%d\n", ce->ce_ctime.sec, ce->ce_ctime.nsec);
    168                 printf("  mtime: %d:%d\n", ce->ce_mtime.sec, ce->ce_mtime.nsec);
    169                 printf("  dev: %d\tino: %d\n", ce->ce_dev, ce->ce_ino);
    170                 printf("  uid: %d\tgid: %d\n", ce->ce_uid, ce->ce_gid);
    171                 printf("  size: %d\tflags: %x\n", ce->ce_size, ce->ce_flags);
     175                const struct stat_data *sd = &ce->ce_stat_data;
     176
     177                printf("  ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
     178                printf("  mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
     179                printf("  dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino);
     180                printf("  uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid);
     181                printf("  size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags);
    172182        }
    173183}
     
    188198                if (len < max_prefix_len)
    189199                        continue; /* outside of the prefix */
    190                 if (!match_pathspec(pathspec, path, len, max_prefix_len, ps_matched))
     200                if (!match_pathspec(&pathspec, path, len,
     201                                    max_prefix_len, ps_matched, 0))
    191202                        continue; /* uninterested */
    192203                for (i = 0; i < 3; i++) {
     
    196207                               find_unique_abbrev(ui->sha1[i], abbrev),
    197208                               i + 1);
    198                         write_name(path, len);
    199                 }
    200         }
     209                        write_name(path);
     210                }
     211        }
     212}
     213
     214static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce)
     215{
     216        int dtype = ce_to_dtype(ce);
     217        return is_excluded(dir, ce->name, &dtype);
    201218}
    202219
     
    207224        /* For cached/deleted files we don't need to even do the readdir */
    208225        if (show_others || show_killed) {
    209                 fill_directory(dir, pathspec);
     226                if (!show_others)
     227                        dir->flags |= DIR_COLLECT_KILLED_ONLY;
     228                fill_directory(dir, &pathspec);
    210229                if (show_others)
    211230                        show_other_files(dir);
     
    213232                        show_killed_files(dir);
    214233        }
    215         if (show_cached | show_stage) {
     234        if (show_cached || show_stage) {
    216235                for (i = 0; i < active_nr; i++) {
    217                         struct cache_entry *ce = active_cache[i];
    218                         int dtype = ce_to_dtype(ce);
    219                         if (dir->flags & DIR_SHOW_IGNORED &&
    220                             !excluded(dir, ce->name, &dtype))
     236                        const struct cache_entry *ce = active_cache[i];
     237                        if ((dir->flags & DIR_SHOW_IGNORED) &&
     238                            !ce_excluded(dir, ce))
    221239                                continue;
    222240                        if (show_unmerged && !ce_stage(ce))
     
    228246                }
    229247        }
    230         if (show_deleted | show_modified) {
     248        if (show_deleted || show_modified) {
    231249                for (i = 0; i < active_nr; i++) {
    232                         struct cache_entry *ce = active_cache[i];
     250                        const struct cache_entry *ce = active_cache[i];
    233251                        struct stat st;
    234252                        int err;
    235                         int dtype = ce_to_dtype(ce);
    236                         if (dir->flags & DIR_SHOW_IGNORED &&
    237                             !excluded(dir, ce->name, &dtype))
     253                        if ((dir->flags & DIR_SHOW_IGNORED) &&
     254                            !ce_excluded(dir, ce))
    238255                                continue;
    239256                        if (ce->ce_flags & CE_UPDATE)
     
    267284        while (last > first) {
    268285                int next = (last + first) >> 1;
    269                 struct cache_entry *ce = active_cache[next];
     286                const struct cache_entry *ce = active_cache[next];
    270287                if (!strncmp(ce->name, prefix, max_prefix_len)) {
    271288                        first = next+1;
     
    275292        }
    276293        active_nr = last;
    277 }
    278 
    279 static void strip_trailing_slash_from_submodules(void)
    280 {
    281         const char **p;
    282 
    283         for (p = pathspec; *p != NULL; p++) {
    284                 int len = strlen(*p), pos;
    285 
    286                 if (len < 1 || (*p)[len - 1] != '/')
    287                         continue;
    288                 pos = cache_name_pos(*p, len - 1);
    289                 if (pos >= 0 && S_ISGITLINK(active_cache[pos]->ce_mode))
    290                         *p = xstrndup(*p, len - 1);
    291         }
    292294}
    293295
     
    323325
    324326        if (prefix) {
    325                 static const char *(matchbuf[2]);
    326                 matchbuf[0] = prefix;
    327                 matchbuf[1] = NULL;
    328                 init_pathspec(&pathspec, matchbuf);
    329                 pathspec.items[0].use_wildcard = 0;
     327                static const char *(matchbuf[1]);
     328                matchbuf[0] = NULL;
     329                parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
     330                               PATHSPEC_PREFER_CWD, prefix, matchbuf);
    330331        } else
    331                 init_pathspec(&pathspec, NULL);
     332                memset(&pathspec, 0, sizeof(pathspec));
    332333        if (read_tree(tree, 1, &pathspec))
    333334                die("unable to read tree entries %s", tree_name);
     
    354355}
    355356
    356 int report_path_error(const char *ps_matched, const char **pathspec, const char *prefix)
     357int report_path_error(const char *ps_matched,
     358                      const struct pathspec *pathspec,
     359                      const char *prefix)
    357360{
    358361        /*
     
    360363         */
    361364        struct strbuf sb = STRBUF_INIT;
    362         const char *name;
    363365        int num, errors = 0;
    364         for (num = 0; pathspec[num]; num++) {
     366        for (num = 0; num < pathspec->nr; num++) {
    365367                int other, found_dup;
    366368
     
    370372                 * The caller might have fed identical pathspec
    371373                 * twice.  Do not barf on such a mistake.
     374                 * FIXME: parse_pathspec should have eliminated
     375                 * duplicate pathspec.
    372376                 */
    373377                for (found_dup = other = 0;
    374                      !found_dup && pathspec[other];
     378                     !found_dup && other < pathspec->nr;
    375379                     other++) {
    376380                        if (other == num || !ps_matched[other])
    377381                                continue;
    378                         if (!strcmp(pathspec[other], pathspec[num]))
     382                        if (!strcmp(pathspec->items[other].original,
     383                                    pathspec->items[num].original))
    379384                                /*
    380385                                 * Ok, we have a match already.
     
    385390                        continue;
    386391
    387                 name = quote_path_relative(pathspec[num], -1, &sb, prefix);
    388392                error("pathspec '%s' did not match any file(s) known to git.",
    389                       name);
     393                      pathspec->items[num].original);
    390394                errors++;
    391395        }
     
    395399
    396400static const char * const ls_files_usage[] = {
    397         "git ls-files [options] [<file>...]",
     401        N_("git ls-files [options] [<file>...]"),
    398402        NULL
    399403};
     
    410414                                const char *arg, int unset)
    411415{
    412         struct exclude_list *list = opt->value;
     416        struct string_list *exclude_list = opt->value;
    413417
    414418        exc_given = 1;
    415         add_exclude(arg, "", 0, list);
     419        string_list_append(exclude_list, arg);
    416420
    417421        return 0;
     
    442446int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
    443447{
    444         int require_work_tree = 0, show_tag = 0;
     448        int require_work_tree = 0, show_tag = 0, i;
    445449        const char *max_prefix;
    446450        struct dir_struct dir;
     451        struct exclude_list *el;
     452        struct string_list exclude_list = STRING_LIST_INIT_NODUP;
    447453        struct option builtin_ls_files_options[] = {
    448454                { OPTION_CALLBACK, 'z', NULL, NULL, NULL,
    449                         "paths are separated with NUL character",
     455                        N_("paths are separated with NUL character"),
    450456                        PARSE_OPT_NOARG, option_parse_z },
    451                 OPT_BOOLEAN('t', NULL, &show_tag,
    452                         "identify the file status with tags"),
    453                 OPT_BOOLEAN('v', NULL, &show_valid_bit,
    454                         "use lowercase letters for 'assume unchanged' files"),
    455                 OPT_BOOLEAN('c', "cached", &show_cached,
    456                         "show cached files in the output (default)"),
    457                 OPT_BOOLEAN('d', "deleted", &show_deleted,
    458                         "show deleted files in the output"),
    459                 OPT_BOOLEAN('m', "modified", &show_modified,
    460                         "show modified files in the output"),
    461                 OPT_BOOLEAN('o', "others", &show_others,
    462                         "show other files in the output"),
     457                OPT_BOOL('t', NULL, &show_tag,
     458                        N_("identify the file status with tags")),
     459                OPT_BOOL('v', NULL, &show_valid_bit,
     460                        N_("use lowercase letters for 'assume unchanged' files")),
     461                OPT_BOOL('c', "cached", &show_cached,
     462                        N_("show cached files in the output (default)")),
     463                OPT_BOOL('d', "deleted", &show_deleted,
     464                        N_("show deleted files in the output")),
     465                OPT_BOOL('m', "modified", &show_modified,
     466                        N_("show modified files in the output")),
     467                OPT_BOOL('o', "others", &show_others,
     468                        N_("show other files in the output")),
    463469                OPT_BIT('i', "ignored", &dir.flags,
    464                         "show ignored files in the output",
     470                        N_("show ignored files in the output"),
    465471                        DIR_SHOW_IGNORED),
    466                 OPT_BOOLEAN('s', "stage", &show_stage,
    467                         "show staged contents' object name in the output"),
    468                 OPT_BOOLEAN('k', "killed", &show_killed,
    469                         "show files on the filesystem that need to be removed"),
     472                OPT_BOOL('s', "stage", &show_stage,
     473                        N_("show staged contents' object name in the output")),
     474                OPT_BOOL('k', "killed", &show_killed,
     475                        N_("show files on the filesystem that need to be removed")),
    470476                OPT_BIT(0, "directory", &dir.flags,
    471                         "show 'other' directories' name only",
     477                        N_("show 'other' directories' name only"),
    472478                        DIR_SHOW_OTHER_DIRECTORIES),
    473479                OPT_NEGBIT(0, "empty-directory", &dir.flags,
    474                         "don't show empty directories",
     480                        N_("don't show empty directories"),
    475481                        DIR_HIDE_EMPTY_DIRECTORIES),
    476                 OPT_BOOLEAN('u', "unmerged", &show_unmerged,
    477                         "show unmerged files in the output"),
    478                 OPT_BOOLEAN(0, "resolve-undo", &show_resolve_undo,
    479                             "show resolve-undo information"),
    480                 { OPTION_CALLBACK, 'x', "exclude", &dir.exclude_list[EXC_CMDL], "pattern",
    481                         "skip files matching pattern",
     482                OPT_BOOL('u', "unmerged", &show_unmerged,
     483                        N_("show unmerged files in the output")),
     484                OPT_BOOL(0, "resolve-undo", &show_resolve_undo,
     485                            N_("show resolve-undo information")),
     486                { OPTION_CALLBACK, 'x', "exclude", &exclude_list, N_("pattern"),
     487                        N_("skip files matching pattern"),
    482488                        0, option_parse_exclude },
    483                 { OPTION_CALLBACK, 'X', "exclude-from", &dir, "file",
    484                         "exclude patterns are read from <file>",
     489                { OPTION_CALLBACK, 'X', "exclude-from", &dir, N_("file"),
     490                        N_("exclude patterns are read from <file>"),
    485491                        0, option_parse_exclude_from },
    486                 OPT_STRING(0, "exclude-per-directory", &dir.exclude_per_dir, "file",
    487                         "read additional per-directory exclude patterns in <file>"),
     492                OPT_STRING(0, "exclude-per-directory", &dir.exclude_per_dir, N_("file"),
     493                        N_("read additional per-directory exclude patterns in <file>")),
    488494                { OPTION_CALLBACK, 0, "exclude-standard", &dir, NULL,
    489                         "add the standard git exclusions",
     495                        N_("add the standard git exclusions"),
    490496                        PARSE_OPT_NOARG, option_parse_exclude_standard },
    491497                { OPTION_SET_INT, 0, "full-name", &prefix_len, NULL,
    492                         "make the output relative to the project top directory",
     498                        N_("make the output relative to the project top directory"),
    493499                        PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL },
    494                 OPT_BOOLEAN(0, "error-unmatch", &error_unmatch,
    495                         "if any <file> is not in the index, treat this as an error"),
    496                 OPT_STRING(0, "with-tree", &with_tree, "tree-ish",
    497                         "pretend that paths removed since <tree-ish> are still present"),
     500                OPT_BOOL(0, "error-unmatch", &error_unmatch,
     501                        N_("if any <file> is not in the index, treat this as an error")),
     502                OPT_STRING(0, "with-tree", &with_tree, N_("tree-ish"),
     503                        N_("pretend that paths removed since <tree-ish> are still present")),
    498504                OPT__ABBREV(&abbrev),
    499                 OPT_BOOLEAN(0, "debug", &debug_mode, "show debugging data"),
     505                OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
    500506                OPT_END()
    501507        };
     
    515521        argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
    516522                        ls_files_usage, 0);
     523        el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
     524        for (i = 0; i < exclude_list.nr; i++) {
     525                add_exclude(exclude_list.items[i].string, "", 0, el, --exclude_args);
     526        }
    517527        if (show_tag || show_valid_bit) {
    518528                tag_cached = "H ";
     
    539549                setup_work_tree();
    540550
    541         pathspec = get_pathspec(prefix, argv);
    542 
    543         /* be nice with submodule paths ending in a slash */
    544         if (pathspec)
    545                 strip_trailing_slash_from_submodules();
     551        parse_pathspec(&pathspec, 0,
     552                       PATHSPEC_PREFER_CWD |
     553                       PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
     554                       prefix, argv);
    546555
    547556        /* Find common prefix for all pathspec's */
    548         max_prefix = common_prefix(pathspec);
     557        max_prefix = common_prefix(&pathspec);
    549558        max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
    550559
    551560        /* Treat unmatching pathspec elements as errors */
    552         if (pathspec && error_unmatch) {
    553                 int num;
    554                 for (num = 0; pathspec[num]; num++)
    555                         ;
    556                 ps_matched = xcalloc(1, num);
    557         }
     561        if (pathspec.nr && error_unmatch)
     562                ps_matched = xcalloc(1, pathspec.nr);
    558563
    559564        if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given)
     
    561566
    562567        /* With no flags, we default to showing the cached files */
    563         if (!(show_stage | show_deleted | show_others | show_unmerged |
    564               show_killed | show_modified | show_resolve_undo))
     568        if (!(show_stage || show_deleted || show_others || show_unmerged ||
     569              show_killed || show_modified || show_resolve_undo))
    565570                show_cached = 1;
    566571
     
    582587        if (ps_matched) {
    583588                int bad;
    584                 bad = report_path_error(ps_matched, pathspec, prefix);
     589                bad = report_path_error(ps_matched, &pathspec, prefix);
    585590                if (bad)
    586591                        fprintf(stderr, "Did you forget to 'git add'?\n");
Note: See TracChangeset for help on using the changeset viewer.