{"thread":{"id":"22122","subject":"[PATCH] Add quiet option to git-ls-files","startedAt":"2010-01-07T19:37:20Z","lastAt":"2010-01-08T02:17:55Z","messageCount":3,"participants":["Ramkumar Ramachandra","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"131033","messageId":"f3271551001071137u6158fa4fm1bf7a51a83354574@mail.gmail.com","threadId":"22122","inReplyTo":null,"subject":"[PATCH] Add quiet option to git-ls-files","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2010-01-07T19:37:20Z","receivedAt":"2010-01-07T19:37:20Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nI just wrote a couple of patches. I'm sorry for having to attach the\nfiles- I'm behind a HTTP proxy, and Gmail mangles patches.\n\nThanks and regards,\nRamkumar\n\n\nFrom f5f76190a833bf105483a7da9b4b61ab03e373ba Mon Sep 17 00:00:00 2001\nFrom: Ramkumar Ramachandra <artagnon@gmail.com>\nDate: Thu, 7 Jan 2010 23:58:08 +0530\nSubject: [PATCH 1/2] Add quiet option to git-ls-files\n\n--quiet option suppresses error output in --error-unmatch mode. Modify\ndocumentation to reflect changes.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Documentation/git-ls-files.txt |    6 ++++++\n builtin-ls-files.c             |   12 +++++++-----\n 2 files changed, 13 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt\nindex 625723e..0a1f94e 100644\n--- a/Documentation/git-ls-files.txt\n+++ b/Documentation/git-ls-files.txt\n@@ -82,6 +82,12 @@ OPTIONS\n \tSkips files matching pattern.\n \tNote that pattern is a shell wildcard pattern.\n \n+--q::\n+--quiet::\n+\tOnly meaningful in --error-unmatch mode. Do not output an\n+\terror message if <file> does not appear in the index. Instead\n+\texit with non-zero status silently.\n+\n -X <file>::\n --exclude-from=<file>::\n \texclude patterns are read from <file>; 1 per line.\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex c9a03e5..40560da 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -421,12 +421,13 @@ static int option_parse_exclude_standard(const struct option *opt,\n \n int cmd_ls_files(int argc, const char **argv, const char *prefix)\n {\n-\tint require_work_tree = 0, show_tag = 0;\n+\tint require_work_tree = 0, show_tag = 0, quiet = 0;\n \tstruct dir_struct dir;\n \tstruct option builtin_ls_files_options[] = {\n \t\t{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,\n \t\t\t\"paths are separated with NUL character\",\n \t\t\tPARSE_OPT_NOARG, option_parse_z },\n+\t\tOPT__QUIET(&quiet),\n \t\tOPT_BOOLEAN('t', NULL, &show_tag,\n \t\t\t\"identify the file status with tags\"),\n \t\tOPT_BOOLEAN('v', NULL, &show_valid_bit,\n@@ -547,10 +548,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \n \tif (ps_matched) {\n \t\tint bad;\n-\t\tbad = report_path_error(ps_matched, pathspec, prefix_offset);\n-\t\tif (bad)\n-\t\t\tfprintf(stderr, \"Did you forget to 'git add'?\\n\");\n-\n+\t\tif (!quiet) {\n+\t\t\tbad = report_path_error(ps_matched, pathspec, prefix_offset);\n+\t\t\tif (bad)\n+\t\t\t\tfprintf(stderr, \"Did you forget to 'git add'?\\n\");\n+\t\t}\n \t\treturn bad ? 1 : 0;\n \t}\n \n-- \n1.6.5\n\n\n\nFrom b5c7a0fb8d092aafcedcbd653f00dee564a0d953 Mon Sep 17 00:00:00 2001\nFrom: Ramkumar Ramachandra <artagnon@gmail.com>\nDate: Fri, 8 Jan 2010 00:00:58 +0530\nSubject: [PATCH 2/2] Replace redirect to /dev/null in favor of quiet option\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n git-mergetool.sh |    2 +-\n git-pull.sh      |    2 +-\n git-rebase.sh    |    2 +-\n git-stash.sh     |   12 ++++++------\n git-submodule.sh |    2 +-\n 5 files changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex b52a741..1c902aa 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -101,7 +101,7 @@ resolve_deleted_merge () {\n \t\treturn 0\n \t\t;;\n \t    [dD]*)\n-\t\tgit rm -- \"$MERGED\" > /dev/null\n+\t\tgit rm --quiet -- \"$MERGED\"\n \t\tcleanup_temp_files\n \t\treturn 0\n \t\t;;\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 9e69ada..336e91a 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -170,7 +170,7 @@ test true = \"$rebase\" && {\n \t. git-parse-remote &&\n \tremoteref=\"$(get_remote_merge_branch \"$@\" 2>/dev/null)\" &&\n \toldremoteref=\"$(git rev-parse -q --verify \"$remoteref\")\" &&\n-\tfor reflog in $(git rev-list -g $remoteref 2>/dev/null)\n+\tfor reflog in $(git rev-list --quiet --walk-reflogs $remoteref)\n \tdo\n \t\tif test \"$reflog\" = \"$(git merge-base $reflog $curr_branch)\"\n \t\tthen\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex b121f45..bfe0475 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -100,7 +100,7 @@ call_merge () {\n \tcmt=\"$(cat \"$dotest/cmt.$1\")\"\n \techo \"$cmt\" > \"$dotest/current\"\n \thd=$(git rev-parse --verify HEAD)\n-\tcmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)\n+\tcmt_name=$(git symbolic-ref --quiet HEAD || echo HEAD)\n \tmsgnum=$(cat \"$dotest/msgnum\")\n \tend=$(cat \"$dotest/end\")\n \teval GITHEAD_$cmt='\"${cmt_name##refs/heads/}~$(($end - $msgnum))\"'\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 3a0685f..5605d19 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -39,7 +39,7 @@ clear_stash () {\n \tthen\n \t\tdie \"git stash clear with parameters is unimplemented\"\n \tfi\n-\tif current=$(git rev-parse --verify $ref_stash 2>/dev/null)\n+\tif current=$(git rev-parse --quiet --verify $ref_stash)\n \tthen\n \t\tgit update-ref -d $ref_stash $current\n \tfi\n@@ -200,7 +200,7 @@ save_stash () {\n }\n \n have_stash () {\n-\tgit rev-parse --verify $ref_stash >/dev/null 2>&1\n+\tgit rev-parse --quiet --verify $ref_stash >/dev/null\n }\n \n list_stash () {\n@@ -337,16 +337,16 @@ drop_stash () {\n \tfi\n \t# Verify supplied argument looks like a stash entry\n \ts=$(git rev-parse --verify \"$@\") &&\n-\tgit rev-parse --verify \"$s:\"   > /dev/null 2>&1 &&\n-\tgit rev-parse --verify \"$s^1:\" > /dev/null 2>&1 &&\n-\tgit rev-parse --verify \"$s^2:\" > /dev/null 2>&1 ||\n+\tgit rev-parse --quiet --verify \"$s:\"   > /dev/null &&\n+\tgit rev-parse --quiet --verify \"$s^1:\" > /dev/null &&\n+\tgit rev-parse --quiet --verify \"$s^2:\" > /dev/null ||\n \t\tdie \"$*: not a valid stashed state\"\n \n \tgit reflog delete --updateref --rewrite \"$@\" &&\n \t\tsay \"Dropped $* ($s)\" || die \"$*: Could not drop stash entry\"\n \n \t# clear_stash if we just dropped the last stash entry\n-\tgit rev-parse --verify \"$ref_stash@{0}\" > /dev/null 2>&1 || clear_stash\n+\tgit rev-parse --quiet --verify \"$ref_stash@{0}\" > /dev/null || clear_stash\n }\n \n apply_to_branch () {\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 77d2232..2b6448f 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -196,7 +196,7 @@ cmd_add()\n \t\t\ttstart\n \t\t\ts|/*$||\n \t\t')\n-\tgit ls-files --error-unmatch \"$path\" > /dev/null 2>&1 &&\n+\tgit ls-files --quiet --error-unmatch \"$path\" > /dev/null &&\n \tdie \"'$path' already exists in the index\"\n \n \t# perhaps the path exists and is already a git repo, else clone it\n-- \n1.6.5\n\n"},{"id":"131034","messageId":"7v1vi14qiy.fsf@alter.siamese.dyndns.org","threadId":"22122","inReplyTo":"f3271551001071137u6158fa4fm1bf7a51a83354574@mail.gmail.com","subject":"Re: [PATCH] Add quiet option to git-ls-files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-07T20:19:01Z","receivedAt":"2010-01-07T20:19:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt\n> index 625723e..0a1f94e 100644\n> --- a/Documentation/git-ls-files.txt\n> +++ b/Documentation/git-ls-files.txt\n> @@ -82,6 +82,12 @@ OPTIONS\n>  \tSkips files matching pattern.\n>  \tNote that pattern is a shell wildcard pattern.\n>  \n> +--q::\n> +--quiet::\n> +\tOnly meaningful in --error-unmatch mode. Do not output an\n> +\terror message if <file> does not appear in the index. Instead\n> +\texit with non-zero status silently.\n\nThe code doesn't seem to match the claim.\n\n> diff --git a/builtin-ls-files.c b/builtin-ls-files.c\n> index c9a03e5..40560da 100644\n> --- a/builtin-ls-files.c\n> +++ b/builtin-ls-files.c\n> @@ -547,10 +548,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n>  \n>  \tif (ps_matched) {\n>  \t\tint bad;\n> +\t\tif (!quiet) {\n> +\t\t\tbad = report_path_error(ps_matched, pathspec, prefix_offset);\n> +\t\t\tif (bad)\n> +\t\t\t\tfprintf(stderr, \"Did you forget to 'git add'?\\n\");\n> +\t\t}\n>  \t\treturn bad ? 1 : 0;\n>  \t}\n\nYou might have seen that the code returns 1 during your testing, but that\nis not because ps_matched[] was inspected, but because you are checking an\nuninitialized garbage on stack in \"bad\" that happened to be non-zero.\n"},{"id":"131064","messageId":"f3271551001071817g3e8dd85cya090be715ae48240@mail.gmail.com","threadId":"22122","inReplyTo":"7v1vi14qiy.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Add quiet option to git-ls-files","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2010-01-08T02:17:55Z","receivedAt":"2010-01-08T02:17:55Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"> The code doesn't seem to match the claim.\n\nI'm sorry- That was horribly sloppy of me. I figured that passing\n`quiet' to report_path_error would break too many things, so I've\ndropped that patch altogether. I've removed the reference to ls-files\n--quiet in my second patch ( viz.\n0002-Replace-redirect-to-dev-null-in-favor-of-quiet-optio.patch) and\nattached version 2.\n\nThanks and regards,\nRamkumar\n\n\nFrom c34c72801804da61169ab6866d6ce262ea6cf5c1 Mon Sep 17 00:00:00 2001\nFrom: Ramkumar Ramachandra <artagnon@gmail.com>\nDate: Fri, 8 Jan 2010 07:32:29 +0530\nSubject: [PATCH v2] Replace redirect to /dev/null in favor of quiet option\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n git-mergetool.sh |    2 +-\n git-pull.sh      |    2 +-\n git-rebase.sh    |    2 +-\n git-stash.sh     |   12 ++++++------\n 4 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex b52a741..1c902aa 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -101,7 +101,7 @@ resolve_deleted_merge () {\n \t\treturn 0\n \t\t;;\n \t    [dD]*)\n-\t\tgit rm -- \"$MERGED\" > /dev/null\n+\t\tgit rm --quiet -- \"$MERGED\"\n \t\tcleanup_temp_files\n \t\treturn 0\n \t\t;;\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 9e69ada..336e91a 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -170,7 +170,7 @@ test true = \"$rebase\" && {\n \t. git-parse-remote &&\n \tremoteref=\"$(get_remote_merge_branch \"$@\" 2>/dev/null)\" &&\n \toldremoteref=\"$(git rev-parse -q --verify \"$remoteref\")\" &&\n-\tfor reflog in $(git rev-list -g $remoteref 2>/dev/null)\n+\tfor reflog in $(git rev-list --quiet --walk-reflogs $remoteref)\n \tdo\n \t\tif test \"$reflog\" = \"$(git merge-base $reflog $curr_branch)\"\n \t\tthen\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex b121f45..bfe0475 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -100,7 +100,7 @@ call_merge () {\n \tcmt=\"$(cat \"$dotest/cmt.$1\")\"\n \techo \"$cmt\" > \"$dotest/current\"\n \thd=$(git rev-parse --verify HEAD)\n-\tcmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)\n+\tcmt_name=$(git symbolic-ref --quiet HEAD || echo HEAD)\n \tmsgnum=$(cat \"$dotest/msgnum\")\n \tend=$(cat \"$dotest/end\")\n \teval GITHEAD_$cmt='\"${cmt_name##refs/heads/}~$(($end - $msgnum))\"'\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 3a0685f..5605d19 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -39,7 +39,7 @@ clear_stash () {\n \tthen\n \t\tdie \"git stash clear with parameters is unimplemented\"\n \tfi\n-\tif current=$(git rev-parse --verify $ref_stash 2>/dev/null)\n+\tif current=$(git rev-parse --quiet --verify $ref_stash)\n \tthen\n \t\tgit update-ref -d $ref_stash $current\n \tfi\n@@ -200,7 +200,7 @@ save_stash () {\n }\n \n have_stash () {\n-\tgit rev-parse --verify $ref_stash >/dev/null 2>&1\n+\tgit rev-parse --quiet --verify $ref_stash >/dev/null\n }\n \n list_stash () {\n@@ -337,16 +337,16 @@ drop_stash () {\n \tfi\n \t# Verify supplied argument looks like a stash entry\n \ts=$(git rev-parse --verify \"$@\") &&\n-\tgit rev-parse --verify \"$s:\"   > /dev/null 2>&1 &&\n-\tgit rev-parse --verify \"$s^1:\" > /dev/null 2>&1 &&\n-\tgit rev-parse --verify \"$s^2:\" > /dev/null 2>&1 ||\n+\tgit rev-parse --quiet --verify \"$s:\"   > /dev/null &&\n+\tgit rev-parse --quiet --verify \"$s^1:\" > /dev/null &&\n+\tgit rev-parse --quiet --verify \"$s^2:\" > /dev/null ||\n \t\tdie \"$*: not a valid stashed state\"\n \n \tgit reflog delete --updateref --rewrite \"$@\" &&\n \t\tsay \"Dropped $* ($s)\" || die \"$*: Could not drop stash entry\"\n \n \t# clear_stash if we just dropped the last stash entry\n-\tgit rev-parse --verify \"$ref_stash@{0}\" > /dev/null 2>&1 || clear_stash\n+\tgit rev-parse --quiet --verify \"$ref_stash@{0}\" > /dev/null || clear_stash\n }\n \n apply_to_branch () {\n-- \n1.6.5\n\n"}]}