{"thread":{"id":"54932","subject":"[PATCH v1 1/1] builtin/ls-files.c:add git ls-file --dedup option","startedAt":"2021-01-05T05:39:51Z","lastAt":"2021-01-05T05:40:16Z","messageCount":2,"participants":["ZheNing Hu"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"413432","messageId":"20210105053946.710743-1-adlternative@gmail.com","threadId":"54932","inReplyTo":null,"subject":"[PATCH v1 1/1] builtin/ls-files.c:add git ls-file --dedup option","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2021-01-05T05:39:45Z","receivedAt":"2021-01-05T05:39:51Z","isPatch":true,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"1.When we use git ls-files with both -m -d,\nwe would find that repeated path,sometimes\nit is confusing.\n2.When we are performing a branch merge,\n the default git ls-files will also output\n multiple repeated file names.\nTherefore, I added the --dedup option to git ls-files.\n1. It can be achieved that only the deleted file name\nis displayed when using -m, -d, and --dedup at the same time.\n2. Add --dedup when merging branches to remove duplicate file\n names. (unless -s, -u are used)\n\nSigned-off-by: ZheNing Hu <adlternative@gmail.com>\n---\n builtin/ls-files.c | 43 ++++++++++++++++++++++++++++++++++++++-----\n 1 file changed, 38 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex c8eae899b8..66a7e251a4 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -35,6 +35,7 @@ static int line_terminator = '\\n';\n static int debug_mode;\n static int show_eol;\n static int recurse_submodules;\n+static int delete_dup;\n \n static const char *prefix;\n static int max_prefix_len;\n@@ -301,6 +302,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)\n {\n \tint i;\n \tstruct strbuf fullname = STRBUF_INIT;\n+\tconst struct cache_entry *last_stage=NULL;\n \n \t/* For cached/deleted files we don't need to even do the readdir */\n \tif (show_others || show_killed) {\n@@ -315,7 +317,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)\n \tif (show_cached || show_stage) {\n \t\tfor (i = 0; i < repo->index->cache_nr; i++) {\n \t\t\tconst struct cache_entry *ce = repo->index->cache[i];\n-\n+\t\t\tif(show_cached && delete_dup){\n+\t\t\t\tswitch (ce_stage(ce)) {\n+\t\t\t\tcase 0:\n+\t\t\t\tdefault:\n+\t\t\t\t\tbreak;\n+\t\t\t\tcase 1:\n+\t\t\t\tcase 2:\n+\t\t\t\tcase 3:\n+\t\t\t\t\tif (last_stage &&\n+\t\t\t\t\t!strcmp(last_stage->name, ce->name))\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\tlast_stage=ce;\n+\t\t\t\t}\n+\t\t\t}\n \t\t\tconstruct_fullname(&fullname, repo, ce);\n \n \t\t\tif ((dir->flags & DIR_SHOW_IGNORED) &&\n@@ -336,7 +351,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)\n \t\t\tconst struct cache_entry *ce = repo->index->cache[i];\n \t\t\tstruct stat st;\n \t\t\tint err;\n-\n+\t\t\tif(delete_dup){\n+\t\t\t\tswitch (ce_stage(ce)) {\n+\t\t\t\tcase 0:\n+\t\t\t\tdefault:\n+\t\t\t\t\tbreak;\n+\t\t\t\tcase 1:\n+\t\t\t\tcase 2:\n+\t\t\t\tcase 3:\n+\t\t\t\t\tif (last_stage &&\n+\t\t\t\t\t!strcmp(last_stage->name, ce->name))\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\tlast_stage=ce;\n+\t\t\t\t}\n+\t\t\t}\n \t\t\tconstruct_fullname(&fullname, repo, ce);\n \n \t\t\tif ((dir->flags & DIR_SHOW_IGNORED) &&\n@@ -347,10 +375,14 @@ static void show_files(struct repository *repo, struct dir_struct *dir)\n \t\t\tif (ce_skip_worktree(ce))\n \t\t\t\tcontinue;\n \t\t\terr = lstat(fullname.buf, &st);\n-\t\t\tif (show_deleted && err)\n+\t\t\tif(delete_dup && show_deleted && show_modified && err)\n \t\t\t\tshow_ce(repo, dir, ce, fullname.buf, tag_removed);\n-\t\t\tif (show_modified && ie_modified(repo->index, ce, &st, 0))\n-\t\t\t\tshow_ce(repo, dir, ce, fullname.buf, tag_modified);\n+\t\t\telse{\n+\t\t\t\tif (show_deleted && err)/* you can't find it,so it's actually removed at all! */\n+\t\t\t\t\tshow_ce(repo, dir, ce, fullname.buf, tag_removed);\n+\t\t\t\tif (show_modified && ie_modified(repo->index, ce, &st, 0))\n+\t\t\t\t\tshow_ce(repo, dir, ce, fullname.buf, tag_modified);\n+\t\t\t}\n \t\t}\n \t}\n \n@@ -578,6 +610,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \t\t\tN_(\"pretend that paths removed since <tree-ish> are still present\")),\n \t\tOPT__ABBREV(&abbrev),\n \t\tOPT_BOOL(0, \"debug\", &debug_mode, N_(\"show debugging data\")),\n+\t\tOPT_BOOL(0, \"dedup\", &delete_dup, N_(\"delete duplicate entry in index\")),\n \t\tOPT_END()\n \t};\n \n-- \n2.30.0\n\n"},{"id":"413433","messageId":"20210105053946.710743-2-adlternative@gmail.com","threadId":"54932","inReplyTo":"20210105053946.710743-1-adlternative@gmail.com","subject":"[PATCH] builtin/ls-files.c:add git ls-file --dedup option","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2021-01-05T05:39:46Z","receivedAt":"2021-01-05T05:40:16Z","isPatch":true,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"1.When we use git ls-files with both -m -d,\nwe would find that repeated path,sometimes\nit is confusing.\n2.When we are performing a branch merge,\n the default git ls-files will also output\n multiple repeated file names.\nTherefore, I added the --dedup option to git ls-files.\n1. It can be achieved that only the deleted file name\nis displayed when using -m, -d, and --dedup at the same time.\n2. Add --dedup when merging branches to remove duplicate file\n names. (unless -s, -u are used)\n\nSigned-off-by: ZheNing Hu <adlternative@gmail.com>\n---\n builtin/ls-files.c | 43 ++++++++++++++++++++++++++++++++++++++-----\n 1 file changed, 38 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex c8eae899b8..66a7e251a4 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -35,6 +35,7 @@ static int line_terminator = '\\n';\n static int debug_mode;\n static int show_eol;\n static int recurse_submodules;\n+static int delete_dup;\n \n static const char *prefix;\n static int max_prefix_len;\n@@ -301,6 +302,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)\n {\n \tint i;\n \tstruct strbuf fullname = STRBUF_INIT;\n+\tconst struct cache_entry *last_stage=NULL;\n \n \t/* For cached/deleted files we don't need to even do the readdir */\n \tif (show_others || show_killed) {\n@@ -315,7 +317,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)\n \tif (show_cached || show_stage) {\n \t\tfor (i = 0; i < repo->index->cache_nr; i++) {\n \t\t\tconst struct cache_entry *ce = repo->index->cache[i];\n-\n+\t\t\tif(show_cached && delete_dup){\n+\t\t\t\tswitch (ce_stage(ce)) {\n+\t\t\t\tcase 0:\n+\t\t\t\tdefault:\n+\t\t\t\t\tbreak;\n+\t\t\t\tcase 1:\n+\t\t\t\tcase 2:\n+\t\t\t\tcase 3:\n+\t\t\t\t\tif (last_stage &&\n+\t\t\t\t\t!strcmp(last_stage->name, ce->name))\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\tlast_stage=ce;\n+\t\t\t\t}\n+\t\t\t}\n \t\t\tconstruct_fullname(&fullname, repo, ce);\n \n \t\t\tif ((dir->flags & DIR_SHOW_IGNORED) &&\n@@ -336,7 +351,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)\n \t\t\tconst struct cache_entry *ce = repo->index->cache[i];\n \t\t\tstruct stat st;\n \t\t\tint err;\n-\n+\t\t\tif(delete_dup){\n+\t\t\t\tswitch (ce_stage(ce)) {\n+\t\t\t\tcase 0:\n+\t\t\t\tdefault:\n+\t\t\t\t\tbreak;\n+\t\t\t\tcase 1:\n+\t\t\t\tcase 2:\n+\t\t\t\tcase 3:\n+\t\t\t\t\tif (last_stage &&\n+\t\t\t\t\t!strcmp(last_stage->name, ce->name))\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\tlast_stage=ce;\n+\t\t\t\t}\n+\t\t\t}\n \t\t\tconstruct_fullname(&fullname, repo, ce);\n \n \t\t\tif ((dir->flags & DIR_SHOW_IGNORED) &&\n@@ -347,10 +375,14 @@ static void show_files(struct repository *repo, struct dir_struct *dir)\n \t\t\tif (ce_skip_worktree(ce))\n \t\t\t\tcontinue;\n \t\t\terr = lstat(fullname.buf, &st);\n-\t\t\tif (show_deleted && err)\n+\t\t\tif(delete_dup && show_deleted && show_modified && err)\n \t\t\t\tshow_ce(repo, dir, ce, fullname.buf, tag_removed);\n-\t\t\tif (show_modified && ie_modified(repo->index, ce, &st, 0))\n-\t\t\t\tshow_ce(repo, dir, ce, fullname.buf, tag_modified);\n+\t\t\telse{\n+\t\t\t\tif (show_deleted && err)/* you can't find it,so it's actually removed at all! */\n+\t\t\t\t\tshow_ce(repo, dir, ce, fullname.buf, tag_removed);\n+\t\t\t\tif (show_modified && ie_modified(repo->index, ce, &st, 0))\n+\t\t\t\t\tshow_ce(repo, dir, ce, fullname.buf, tag_modified);\n+\t\t\t}\n \t\t}\n \t}\n \n@@ -578,6 +610,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \t\t\tN_(\"pretend that paths removed since <tree-ish> are still present\")),\n \t\tOPT__ABBREV(&abbrev),\n \t\tOPT_BOOL(0, \"debug\", &debug_mode, N_(\"show debugging data\")),\n+\t\tOPT_BOOL(0, \"dedup\", &delete_dup, N_(\"delete duplicate entry in index\")),\n \t\tOPT_END()\n \t};\n \n-- \n2.30.0\n\n"}]}