[PATCH][GSOC] Selection of the verbose message is replaced with generated message in install_branch_config()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]