* [PATCH] stripspace: add --line-count flag
@ 2016-03-04 18:38 Sidhant Sharma [:tk]
2016-03-04 18:43 ` Sidhant Sharma
0 siblings, 1 reply; 5+ messages in thread
From: Sidhant Sharma [:tk] @ 2016-03-04 18:38 UTC (permalink / raw)
To: git
When used, this flag outputs number of lines after stripspace has removed trailing whitespace.
With `--line-count`, git-rebase--interactive.sh need not rely on `wc -l` for line
count.
Signed-off-by: Sidhant Sharma [:tk] <tigerkid001@gmail.com>
---
This the first version of the patch for the small project listed here:
https://git.wiki.kernel.org/index.php/SmallProjectsIdeas#implement_.27--count-lines.27_in_.27git_stripspace.27
builtin/stripspace.c | 22 +++++++++++++++++++++-
git-rebase--interactive.sh | 6 +++---
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 15e716e..e08da03 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -13,22 +13,38 @@ static void comment_lines(struct strbuf *buf)
free(msg);
}
+static void count_lines(struct strbuf *buf)
+{
+ size_t len = 0;
+ int i;
+
+ for (i = 0; i < buf->len; i++)
+ if (buf->buf[i] == '\n')
+ len++;
+
+ sprintf(buf->buf, "%zu", len);
+ buf->len = strlen(buf->buf);
+}
+
static const char * const stripspace_usage[] = {
N_("git stripspace [-s | --strip-comments]"),
N_("git stripspace [-c | --comment-lines]"),
+ N_("git stripspace [-l | --line-count]"),
NULL
};
enum stripspace_mode {
STRIP_DEFAULT = 0,
STRIP_COMMENTS,
- COMMENT_LINES
+ COMMENT_LINES,
+ LINE_COUNT
};
int cmd_stripspace(int argc, const char **argv, const char *prefix)
{
struct strbuf buf = STRBUF_INIT;
enum stripspace_mode mode = STRIP_DEFAULT;
+ int count = 0;
const struct option options[] = {
OPT_CMDMODE('s', "strip-comments", &mode,
@@ -37,6 +53,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
OPT_CMDMODE('c', "comment-lines", &mode,
N_("prepend comment character and space to each line"),
COMMENT_LINES),
+ OPT_BOOL('l', "line-count", &count, N_("count number of lines")),
OPT_END()
};
@@ -55,6 +72,9 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
else
comment_lines(&buf);
+ if (count)
+ count_lines(&buf);
+
write_or_die(1, buf.buf, buf.len);
strbuf_release(&buf);
return 0;
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index c0cfe88..e8bef37 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -120,9 +120,9 @@ mark_action_done () {
sed -e 1q < "$todo" >> "$done"
sed -e 1d < "$todo" >> "$todo".new
mv -f "$todo".new "$todo"
- new_count=$(git stripspace --strip-comments <"$done" | wc -l)
+ new_count=$(git stripspace --strip-comments --line-count <"$done")
echo $new_count >"$msgnum"
- total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
+ total=$(($new_count + $(git stripspace --strip-comments --line-count <"$todo")))
echo $total >"$end"
if test "$last_count" != "$new_count"
then
@@ -1251,7 +1251,7 @@ test -s "$todo" || echo noop >> "$todo"
test -n "$autosquash" && rearrange_squash "$todo"
test -n "$cmd" && add_exec_commands "$todo"
-todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
+todocount=$(git stripspace --strip-comments --line-count <"$todo")
todocount=${todocount##* }
cat >>"$todo" <<EOF
--
2.7.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] stripspace: add --line-count flag
2016-03-04 18:38 [PATCH] stripspace: add --line-count flag Sidhant Sharma [:tk]
@ 2016-03-04 18:43 ` Sidhant Sharma
2016-03-04 18:49 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Sidhant Sharma @ 2016-03-04 18:43 UTC (permalink / raw)
To: git
> builtin/stripspace.c | 22 +++++++++++++++++++++-
> git-rebase--interactive.sh | 6 +++---
> 2 files changed, 24 insertions(+), 4 deletions(-)
>
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.
With 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.
Comments?
Thanks and regards,
Sidhant Sharma [:tk]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] stripspace: add --line-count flag
2016-03-04 18:43 ` Sidhant Sharma
@ 2016-03-04 18:49 ` Junio C Hamano
2016-03-04 18:56 ` Sidhant Sharma
2016-03-04 18:57 ` Junio C Hamano
0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2016-03-04 18:49 UTC (permalink / raw)
To: Sidhant Sharma; +Cc: git
Sidhant Sharma <tigerkid001@gmail.com> writes:
> 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.
> Comments?
Isn't that page somewhat stale?
http://git.661346.n2.nabble.com/PATCH-0-3-stripspace-Implement-and-use-count-lines-option-tt7641360.html#none
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] stripspace: add --line-count flag
2016-03-04 18:49 ` Junio C Hamano
@ 2016-03-04 18:56 ` Sidhant Sharma
2016-03-04 18:57 ` Junio C Hamano
1 sibling, 0 replies; 5+ messages in thread
From: Sidhant Sharma @ 2016-03-04 18:56 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
On Saturday 05 March 2016 12:19 AM, Junio C Hamano wrote:
> Sidhant Sharma <tigerkid001@gmail.com> writes:
>
>> 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.
>> Comments?
> Isn't that page somewhat stale?
>
> http://git.661346.n2.nabble.com/PATCH-0-3-stripspace-Implement-and-use-count-lines-option-tt7641360.html#none
Oh, I should've checked first. My bad, I was just looking to get familiar with the codebase.
Thanks
Sidhant Sharma [:tk]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] stripspace: add --line-count flag
2016-03-04 18:49 ` Junio C Hamano
2016-03-04 18:56 ` Sidhant Sharma
@ 2016-03-04 18:57 ` Junio C Hamano
1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2016-03-04 18:57 UTC (permalink / raw)
To: Sidhant Sharma; +Cc: git
Junio C Hamano <gitster@pobox.com> writes:
> Sidhant Sharma <tigerkid001@gmail.com> writes:
>
>> 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.
>
>> Comments?
>
> Isn't that page somewhat stale?
>
> http://git.661346.n2.nabble.com/PATCH-0-3-stripspace-Implement-and-use-count-lines-option-tt7641360.html#none
And its reroll:
http://thread.gmane.org/gmane.comp.version-control.git/279742
The discussion seems to indicate that we weren't in favor of
addition of this feature at least back then, e.g.
http://thread.gmane.org/gmane.comp.version-control.git/279742/focus=279888
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-03-04 18:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-04 18:38 [PATCH] stripspace: add --line-count flag Sidhant Sharma [:tk]
2016-03-04 18:43 ` Sidhant Sharma
2016-03-04 18:49 ` Junio C Hamano
2016-03-04 18:56 ` Sidhant Sharma
2016-03-04 18:57 ` Junio C Hamano
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).