git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] SoC 2014 MicroProject No.8:change multiple if-else statement to table-driven approach

From
YZYao Zhao <zhaox383@umn.edu>
Date
Mar 12, 2014, 03:47 UTC
Message-ID
<1394596049-8767-1-git-send-email-zhaox383@umn.edu>
In-Reply-To
<zhaox383@umn.edu>
Signed-off-by: Yao Zhao <zhaox383@umn.edu>
---
 branch.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 2 deletions(-)
diff --git a/branch.c b/branch.c
index 723a36b..6432e27 100644
--- a/branch.c
+++ b/branch.c
@@ -53,7 +53,20 @@ 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);
-
+	char** print_list = malloc(8 * sizeof(char*));
+	char* arg1=NULL;
+	char* arg2=NULL;
+	char* arg3=NULL;
+	int index=0;
+
+	print_list[7] = _("Branch %s set up to track remote branch %s from %s by rebasing.");
+	print_list[6] = _("Branch %s set up to track remote branch %s from %s.");
+	print_list[5] = _("Branch %s set up to track local branch %s by rebasing.");
+	print_list[4] = _("Branch %s set up to track local branch %s.");
+	print_list[3] = _("Branch %s set up to track remote ref %s by rebasing.");
+	print_list[2] = _("Branch %s set up to track remote ref %s.");
+	print_list[1] = _("Branch %s set up to track local ref %s by rebasing.");
+	print_list[0] = _("Branch %s set up to track local ref %s.");
 	if (remote_is_branch
 	    && !strcmp(local, shortname)
 	    && !origin) {
@@ -77,7 +90,44 @@ 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)
+		if(remote_is_branch)
+				index += 4;
+		if(origin)
+				index += 2;
+		if(rebasing)
+				index += 1;
+		
+		if(index < 0 || index > 7)
+		{
+			die("BUG: impossible combination of %d and %p",
+			    remote_is_branch, origin);
+		}
+
+		if(index <= 4) {
+			arg1 = local;
+			arg2 = remote;
+		}
+		else if(index > 6) {
+			arg1 = local;
+			arg2 = shortname;
+			arg3 = origin;
+		}
+		else {
+			arg1 = local;
+			arg2 = shortname;
+		}
+
+		if(!arg3) {
+			printf_ln(print_list[index],arg1,arg2);
+		}
+		else {
+			printf_ln(print_list[index],arg1,arg2,arg3);
+		}
+
+		free(print_list);
+
+
+/*		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."),
@@ -100,6 +150,7 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
 		else
 			die("BUG: impossible combination of %d and %p",
 			    remote_is_branch, origin);
+*/
 	}
 }
 
-- 
1.8.3.2
Next: Eric Sunshine
Message 1 of 13 in “SoC 2014 MicroProject No.8:change multiple if-else statement to table-driven approach”
  1. SoC 2014 MicroProject No.8:change multiple if-else statement to table-driven approachYao Zhao, Mar 12, 2014
  2. Eric SunshineMar 12, 2014
  3. GSoC Change multiple if-else statements to be table-drivenYao Zhao, Mar 13, 2014
  4. Eric SunshineMar 14, 2014
  5. Junio C HamanoMar 14, 2014
  6. Eric SunshineMar 17, 2014
  7. Junio C HamanoMar 17, 2014
  8. Michael HaggertyMar 17, 2014
  9. Junio C HamanoMar 17, 2014
  10. Eric SunshineMar 17, 2014
  11. Quint GuvernatorMar 17, 2014
  12. branch.c: turn nested if-else logic to table-drivenYao Zhao, Mar 16, 2014
  13. Eric SunshineMar 17, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.