diff mbox series

[v4,1/3] ls_files.c: bugfix for --deleted and --modified

Message ID f4d9af8a3124bcd37a35b1863441406f6d939f11.1610856136.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series builtin/ls-files.c:add git ls-file --dedup option | expand

Commit Message

ZheNing Hu Jan. 17, 2021, 4:02 a.m. UTC
From: ZheNing Hu <adlternative@gmail.com>

This situation may occur in the original code: lstat() failed
but we use `&st` to feed ie_modified() later.

It's buggy!

Therefore, we can directly execute show_ce without the judgment of
ie_modified() when lstat() has failed.

Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
 builtin/ls-files.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Junio C Hamano Jan. 17, 2021, 6:22 a.m. UTC | #1
"ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: ZheNing Hu <adlternative@gmail.com>
>
> This situation may occur in the original code: lstat() failed
> but we use `&st` to feed ie_modified() later.
>
> It's buggy!

Wasteful extra paragraph with almost no information contents over
what has already been said in the first paragraph.

> Therefore, we can directly execute show_ce without the judgment of
> ie_modified() when lstat() has failed.

But it introduces another bug, as you do not even see why a path
cannot be lstat'ed, no?

>
> Signed-off-by: ZheNing Hu <adlternative@gmail.com>
> ---
>  builtin/ls-files.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/ls-files.c b/builtin/ls-files.c
> index c8eae899b82..6f97a23c2dc 100644
> --- a/builtin/ls-files.c
> +++ b/builtin/ls-files.c
> @@ -347,9 +347,12 @@ 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)
> -				show_ce(repo, dir, ce, fullname.buf, tag_removed);
> -			if (show_modified && ie_modified(repo->index, ce, &st, 0))
> +			if (err) {
> +					if (show_deleted)
> +						show_ce(repo, dir, ce, fullname.buf, tag_removed);
> +					if (show_modified)
> +						show_ce(repo, dir, ce, fullname.buf, tag_modified);
> +			}else if (show_modified && ie_modified(repo->index, ce, &st, 0))
>  				show_ce(repo, dir, ce, fullname.buf, tag_modified);
>  		}
>  	}
diff mbox series

Patch

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index c8eae899b82..6f97a23c2dc 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -347,9 +347,12 @@  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)
-				show_ce(repo, dir, ce, fullname.buf, tag_removed);
-			if (show_modified && ie_modified(repo->index, ce, &st, 0))
+			if (err) {
+					if (show_deleted)
+						show_ce(repo, dir, ce, fullname.buf, tag_removed);
+					if (show_modified)
+						show_ce(repo, dir, ce, fullname.buf, tag_modified);
+			}else if (show_modified && ie_modified(repo->index, ce, &st, 0))
 				show_ce(repo, dir, ce, fullname.buf, tag_modified);
 		}
 	}