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

[PATCH 05/16] remote: remove dead code in read_branches_file()

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jun 21, 2013, 11:12 UTC
Message-ID
<1371813160-4200-6-git-send-email-artagnon@gmail.com>
In-Reply-To
<1371813160-4200-1-git-send-email-artagnon@gmail.com>

The first line of the function checks that the remote-name contains a slash ('/'), and sets the "slash" variable accordingly. The only caller of read_branches_file() is remote_get_1(); the calling codepath is guarded by valid_remote_nick(), which checks that the remote does not contain a slash. Therefore, the "slash" variable can never be set: remove the dead code that assumes otherwise.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 remote.c | 26 +++-----------------------
 1 file changed, 3 insertions(+), 23 deletions(-)
diff --git a/remote.c b/remote.c
index e71f66d..128b210 100644
--- a/remote.c
+++ b/remote.c
@@ -276,10 +276,9 @@ static void read_remotes_file(struct remote *remote)
 
 static void read_branches_file(struct remote *remote)
 {
-	const char *slash = strchr(remote->name, '/');
 	char *frag;
 	struct strbuf branch = STRBUF_INIT;
-	int n = slash ? slash - remote->name : 1000;
+	int n = 1000;
 	FILE *f = fopen(git_path("branches/%.*s", n, remote->name), "r");
 	char *s, *p;
 	int len;
@@ -299,36 +298,17 @@ static void read_branches_file(struct remote *remote)
 	while (isspace(p[-1]))
 		*--p = 0;
 	len = p - s;
-	if (slash)
-		len += strlen(slash);
 	p = xmalloc(len + 1);
 	strcpy(p, s);
-	if (slash)
-		strcat(p, slash);
 
-	/*
-	 * With "slash", e.g. "git fetch jgarzik/netdev-2.6" when
-	 * reading from $GIT_DIR/branches/jgarzik fetches "HEAD" from
-	 * the partial URL obtained from the branches file plus
-	 * "/netdev-2.6" and does not store it in any tracking ref.
-	 * #branch specifier in the file is ignored.
-	 *
-	 * Otherwise, the branches file would have URL and optionally
-	 * #branch specified.  The "master" (or specified) branch is
-	 * fetched and stored in the local branch of the same name.
-	 */
 	frag = strchr(p, '#');
 	if (frag) {
 		*(frag++) = '\0';
 		strbuf_addf(&branch, "refs/heads/%s", frag);
 	} else
 		strbuf_addstr(&branch, "refs/heads/master");
-	if (!slash) {
-		strbuf_addf(&branch, ":refs/heads/%s", remote->name);
-	} else {
-		strbuf_reset(&branch);
-		strbuf_addstr(&branch, "HEAD:");
-	}
+
+	strbuf_addf(&branch, ":refs/heads/%s", remote->name);
 	add_url_alias(remote, p);
 	add_fetch_refspec(remote, strbuf_detach(&branch, NULL));
 	/*
-- 
1.8.3.1.499.g7ad3486.dirty
Previous: Ramkumar RamachandraNext: Junio C Hamano
Message 13 of 43 in “Cleanup {branches,remotes}-file cruft”
  1. 00/16 Cleanup {branches,remotes}-file cruftRamkumar Ramachandra, Jun 21, 2013
  2. 01/16 t/t5505-remote: modernize subshell-style of one testRamkumar Ramachandra, Jun 21, 2013
  3. Junio C HamanoJun 21, 2013
  4. Ramkumar RamachandraJun 22, 2013
  5. 02/16 t/t5505-remote: test push-refspec in branches-fileRamkumar Ramachandra, Jun 21, 2013
  6. Junio C HamanoJun 21, 2013
  7. 03/16 t/t5505-remote: use test_path_is_missingRamkumar Ramachandra, Jun 21, 2013
  8. 04/16 t/t5505-remote: remove dependency on $origin_urlRamkumar Ramachandra, Jun 21, 2013
  9. Junio C HamanoJun 21, 2013
  10. Ramkumar RamachandraJun 22, 2013
  11. Junio C HamanoJun 22, 2013
  12. Ramkumar RamachandraJun 23, 2013
  13. 05/16 remote: remove dead code in read_branches_file()Ramkumar Ramachandra, Jun 21, 2013
  14. Junio C HamanoJun 21, 2013
  15. Ramkumar RamachandraJun 22, 2013
  16. Junio C HamanoJun 23, 2013
  17. Ramkumar RamachandraJun 23, 2013
  18. Junio C HamanoJun 23, 2013
  19. 06/16 t/t5505-remote: test url-with-# in branches-fileRamkumar Ramachandra, Jun 21, 2013
  20. Junio C HamanoJun 21, 2013
  21. Ramkumar RamachandraJun 22, 2013
  22. 07/16 t/t5516-fetch-push: don't use branches-fileRamkumar Ramachandra, Jun 21, 2013
  23. Junio C HamanoJun 21, 2013
  24. 08/16 t/t5516-fetch-push: use test_config()Ramkumar Ramachandra, Jun 21, 2013
  25. Junio C HamanoJun 21, 2013
  26. Ramkumar RamachandraJun 22, 2013
  27. Johannes SixtJun 22, 2013
  28. 09/16 ls-remote doc: fix example invocation on git.gitRamkumar Ramachandra, Jun 21, 2013
  29. Junio C HamanoJun 21, 2013
  30. 10/16 ls-remote doc: rewrite <repository> paragraphRamkumar Ramachandra, Jun 21, 2013
  31. Junio C HamanoJun 21, 2013
  32. 11/16 ls-remote doc: don't encourage use of branches-fileRamkumar Ramachandra, Jun 21, 2013
  33. 12/16 t/t5505-remote: modernize subshell-style of one testRamkumar Ramachandra, Jun 21, 2013
  34. 13/16 t/t5505-remote: test multiple push/pull in remotes-fileRamkumar Ramachandra, Jun 21, 2013
  35. Eric SunshineJun 21, 2013
  36. Ramkumar RamachandraJun 22, 2013
  37. 14/16 t/t5510-fetch: don't use remotes-fileRamkumar Ramachandra, Jun 21, 2013
  38. 15/16 t/t5515-fetch-merge-logic: don't use {branches,remotes}-fileRamkumar Ramachandra, Jun 21, 2013
  39. 16/16 remote: deprecate read_{branches,remotes}_fileRamkumar Ramachandra, Jun 21, 2013
  40. Junio C HamanoJun 21, 2013
  41. Ramkumar RamachandraJun 21, 2013
  42. Junio C HamanoJun 21, 2013
  43. Ramkumar RamachandraJun 21, 2013

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.