{"thread":{"id":"41609","subject":"[PATCH] stripspace: add --line-count flag","startedAt":"2016-03-04T18:38:43Z","lastAt":"2016-03-04T18:57:33Z","messageCount":5,"participants":["Sidhant Sharma [:tk]","Sidhant Sharma","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"280204","messageId":"1457116723-20206-1-git-send-email-tigerkid001@gmail.com","threadId":"41609","inReplyTo":null,"subject":"[PATCH] stripspace: add --line-count flag","fromName":"Sidhant Sharma [:tk]","fromEmail":"tigerkid001@gmail.com","sentAt":"2016-03-04T18:38:43Z","receivedAt":"2016-03-04T18:38:43Z","isPatch":true,"sender":{"key":"tigerkid001@gmail.com","avatar":"https://avatars.githubusercontent.com/u/7801881?v=4"},"body":"When used, this flag outputs number of lines after stripspace has removed trailing whitespace.\nWith `--line-count`, git-rebase--interactive.sh need not rely on `wc -l` for line\ncount.\n\nSigned-off-by: Sidhant Sharma [:tk] <tigerkid001@gmail.com>\n---\n\n This the first version of the patch for the small project listed here:\n https://git.wiki.kernel.org/index.php/SmallProjectsIdeas#implement_.27--count-lines.27_in_.27git_stripspace.27\n\n builtin/stripspace.c       | 22 +++++++++++++++++++++-\n git-rebase--interactive.sh |  6 +++---\n 2 files changed, 24 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/stripspace.c b/builtin/stripspace.c\nindex 15e716e..e08da03 100644\n--- a/builtin/stripspace.c\n+++ b/builtin/stripspace.c\n@@ -13,22 +13,38 @@ static void comment_lines(struct strbuf *buf)\n \tfree(msg);\n }\n\n+static void count_lines(struct strbuf *buf)\n+{\n+\tsize_t len = 0;\n+\tint i;\n+\n+\tfor (i = 0; i < buf->len; i++)\n+\t\tif (buf->buf[i] == '\\n')\n+\t\t\tlen++;\n+\n+\tsprintf(buf->buf, \"%zu\", len);\n+\tbuf->len = strlen(buf->buf);\n+}\n+\n static const char * const stripspace_usage[] = {\n \tN_(\"git stripspace [-s | --strip-comments]\"),\n \tN_(\"git stripspace [-c | --comment-lines]\"),\n+\tN_(\"git stripspace [-l | --line-count]\"),\n \tNULL\n };\n\n enum stripspace_mode {\n \tSTRIP_DEFAULT = 0,\n \tSTRIP_COMMENTS,\n-\tCOMMENT_LINES\n+\tCOMMENT_LINES,\n+\tLINE_COUNT\n };\n\n int cmd_stripspace(int argc, const char **argv, const char *prefix)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tenum stripspace_mode mode = STRIP_DEFAULT;\n+\tint count = 0;\n\n \tconst struct option options[] = {\n \t\tOPT_CMDMODE('s', \"strip-comments\", &mode,\n@@ -37,6 +53,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)\n \t\tOPT_CMDMODE('c', \"comment-lines\", &mode,\n \t\t\t    N_(\"prepend comment character and space to each line\"),\n \t\t\t    COMMENT_LINES),\n+\t\tOPT_BOOL('l', \"line-count\", &count, N_(\"count number of lines\")),\n \t\tOPT_END()\n \t};\n\n@@ -55,6 +72,9 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)\n \telse\n \t\tcomment_lines(&buf);\n\n+\tif (count)\n+\t\tcount_lines(&buf);\n+\n \twrite_or_die(1, buf.buf, buf.len);\n \tstrbuf_release(&buf);\n \treturn 0;\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex c0cfe88..e8bef37 100644\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -120,9 +120,9 @@ mark_action_done () {\n \tsed -e 1q < \"$todo\" >> \"$done\"\n \tsed -e 1d < \"$todo\" >> \"$todo\".new\n \tmv -f \"$todo\".new \"$todo\"\n-\tnew_count=$(git stripspace --strip-comments <\"$done\" | wc -l)\n+\tnew_count=$(git stripspace --strip-comments --line-count <\"$done\")\n \techo $new_count >\"$msgnum\"\n-\ttotal=$(($new_count + $(git stripspace --strip-comments <\"$todo\" | wc -l)))\n+\ttotal=$(($new_count + $(git stripspace --strip-comments --line-count <\"$todo\")))\n \techo $total >\"$end\"\n \tif test \"$last_count\" != \"$new_count\"\n \tthen\n@@ -1251,7 +1251,7 @@ test -s \"$todo\" || echo noop >> \"$todo\"\n test -n \"$autosquash\" && rearrange_squash \"$todo\"\n test -n \"$cmd\" && add_exec_commands \"$todo\"\n\n-todocount=$(git stripspace --strip-comments <\"$todo\" | wc -l)\n+todocount=$(git stripspace --strip-comments --line-count <\"$todo\")\n todocount=${todocount##* }\n\n cat >>\"$todo\" <<EOF\n--\n2.7.2\n"},{"id":"280205","messageId":"56D9D750.1030703@gmail.com","threadId":"41609","inReplyTo":"1457116723-20206-1-git-send-email-tigerkid001@gmail.com","subject":"Re: [PATCH] stripspace: add --line-count flag","fromName":"Sidhant Sharma","fromEmail":"tigerkid001@gmail.com","sentAt":"2016-03-04T18:43:28Z","receivedAt":"2016-03-04T18:43:28Z","isPatch":true,"sender":{"key":"tigerkid001@gmail.com","avatar":"https://avatars.githubusercontent.com/u/7801881?v=4"},"body":"\n>  builtin/stripspace.c       | 22 +++++++++++++++++++++-\n>  git-rebase--interactive.sh |  6 +++---\n>  2 files changed, 24 insertions(+), 4 deletions(-)\n>\nThis is my first attempt at the small project listed here: https://git.wiki.kernel.org/index.php/SmallProjectsIdeas#implement_.27--count-lines.27_in_.27git_stripspace.27.\nWith this, --line-count can be used with stripspace, instead of having to pipe its output to `wc -l` in git-rebase--interactive.sh. I went with --line-count and not --count-lines since its short form (-c) is already in use, and I think -l is more apt for this.\nComments?\n\n\nThanks and regards,\nSidhant Sharma [:tk]\n"},{"id":"280206","messageId":"xmqqk2liyt7j.fsf@gitster.mtv.corp.google.com","threadId":"41609","inReplyTo":"56D9D750.1030703@gmail.com","subject":"Re: [PATCH] stripspace: add --line-count flag","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-04T18:49:04Z","receivedAt":"2016-03-04T18:49:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sidhant Sharma <tigerkid001@gmail.com> writes:\n\n> This is my first attempt at the small project listed here: https://git.wiki.kernel.org/index.php/SmallProjectsIdeas#implement_.27--count-lines.27_in_.27git_stripspace.27.\n\n> Comments?\n\nIsn't that page somewhat stale?\n\nhttp://git.661346.n2.nabble.com/PATCH-0-3-stripspace-Implement-and-use-count-lines-option-tt7641360.html#none\n"},{"id":"280208","messageId":"56D9DA55.6040309@gmail.com","threadId":"41609","inReplyTo":"xmqqk2liyt7j.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] stripspace: add --line-count flag","fromName":"Sidhant Sharma","fromEmail":"tigerkid001@gmail.com","sentAt":"2016-03-04T18:56:21Z","receivedAt":"2016-03-04T18:56:21Z","isPatch":true,"sender":{"key":"tigerkid001@gmail.com","avatar":"https://avatars.githubusercontent.com/u/7801881?v=4"},"body":"\n\nOn Saturday 05 March 2016 12:19 AM, Junio C Hamano wrote:\n> Sidhant Sharma <tigerkid001@gmail.com> writes:\n>\n>> This is my first attempt at the small project listed here: https://git.wiki.kernel.org/index.php/SmallProjectsIdeas#implement_.27--count-lines.27_in_.27git_stripspace.27.\n>> Comments?\n> Isn't that page somewhat stale?\n>\n> http://git.661346.n2.nabble.com/PATCH-0-3-stripspace-Implement-and-use-count-lines-option-tt7641360.html#none\nOh, I should've checked first. My bad, I was just looking to get familiar with the codebase.\n\n\nThanks\n\nSidhant Sharma [:tk]\n"},{"id":"280209","messageId":"xmqqfuw6yste.fsf@gitster.mtv.corp.google.com","threadId":"41609","inReplyTo":"xmqqk2liyt7j.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] stripspace: add --line-count flag","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-04T18:57:33Z","receivedAt":"2016-03-04T18:57:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Sidhant Sharma <tigerkid001@gmail.com> writes:\n>\n>> This is my first attempt at the small project listed here: https://git.wiki.kernel.org/index.php/SmallProjectsIdeas#implement_.27--count-lines.27_in_.27git_stripspace.27.\n>\n>> Comments?\n>\n> Isn't that page somewhat stale?\n>\n> http://git.661346.n2.nabble.com/PATCH-0-3-stripspace-Implement-and-use-count-lines-option-tt7641360.html#none\n\nAnd its reroll:\n\n  http://thread.gmane.org/gmane.comp.version-control.git/279742\n\nThe discussion seems to indicate that we weren't in favor of\naddition of this feature at least back then, e.g.\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/279742/focus=279888\n"}]}