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

[PATCH 14/21] builtin-remote: rename variables and eliminate redundant function call

From
Jay Soffian <jaysoffian@gmail.com>
Date
Feb 25, 2009, 08:32 UTC
Message-ID
<a21a51f2e43118267f515e8947915cf8c5c512e4.1235546708.git.jaysoffian@gmail.com>
In-Reply-To
<cover.1235546707.git.jaysoffian@gmail.com>
- The variable name "remote" is used as both a "char *" and as a "struct
  remote *"; this is confusing, so rename the former to remote_name.
- Consistently refer to the refs returned by transport_get_remote_refs()
  as remote_refs.
- There is no need to call "sort_string_list(&branch_list)" as
  branch_list is populated via string_list_insert(), which maintains its
  order.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
In the original series this is two commits, but after re-ordering it
made sense to squash the two together as they were both very minimal.
 builtin-remote.c |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 3e6dee4..fc02e5f 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -143,7 +143,7 @@ static int add(int argc, const char **argv)
 }
 
 struct branch_info {
-	char *remote;
+	char *remote_name;
 	struct string_list merge;
 };
 
@@ -182,9 +182,9 @@ static int config_read_branches(const char *key, const char *value, void *cb)
 			item->util = xcalloc(sizeof(struct branch_info), 1);
 		info = item->util;
 		if (type == REMOTE) {
-			if (info->remote)
+			if (info->remote_name)
 				warning("more than one branch.%s", key);
-			info->remote = xstrdup(value);
+			info->remote_name = xstrdup(value);
 		} else {
 			char *space = strchr(value, ' ');
 			value = abbrev_branch(value);
@@ -206,7 +206,6 @@ static void read_branches(void)
 	if (branch_list.nr)
 		return;
 	git_config(config_read_branches, NULL);
-	sort_string_list(&branch_list);
 }
 
 struct ref_states {
@@ -238,13 +237,14 @@ static int handle_one_branch(const char *refname,
 	return 0;
 }
 
-static int get_ref_states(const struct ref *ref, struct ref_states *states)
+static int get_ref_states(const struct ref *remote_refs, struct ref_states *states)
 {
 	struct ref *fetch_map = NULL, **tail = &fetch_map;
+	struct ref *ref;
 	int i;
 
 	for (i = 0; i < states->remote->fetch_refspec_nr; i++)
-		if (get_fetch_map(ref, states->remote->fetch + i, &tail, 1))
+		if (get_fetch_map(remote_refs, states->remote->fetch + i, &tail, 1))
 			die("Could not get fetch map for refspec %s",
 				states->remote->fetch_refspec[i]);
 
@@ -459,7 +459,7 @@ static int mv(int argc, const char **argv)
 	for (i = 0; i < branch_list.nr; i++) {
 		struct string_list_item *item = branch_list.items + i;
 		struct branch_info *info = item->util;
-		if (info->remote && !strcmp(info->remote, rename.old)) {
+		if (info->remote_name && !strcmp(info->remote_name, rename.old)) {
 			strbuf_reset(&buf);
 			strbuf_addf(&buf, "branch.%s.remote", item->string);
 			if (git_config_set(buf.buf, rename.new)) {
@@ -569,7 +569,7 @@ static int rm(int argc, const char **argv)
 	for (i = 0; i < branch_list.nr; i++) {
 		struct string_list_item *item = branch_list.items + i;
 		struct branch_info *info = item->util;
-		if (info->remote && !strcmp(info->remote, remote->name)) {
+		if (info->remote_name && !strcmp(info->remote_name, remote->name)) {
 			const char *keys[] = { "remote", "merge", NULL }, **k;
 			for (k = keys; *k; k++) {
 				strbuf_reset(&buf);
@@ -637,7 +637,7 @@ static int get_remote_ref_states(const char *name,
 				 int query)
 {
 	struct transport *transport;
-	const struct ref *ref;
+	const struct ref *remote_refs;
 
 	states->remote = remote_get(name);
 	if (!states->remote)
@@ -648,10 +648,10 @@ static int get_remote_ref_states(const char *name,
 	if (query) {
 		transport = transport_get(NULL, states->remote->url_nr > 0 ?
 			states->remote->url[0] : NULL);
-		ref = transport_get_remote_refs(transport);
+		remote_refs = transport_get_remote_refs(transport);
 		transport_disconnect(transport);
 
-		get_ref_states(ref, states);
+		get_ref_states(remote_refs, states);
 	}
 
 	return 0;
@@ -701,7 +701,7 @@ static int show(int argc, const char **argv)
 			struct branch_info *info = branch->util;
 			int j;
 
-			if (!info->merge.nr || strcmp(*argv, info->remote))
+			if (!info->merge.nr || strcmp(*argv, info->remote_name))
 				continue;
 			printf("  Remote branch%s merged with 'git pull' "
 				"while on branch %s\n   ",
-- 
1.6.2.rc1.291.g83eb
Previous: Jay SoffianNext: Jay Soffian
Message 19 of 28 in “git remote: set-head and new show output”
  1. 00/21 git remote: set-head and new show outputJay Soffian, Feb 25, 2009
  2. 01/21 test scripts: refactor start_httpd helperJay Soffian, Feb 25, 2009
  3. 02/21 add basic http clone/fetch testsJay Soffian, Feb 25, 2009
  4. 03/21 refactor find_ref_by_name() to accept const listJay Soffian, Feb 25, 2009
  5. 04/21 move duplicated get_local_heads() to remote.cJay Soffian, Feb 25, 2009
  6. 05/21 move duplicated ref_newer() to remote.cJay Soffian, Feb 25, 2009
  7. 06/21 move locate_head() to remote.cJay Soffian, Feb 25, 2009
  8. 07/21 remote: simplify guess_remote_head()Jay Soffian, Feb 25, 2009
  9. 08/21 remote: let guess_remote_head() optionally return all matchesJay Soffian, Feb 25, 2009
  10. Jeff KingFeb 26, 2009
  11. Jeff KingFeb 26, 2009
  12. Jay SoffianFeb 26, 2009
  13. Jeff KingFeb 27, 2009
  14. 09/21 remote: make match_refs() copy src ref before assigning to peer_refJay Soffian, Feb 25, 2009
  15. 10/21 remote: make match_refs() not short-circuitJay Soffian, Feb 25, 2009
  16. 11/21 string-list: new for_each_string_list() functionJay Soffian, Feb 25, 2009
  17. 12/21 builtin-remote: refactor duplicated cleanup codeJay Soffian, Feb 25, 2009
  18. 13/21 builtin-remote: remove unused code in get_ref_statesJay Soffian, Feb 25, 2009
  19. 14/21 builtin-remote: rename variables and eliminate redundant function callJay Soffian, Feb 25, 2009
  20. 15/21 builtin-remote: make get_remote_ref_states() always populate states.trackedJay Soffian, Feb 25, 2009
  21. 16/21 builtin-remote: fix two inconsistencies in the output of "show <remote>"Jay Soffian, Feb 25, 2009
  22. 17/21 builtin-remote: teach show to display remote HEADJay Soffian, Feb 25, 2009
  23. 18/21 builtin-remote: add set-head subcommandJay Soffian, Feb 25, 2009
  24. 19/21 remote: make guess_remote_head() use exact HEAD lookup if it is availableJay Soffian, Feb 25, 2009
  25. 20/21 builtin-remote: new show output styleJay Soffian, Feb 25, 2009
  26. 21/21 builtin-remote: new show output style for push refspecsJay Soffian, Feb 25, 2009
  27. Jeff KingFeb 26, 2009
  28. Junio C HamanoFeb 26, 2009

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.