git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Yao Zhao <zhaox383@umn.edu>
To: sunshine@sunshineco.com
Cc: git@vger.kernel.org, Yao Zhao <zhaox383@umn.edu>
Subject: [PATCH/GSoC_v3] branch.c: turn nested if-else logic to table-driven
Date: Sun, 16 Mar 2014 01:08:23 -0500	[thread overview]
Message-ID: <1394950103-2264-1-git-send-email-zhaox383@umn.edu> (raw)
In-Reply-To: <CAPig+cRF_eQiGugR8TSks5ki375y-5wiQ7HWKyKRudJ5apd4cg@mail.gmail.com>

Signed-off-by: Yao Zhao <zhaox383@umn.edu>
---
 branch.c | 53 +++++++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 24 deletions(-)
Hello Eric,

Thank you and Junio for reviewing my code. It is really helpful to improve my code quality.

This is version 3 of patch. Previous address : http://thread.gmane.org/gmane.comp.version-control.git/243919. I do not use positional initializer because it is not allowed to use variable in it. I don't know if it's ok to use this redundant way to initialize "list".

I cannot find -v flag in documentation you indicated in last email so I use set-prefix to add it into prefix.
	
Now I am working on writing proposal for git project. I am really interested in last one, about improve git_config. I know it's important to get known about git_config first and have read documentation about it. But I am really confused about how to understand code of git_config. When user type in git config in terminal, what is the execute order of functions? How git config influence other git command? Does program read config file every time when they execuate config-related command?

Thank you,

Yao

diff --git a/branch.c b/branch.c
index 723a36b..1df30c7 100644
--- a/branch.c
+++ b/branch.c
@@ -53,7 +53,33 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
 	int remote_is_branch = starts_with(remote, "refs/heads/");
 	struct strbuf key = STRBUF_INIT;
 	int rebasing = should_setup_rebase(origin);
-
+	struct print_list {
+		const char *print_str;
+		const char *arg2; 
+		const char *arg3;
+	} ; 
+	struct print_list target;
+
+	struct print_list list[2][2][2];
+	list[0][0][0].print_str = N_("Branch %s set up to track local ref %s.");
+	list[0][0][0].arg2 = remote;
+	list[0][0][1].print_str = N_("Branch %s set up to track local ref %s by rebasing.");
+	list[0][0][1].arg2 = remote;
+	list[0][1][0].print_str = N_("Branch %s set up to track remote ref %s.");
+	list[0][1][0].arg2 = remote;
+	list[0][1][1].print_str = N_("Branch %s set up to track remote ref %s by rebasing.");
+	list[0][1][1].arg2 = remote;
+	list[1][0][0].print_str = N_("Branch %s set up to track local branch %s.");
+	list[1][0][0].arg2 =shortname;
+	list[1][0][1].print_str = N_("Branch %s set up to track local branch %s by rebasing.");
+	list[1][0][1].arg2 = shortname;
+	list[1][1][0].print_str = N_("Branch %s set up to track remote branch %s from %s.");
+	list[1][1][0].arg2 = shortname;
+	list[1][1][0].arg3 = origin;
+	list[1][1][1].print_str = N_("Branch %s set up to track remote branch %s from %s by rebasing.");
+	list[1][1][1].arg2 = shortname;
+	list[1][1][1].arg3 = origin;
+ 
 	if (remote_is_branch
 	    && !strcmp(local, shortname)
 	    && !origin) {
@@ -77,29 +103,8 @@ 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);
+			target = list[!!remote_is_branch][!!origin][!!rebasing];
+			printf_ln (_(target.print_str), local, target.arg2, target.arg3);
 	}
 }
 
-- 
1.8.3.2

  parent reply	other threads:[~2014-03-16  6:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-12  3:47 [PATCH] SoC 2014 MicroProject No.8:change multiple if-else statement to table-driven approach Yao Zhao
2014-03-12  9:21 ` Eric Sunshine
2014-03-13 20:20   ` [PATCH] GSoC Change multiple if-else statements to be table-driven Yao Zhao
2014-03-14  2:16     ` Eric Sunshine
2014-03-14 16:54       ` Junio C Hamano
2014-03-17  6:29         ` Eric Sunshine
2014-03-17  7:31           ` Junio C Hamano
2014-03-17 14:11             ` Michael Haggerty
2014-03-17 19:12               ` Junio C Hamano
2014-03-17 19:27               ` Eric Sunshine
2014-03-17 20:39                 ` Quint Guvernator
2014-03-16  6:08       ` Yao Zhao [this message]
2014-03-17  7:54         ` [PATCH/GSoC_v3] branch.c: turn nested if-else logic to table-driven Eric Sunshine

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1394950103-2264-1-git-send-email-zhaox383@umn.edu \
    --to=zhaox383@umn.edu \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).