git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Aleksey Mokhovikov <moxobukob@gmail.com>
To: git@vger.kernel.org
Cc: Aleksey Mokhovikov <moxobukob@gmail.com>
Subject: [PATCH][GSOC] Selection of the verbose message is replaced with generated message in install_branch_config()
Date: Mon, 17 Mar 2014 16:55:04 +0700	[thread overview]
Message-ID: <1395050104-19152-1-git-send-email-moxobukob@gmail.com> (raw)


This is a milliproject from git google summer of code page. The current code that selects the output message is quite easy to understand. So I tried to improve it by removing nested conditions and code duplication. The output string is generated by selecting the proper parts of the message and concatenating them the into one template string.  


 
Signed-off-by: Aleksey Mokhovikov <moxobukob@gmail.com>
---
 branch.c | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/branch.c b/branch.c
index 723a36b..2ee353f 100644
--- a/branch.c
+++ b/branch.c
@@ -77,29 +77,22 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
 	strbuf_release(&key);
 
 	if (flag & BRANCH_CONFIG_VERBOSE) {
-		if (remote_is_branch && origin)
-			printf_ln(rebasing ?
-				  _("Branch %s set up to track remote branch %s from %s by rebasing.") :
-				  _("Branch %s set up to track remote branch %s from %s."),
-				  local, shortname, origin);
-		else if (remote_is_branch && !origin)
-			printf_ln(rebasing ?
-				  _("Branch %s set up to track local branch %s by rebasing.") :
-				  _("Branch %s set up to track local branch %s."),
-				  local, shortname);
-		else if (!remote_is_branch && origin)
-			printf_ln(rebasing ?
-				  _("Branch %s set up to track remote ref %s by rebasing.") :
-				  _("Branch %s set up to track remote ref %s."),
-				  local, remote);
-		else if (!remote_is_branch && !origin)
-			printf_ln(rebasing ?
-				  _("Branch %s set up to track local ref %s by rebasing.") :
-				  _("Branch %s set up to track local ref %s."),
-				  local, remote);
-		else
-			die("BUG: impossible combination of %d and %p",
-			    remote_is_branch, origin);
+		const char *message_template_parts[] = {
+			"Branch %s set up to track",
+			origin ? " remote" : " local",
+			remote_is_branch ? " branch %s" : " ref %s",
+			(remote_is_branch && origin) ? " from %s" : "",
+			rebasing ? " by rebasing." : "."};
+		struct strbuf message_template = STRBUF_INIT;
+		size_t i = 0;
+		
+		for (i = 0; i < sizeof(message_template_parts)/sizeof(const char *); ++i) {
+			strbuf_addstr(&message_template, message_template_parts[i]);
+		}
+		
+		printf_ln(_(message_template.buf), local, remote_is_branch ? shortname : remote, origin);
+		
+		strbuf_release(&message_template);
 	}
 }
 
-- 
1.8.3.2

             reply	other threads:[~2014-03-17  9:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-17  9:55 Aleksey Mokhovikov [this message]
2014-03-17 10:01 ` [PATCH][GSOC] Selection of the verbose message is replaced with generated message in install_branch_config() Matthieu Moy
2014-03-18 14:42   ` Aleksey Mokhovikov
2014-03-17 10:53 ` Eric Sunshine
2014-03-18 14:37   ` Aleksey Mokhovikov
2014-03-18 12:22 ` Aleksey Mokhovikov
2014-03-18 14:33   ` Aleksey Mokhovikov
2014-03-19  9:21     ` Eric Sunshine
2014-03-20 11:56       ` Aleksey Mokhovikov
2014-03-21  4:03         ` Eric Sunshine
2014-03-21 17:09           ` Junio C Hamano
2014-03-21 21:13             ` Michael Haggerty
2014-03-21 21:33               ` Eric Sunshine
2014-03-21 21:45                 ` Michael Haggerty
2014-03-24  7:28               ` Aleksey Mokhovikov
2014-03-24 12:22                 ` Michael Haggerty

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=1395050104-19152-1-git-send-email-moxobukob@gmail.com \
    --to=moxobukob@gmail.com \
    --cc=git@vger.kernel.org \
    /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 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).