All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Johannes Sixt <j.sixt@viscovery.net>,
	Yaroslav Halchenko <debian@onerussian.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v5 1/5] fmt_merge_msg: Change fmt_merge_msg API to accept shortlog_len
Date: Mon, 23 Aug 2010 17:00:31 -0500	[thread overview]
Message-ID: <20100823220031.GA1308@burratino> (raw)
In-Reply-To: <1282494398-20542-2-git-send-email-artagnon@gmail.com>

Ramkumar Ramachandra wrote:

> Update the API of the fmt_merge_msg function to replace the the
> merge_summary argument with a new shortlog_len argument.

Even more, actually:

> +++ b/builtin.h
> @@ -14,9 +14,8 @@ extern const char git_more_info_string[];
>  extern void list_common_cmds_help(void);
>  extern const char *help_unknown_cmd(const char *cmd);
>  extern void prune_packed_objects(int);
> -extern int fmt_merge_msg(int merge_summary, struct strbuf *in,
> -	struct strbuf *out);
> -extern int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out);
> +extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
> +			 int merge_title, int shortlog_len);

This combines the public functions.  Nice, but probably worth a
mention in the log message.

The API does not make the sense of the merge_title argument clear:
should it be 1 when the caller provides a title or when fmt_merge_msg
should provide one?  There is not much I can see to do about that;
I'd just suggest making it clear in the commit message (so it can
be mentioned in the API docs, once they're written :)).

> @@ -357,9 +354,10 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
>  		die_errno("could not read input file");
>  	if (message) {
>  		strbuf_addstr(&output, message);
> -		ret = fmt_merge_msg_shortlog(&input, &output);
> +		ret = fmt_merge_msg(&input, &output, 0, 20);
>  	} else {
> -		ret = fmt_merge_msg(merge_summary, &input, &output);
> +		ret = fmt_merge_msg(&input, &output, 1,
> +				    merge_summary ? 20 : 0);

Could be further simplified:

	if (message)
		strbuf_addstr(&output, message);
	ret = fmt_merge_msg(&input, &output,
				message ? 0 : 1,
				merge_summary ? 20 : 0);

Not sure if that helps or not.

A part of me wishes that the constant 20 wouldn't be duplicated so much.
Would something like

	#define DEFAULT_MERGE_SHORTLOG_LEN 20

make sense?

> +++ b/builtin/merge.c
> @@ -1014,9 +1014,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
>  			merge_name(argv[i], &merge_names);
>  
>  		if (have_message && option_log)
> -			fmt_merge_msg_shortlog(&merge_names, &merge_msg);
> +			fmt_merge_msg(&merge_names, &merge_msg, 0, 20);
>  		else if (!have_message)
> -			fmt_merge_msg(option_log, &merge_names, &merge_msg);
> +			fmt_merge_msg(&merge_names, &merge_msg, 1,
> +				      option_log ? 20: 0);

Likewise.

The rest looks good.  So except for the commit message,

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

Thanks.

Here are the cleanups I mentioned.  Except for the #define, they
probably don't belong in this patch.
---
diff --git a/builtin.h b/builtin.h
index 7d18106..09b94ea 100644
--- a/builtin.h
+++ b/builtin.h
@@ -7,6 +7,8 @@
 #include "commit.h"
 #include "notes.h"
 
+#define DEFAULT_MERGE_LOG_LEN 20
+
 extern const char git_version_string[];
 extern const char git_usage_string[];
 extern const char git_more_info_string[];
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 4ed728a..7f06b95 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -352,13 +352,13 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
 
 	if (strbuf_read(&input, fileno(in), 0) < 0)
 		die_errno("could not read input file");
-	if (message) {
+
+	if (message)
 		strbuf_addstr(&output, message);
-		ret = fmt_merge_msg(&input, &output, 0, 20);
-	} else {
-		ret = fmt_merge_msg(&input, &output, 1,
-				    merge_summary ? 20 : 0);
-	}
+	ret = fmt_merge_msg(&input, &output,
+			    message ? 0 : 1,
+			    merge_summary ? DEFAULT_MERGE_LOG_LEN : 0);
+
 	if (ret)
 		return ret;
 	write_in_full(STDOUT_FILENO, output.buf, output.len);
diff --git a/builtin/merge.c b/builtin/merge.c
index 70ee412..d797853 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1000,15 +1000,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		for (i = 0; i < argc; i++)
 			merge_name(argv[i], &merge_names);
 
-		if (have_message && option_log)
-			fmt_merge_msg(&merge_names, &merge_msg, 0, 20);
-		else if (!have_message)
-			fmt_merge_msg(&merge_names, &merge_msg, 1,
-				      option_log ? 20: 0);
-
-
-		if (!(have_message && !option_log) && merge_msg.len)
-			strbuf_setlen(&merge_msg, merge_msg.len-1);
+		if (!have_message || option_log) {
+			fmt_merge_msg(&merge_names, &merge_msg, !have_message,
+				      option_log ? DEFAULT_MERGE_LOG_LEN : 0);
+			if (merge_msg.len)
+				strbuf_setlen(&merge_msg, merge_msg.len - 1);
+		}
 	}
 
 	if (head_invalid || !argc)
-- 

  reply	other threads:[~2010-08-23 22:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-22 16:26 [PATCH v5 0/5] merge --log configurability Ramkumar Ramachandra
2010-08-22 16:26 ` [PATCH v5 1/5] fmt_merge_msg: Change fmt_merge_msg API to accept shortlog_len Ramkumar Ramachandra
2010-08-23 22:00   ` Jonathan Nieder [this message]
2010-08-24 17:16     ` Junio C Hamano
2010-08-25  2:44       ` [PATCH rr/fmt-merge-msg] merge, fmt_merge_msg --log: default value is DEFAULT_MERGE_LOG_LEN Jonathan Nieder
2010-08-22 16:26 ` [PATCH v5 2/5] merge: Make '--log' an integer option for number of shortlog entries Ramkumar Ramachandra
2010-08-23 22:25   ` Jonathan Nieder
2010-08-25  4:50     ` Ramkumar Ramachandra
2010-08-22 16:26 ` [PATCH v5 3/5] merge: Make 'merge.log' an integer or boolean option Ramkumar Ramachandra
2010-08-24 19:01   ` Junio C Hamano
2010-08-25  3:52     ` Ramkumar Ramachandra
2010-08-22 16:26 ` [PATCH v5 4/5] fmt-merge-msg: Remove deprecated '--summary' option Ramkumar Ramachandra
2010-08-22 16:26 ` [PATCH v5 5/5] parse-options: clarify PARSE_OPT_NOARG description Ramkumar Ramachandra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100823220031.GA1308@burratino \
    --to=jrnieder@gmail.com \
    --cc=artagnon@gmail.com \
    --cc=debian@onerussian.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.