Merge branch 'doc-style/for-next' of git://repo.or.cz/git/trast
[gitweb.git] / builtin-ls-files.c
index c9a03e5427bbf1390aeefb9d48b4e362ca6a8e1b..b065061392718e4250d2c52dc3d53a0c1c7938e9 100644 (file)
@@ -11,6 +11,8 @@
 #include "builtin.h"
 #include "tree.h"
 #include "parse-options.h"
+#include "resolve-undo.h"
+#include "string-list.h"
 
 static int abbrev;
 static int show_deleted;
@@ -18,6 +20,7 @@ static int show_cached;
 static int show_others;
 static int show_stage;
 static int show_unmerged;
+static int show_resolve_undo;
 static int show_modified;
 static int show_killed;
 static int show_valid_bit;
@@ -37,6 +40,8 @@ static const char *tag_removed = "";
 static const char *tag_other = "";
 static const char *tag_killed = "";
 static const char *tag_modified = "";
+static const char *tag_skip_worktree = "";
+static const char *tag_resolve_undo = "";
 
 static void show_dir_entry(const char *tag, struct dir_entry *ent)
 {
@@ -155,6 +160,38 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
        write_name_quoted(ce->name + offset, stdout, line_terminator);
 }
 
+static int show_one_ru(struct string_list_item *item, void *cbdata)
+{
+       int offset = prefix_offset;
+       const char *path = item->string;
+       struct resolve_undo_info *ui = item->util;
+       int i, len;
+
+       len = strlen(path);
+       if (len < prefix_len)
+               return 0; /* outside of the prefix */
+       if (!match_pathspec(pathspec, path, len, prefix_len, ps_matched))
+               return 0; /* uninterested */
+       for (i = 0; i < 3; i++) {
+               if (!ui->mode[i])
+                       continue;
+               printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
+                      abbrev
+                      ? find_unique_abbrev(ui->sha1[i], abbrev)
+                      : sha1_to_hex(ui->sha1[i]),
+                      i + 1);
+               write_name_quoted(path + offset, stdout, line_terminator);
+       }
+       return 0;
+}
+
+static void show_ru_info(const char *prefix)
+{
+       if (!the_index.resolve_undo)
+               return;
+       for_each_string_list(show_one_ru, the_index.resolve_undo, NULL);
+}
+
 static void show_files(struct dir_struct *dir, const char *prefix)
 {
        int i;
@@ -178,7 +215,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
                                continue;
                        if (ce->ce_flags & CE_UPDATE)
                                continue;
-                       show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce);
+                       show_ce_entry(ce_stage(ce) ? tag_unmerged :
+                               (ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce);
                }
        }
        if (show_deleted | show_modified) {
@@ -192,6 +230,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
                                continue;
                        if (ce->ce_flags & CE_UPDATE)
                                continue;
+                       if (ce_skip_worktree(ce))
+                               continue;
                        err = lstat(ce->name, &st);
                        if (show_deleted && err)
                                show_ce_entry(tag_removed, ce);
@@ -454,6 +494,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
                        DIR_HIDE_EMPTY_DIRECTORIES),
                OPT_BOOLEAN('u', "unmerged", &show_unmerged,
                        "show unmerged files in the output"),
+               OPT_BOOLEAN(0, "resolve-undo", &show_resolve_undo,
+                           "show resolve-undo information"),
                { OPTION_CALLBACK, 'x', "exclude", &dir.exclude_list[EXC_CMDL], "pattern",
                        "skip files matching pattern",
                        0, option_parse_exclude },
@@ -481,6 +523,9 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
                prefix_offset = strlen(prefix);
        git_config(git_default_config, NULL);
 
+       if (read_cache() < 0)
+               die("index file corrupt");
+
        argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
                        ls_files_usage, 0);
        if (show_tag || show_valid_bit) {
@@ -490,6 +535,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
                tag_modified = "C ";
                tag_other = "? ";
                tag_killed = "K ";
+               tag_skip_worktree = "S ";
+               tag_resolve_undo = "U ";
        }
        if (show_modified || show_others || show_deleted || (dir.flags & DIR_SHOW_IGNORED) || show_killed)
                require_work_tree = 1;
@@ -508,7 +555,6 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
        pathspec = get_pathspec(prefix, argv);
 
        /* be nice with submodule paths ending in a slash */
-       read_cache();
        if (pathspec)
                strip_trailing_slash_from_submodules();
 
@@ -529,7 +575,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 
        /* With no flags, we default to showing the cached files */
        if (!(show_stage | show_deleted | show_others | show_unmerged |
-             show_killed | show_modified))
+             show_killed | show_modified | show_resolve_undo))
                show_cached = 1;
 
        if (prefix)
@@ -544,6 +590,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
                overlay_tree_on_cache(with_tree, prefix);
        }
        show_files(&dir, prefix);
+       if (show_resolve_undo)
+               show_ru_info(prefix);
 
        if (ps_matched) {
                int bad;