* [PATCH v1 1/1] builtin/ls-files.c:add git ls-file --dedup option
@ 2021-01-05 5:39 ZheNing Hu
2021-01-05 5:39 ` [PATCH] " ZheNing Hu
0 siblings, 1 reply; 6+ messages in thread
From: ZheNing Hu @ 2021-01-05 5:39 UTC (permalink / raw)
To: git; +Cc: felipe.contreras, ZheNing Hu
1.When we use git ls-files with both -m -d,
we would find that repeated path,sometimes
it is confusing.
2.When we are performing a branch merge,
the default git ls-files will also output
multiple repeated file names.
Therefore, I added the --dedup option to git ls-files.
1. It can be achieved that only the deleted file name
is displayed when using -m, -d, and --dedup at the same time.
2. Add --dedup when merging branches to remove duplicate file
names. (unless -s, -u are used)
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
builtin/ls-files.c | 43 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index c8eae899b8..66a7e251a4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -35,6 +35,7 @@ static int line_terminator = '\n';
static int debug_mode;
static int show_eol;
static int recurse_submodules;
+static int delete_dup;
static const char *prefix;
static int max_prefix_len;
@@ -301,6 +302,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
{
int i;
struct strbuf fullname = STRBUF_INIT;
+ const struct cache_entry *last_stage=NULL;
/* For cached/deleted files we don't need to even do the readdir */
if (show_others || show_killed) {
@@ -315,7 +317,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
if (show_cached || show_stage) {
for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];
-
+ if(show_cached && delete_dup){
+ switch (ce_stage(ce)) {
+ case 0:
+ default:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ if (last_stage &&
+ !strcmp(last_stage->name, ce->name))
+ continue;
+ last_stage=ce;
+ }
+ }
construct_fullname(&fullname, repo, ce);
if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -336,7 +351,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
const struct cache_entry *ce = repo->index->cache[i];
struct stat st;
int err;
-
+ if(delete_dup){
+ switch (ce_stage(ce)) {
+ case 0:
+ default:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ if (last_stage &&
+ !strcmp(last_stage->name, ce->name))
+ continue;
+ last_stage=ce;
+ }
+ }
construct_fullname(&fullname, repo, ce);
if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -347,10 +375,14 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
if (ce_skip_worktree(ce))
continue;
err = lstat(fullname.buf, &st);
- if (show_deleted && err)
+ if(delete_dup && show_deleted && show_modified && err)
show_ce(repo, dir, ce, fullname.buf, tag_removed);
- if (show_modified && ie_modified(repo->index, ce, &st, 0))
- show_ce(repo, dir, ce, fullname.buf, tag_modified);
+ else{
+ if (show_deleted && err)/* you can't find it,so it's actually removed at all! */
+ show_ce(repo, dir, ce, fullname.buf, tag_removed);
+ if (show_modified && ie_modified(repo->index, ce, &st, 0))
+ show_ce(repo, dir, ce, fullname.buf, tag_modified);
+ }
}
}
@@ -578,6 +610,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
N_("pretend that paths removed since <tree-ish> are still present")),
OPT__ABBREV(&abbrev),
OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
+ OPT_BOOL(0, "dedup", &delete_dup, N_("delete duplicate entry in index")),
OPT_END()
};
--
2.30.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] builtin/ls-files.c:add git ls-file --dedup option
2021-01-05 5:39 [PATCH v1 1/1] builtin/ls-files.c:add git ls-file --dedup option ZheNing Hu
@ 2021-01-05 5:39 ` ZheNing Hu
0 siblings, 0 replies; 6+ messages in thread
From: ZheNing Hu @ 2021-01-05 5:39 UTC (permalink / raw)
To: git; +Cc: felipe.contreras, ZheNing Hu
1.When we use git ls-files with both -m -d,
we would find that repeated path,sometimes
it is confusing.
2.When we are performing a branch merge,
the default git ls-files will also output
multiple repeated file names.
Therefore, I added the --dedup option to git ls-files.
1. It can be achieved that only the deleted file name
is displayed when using -m, -d, and --dedup at the same time.
2. Add --dedup when merging branches to remove duplicate file
names. (unless -s, -u are used)
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
builtin/ls-files.c | 43 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index c8eae899b8..66a7e251a4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -35,6 +35,7 @@ static int line_terminator = '\n';
static int debug_mode;
static int show_eol;
static int recurse_submodules;
+static int delete_dup;
static const char *prefix;
static int max_prefix_len;
@@ -301,6 +302,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
{
int i;
struct strbuf fullname = STRBUF_INIT;
+ const struct cache_entry *last_stage=NULL;
/* For cached/deleted files we don't need to even do the readdir */
if (show_others || show_killed) {
@@ -315,7 +317,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
if (show_cached || show_stage) {
for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];
-
+ if(show_cached && delete_dup){
+ switch (ce_stage(ce)) {
+ case 0:
+ default:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ if (last_stage &&
+ !strcmp(last_stage->name, ce->name))
+ continue;
+ last_stage=ce;
+ }
+ }
construct_fullname(&fullname, repo, ce);
if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -336,7 +351,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
const struct cache_entry *ce = repo->index->cache[i];
struct stat st;
int err;
-
+ if(delete_dup){
+ switch (ce_stage(ce)) {
+ case 0:
+ default:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ if (last_stage &&
+ !strcmp(last_stage->name, ce->name))
+ continue;
+ last_stage=ce;
+ }
+ }
construct_fullname(&fullname, repo, ce);
if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -347,10 +375,14 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
if (ce_skip_worktree(ce))
continue;
err = lstat(fullname.buf, &st);
- if (show_deleted && err)
+ if(delete_dup && show_deleted && show_modified && err)
show_ce(repo, dir, ce, fullname.buf, tag_removed);
- if (show_modified && ie_modified(repo->index, ce, &st, 0))
- show_ce(repo, dir, ce, fullname.buf, tag_modified);
+ else{
+ if (show_deleted && err)/* you can't find it,so it's actually removed at all! */
+ show_ce(repo, dir, ce, fullname.buf, tag_removed);
+ if (show_modified && ie_modified(repo->index, ce, &st, 0))
+ show_ce(repo, dir, ce, fullname.buf, tag_modified);
+ }
}
}
@@ -578,6 +610,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
N_("pretend that paths removed since <tree-ish> are still present")),
OPT__ABBREV(&abbrev),
OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
+ OPT_BOOL(0, "dedup", &delete_dup, N_("delete duplicate entry in index")),
OPT_END()
};
--
2.30.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] builtin/ls-files.c:add git ls-file --dedup option
@ 2021-01-06 8:53 阿德烈 via GitGitGadget
2021-01-07 6:10 ` Eric Sunshine
0 siblings, 1 reply; 6+ messages in thread
From: 阿德烈 via GitGitGadget @ 2021-01-06 8:53 UTC (permalink / raw)
To: git; +Cc: 阿德烈, ZheNing Hu
From: ZheNing Hu <adlternative@gmail.com>
1.When we use git ls-files with both -m -d,
we would find that repeated path,sometimes
it is confusing.
2.When we are performing a branch merge,
the default git ls-files will also output
multiple repeated file names.
Therefore, I added the --dedup option to git ls-files.
1. It can be achieved that only the deleted file name
is displayed when using -m, -d, and --dedup at the same time.
2. Add --dedup when merging branches to remove duplicate file
names. (unless -s, -u are used)
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
builtin/ls-files.c:add git ls-file --dedup option
I am reading the source code of git ls-files and learned that git ls
-files may have duplicate entries when conflict occurs in a branch merge
or when different options are used at the same time. Users may fell
confuse when they see these duplicate entries.
As Junio C Hamano said ,it have odd behaviour.
Therefore, we can provide an additional option to git ls-files to delete
those repeated information.
This fixes https://github.com/gitgitgadget/git/issues/198
Thanks!
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-832%2Fadlternative%2Fls-files-dedup-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-832/adlternative/ls-files-dedup-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/832
builtin/ls-files.c | 43 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index c8eae899b82..66a7e251a46 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -35,6 +35,7 @@ static int line_terminator = '\n';
static int debug_mode;
static int show_eol;
static int recurse_submodules;
+static int delete_dup;
static const char *prefix;
static int max_prefix_len;
@@ -301,6 +302,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
{
int i;
struct strbuf fullname = STRBUF_INIT;
+ const struct cache_entry *last_stage=NULL;
/* For cached/deleted files we don't need to even do the readdir */
if (show_others || show_killed) {
@@ -315,7 +317,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
if (show_cached || show_stage) {
for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];
-
+ if(show_cached && delete_dup){
+ switch (ce_stage(ce)) {
+ case 0:
+ default:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ if (last_stage &&
+ !strcmp(last_stage->name, ce->name))
+ continue;
+ last_stage=ce;
+ }
+ }
construct_fullname(&fullname, repo, ce);
if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -336,7 +351,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
const struct cache_entry *ce = repo->index->cache[i];
struct stat st;
int err;
-
+ if(delete_dup){
+ switch (ce_stage(ce)) {
+ case 0:
+ default:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ if (last_stage &&
+ !strcmp(last_stage->name, ce->name))
+ continue;
+ last_stage=ce;
+ }
+ }
construct_fullname(&fullname, repo, ce);
if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -347,10 +375,14 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
if (ce_skip_worktree(ce))
continue;
err = lstat(fullname.buf, &st);
- if (show_deleted && err)
+ if(delete_dup && show_deleted && show_modified && err)
show_ce(repo, dir, ce, fullname.buf, tag_removed);
- if (show_modified && ie_modified(repo->index, ce, &st, 0))
- show_ce(repo, dir, ce, fullname.buf, tag_modified);
+ else{
+ if (show_deleted && err)/* you can't find it,so it's actually removed at all! */
+ show_ce(repo, dir, ce, fullname.buf, tag_removed);
+ if (show_modified && ie_modified(repo->index, ce, &st, 0))
+ show_ce(repo, dir, ce, fullname.buf, tag_modified);
+ }
}
}
@@ -578,6 +610,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
N_("pretend that paths removed since <tree-ish> are still present")),
OPT__ABBREV(&abbrev),
OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
+ OPT_BOOL(0, "dedup", &delete_dup, N_("delete duplicate entry in index")),
OPT_END()
};
base-commit: 6d3ef5b467eccd2769f1aa1c555d317d3c8dc707
--
gitgitgadget
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] builtin/ls-files.c:add git ls-file --dedup option
2021-01-06 8:53 阿德烈 via GitGitGadget
@ 2021-01-07 6:10 ` Eric Sunshine
2021-01-07 6:40 ` Junio C Hamano
0 siblings, 1 reply; 6+ messages in thread
From: Eric Sunshine @ 2021-01-07 6:10 UTC (permalink / raw)
To: 阿德烈 via GitGitGadget; +Cc: Git List, ZheNing Hu
On Wed, Jan 6, 2021 at 3:54 AM 阿德烈 via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> [...]
> Therefore, I added the --dedup option to git ls-files.
> 1. It can be achieved that only the deleted file name
> is displayed when using -m, -d, and --dedup at the same time.
> 2. Add --dedup when merging branches to remove duplicate file
> names. (unless -s, -u are used)
I'm just pointing out a few minor style issues below; I'm not properly
reviewing the patch...
> Signed-off-by: ZheNing Hu <adlternative@gmail.com>
> ---
> builtin/ls-files.c | 43 ++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 38 insertions(+), 5 deletions(-)
This change adds a new command-line option, so the documentation
(Documentation/git-ls-files.txt) should be updated and at least one
new test should be added (in one of the t/t30??-ls-files-*.sh scripts
probably).
> diff --git a/builtin/ls-files.c b/builtin/ls-files.c
> @@ -301,6 +302,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
> struct strbuf fullname = STRBUF_INIT;
> + const struct cache_entry *last_stage=NULL;
Add spaces around `=` similar to the preceding line:
const struct cache_entry *last_stage = NULL;
> @@ -315,7 +317,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
> for (i = 0; i < repo->index->cache_nr; i++) {
> const struct cache_entry *ce = repo->index->cache[i];
> -
This patch deletes the blank line but this project usually prefers to
have a blank line after declarations.
> + if(show_cached && delete_dup){
Add space after `if` and before `{`:
if (show_cached && delete_dup) {
> @@ -336,7 +351,20 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
> + if(delete_dup){
Style: if (delete_dup) {
> @@ -347,10 +375,14 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
> - if (show_deleted && err)
> + if(delete_dup && show_deleted && show_modified && err)
Style: if (delete_dup && ...
> - if (show_modified && ie_modified(repo->index, ce, &st, 0))
> - show_ce(repo, dir, ce, fullname.buf, tag_modified);
> + else{
Style: else {
> + if (show_deleted && err)/* you can't find it,so it's actually removed at all! */
Add space before `/* comment */`.
Add space in "...it, so...".
> @@ -578,6 +610,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
> + OPT_BOOL(0, "dedup", &delete_dup, N_("delete duplicate entry in index")),
The short help makes it seem like it's modifying the index. Perhaps instead:
N_("suppress duplicate entries")
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] builtin/ls-files.c:add git ls-file --dedup option
@ 2021-01-07 6:58 胡哲宁
0 siblings, 0 replies; 6+ messages in thread
From: 胡哲宁 @ 2021-01-07 6:58 UTC (permalink / raw)
To: sunshine; +Cc: adlternative, git, gitgitgadget
Oh my god! Thank you for your correction! :-)
I didn't learn to write git project format specifications before, I
will pay attention.
I will learn to write test scripts later.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-07 6:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 5:39 [PATCH v1 1/1] builtin/ls-files.c:add git ls-file --dedup option ZheNing Hu
2021-01-05 5:39 ` [PATCH] " ZheNing Hu
2021-01-06 8:53 阿德烈 via GitGitGadget
2021-01-07 6:10 ` Eric Sunshine
2021-01-07 6:40 ` Junio C Hamano
2021-01-07 6:58 胡哲宁
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).