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

[PATCH 1/4] remote: use skip_prefix

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Feb 15, 2016, 17:42 UTC
Message-ID
<1455558150-30267-2-git-send-email-t.gummerer@gmail.com>
In-Reply-To
<1455558150-30267-1-git-send-email-t.gummerer@gmail.com>

95b567c7 ("use skip_prefix to avoid repeating strings") transformed calls using starts_with() and then skipping the length of the prefix to skip_prefix() calls. In remote.c there are a few calls like:

  if (starts_with(foo, "bar"))
      foo += 3

These calls weren't touched by the commit mentioned above, but can benefit from the same treatment to avoid magic numbers.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
 remote.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/remote.c b/remote.c
index 02e698a..4b5b576 100644
--- a/remote.c
+++ b/remote.c
@@ -321,8 +321,7 @@ static int handle_config(const char *key, const char *value, void *cb)
 	const char *subkey;
 	struct remote *remote;
 	struct branch *branch;
-	if (starts_with(key, "branch.")) {
-		name = key + 7;
+	if (skip_prefix(key, "branch.", &name)) {
 		subkey = strrchr(name, '.');
 		if (!subkey)
 			return 0;
@@ -338,9 +337,8 @@ static int handle_config(const char *key, const char *value, void *cb)
 		}
 		return 0;
 	}
-	if (starts_with(key, "url.")) {
+	if (skip_prefix(key, "url.", &name)) {
 		struct rewrite *rewrite;
-		name = key + 4;
 		subkey = strrchr(name, '.');
 		if (!subkey)
 			return 0;
@@ -357,9 +355,8 @@ static int handle_config(const char *key, const char *value, void *cb)
 		}
 	}
 
-	if (!starts_with(key,  "remote."))
+	if (!skip_prefix(key, "remote.", &name))
 		return 0;
-	name = key + 7;
 
 	/* Handle remote.* variables */
 	if (!strcmp(name, "pushdefault"))
-- 
2.7.1.410.g6faf27b
Previous: Thomas GummererNext: Jeff King
Message 2 of 18 in “git remote improvements”
  1. 0/4 git remote improvementsThomas Gummerer, Feb 15, 2016
  2. 1/4 remote: use skip_prefixThomas Gummerer, Feb 15, 2016
  3. Jeff KingFeb 15, 2016
  4. Eric SunshineFeb 15, 2016
  5. Jeff KingFeb 15, 2016
  6. Thomas GummererFeb 15, 2016
  7. 2/4 remote: simplify remote_is_configured()Thomas Gummerer, Feb 15, 2016
  8. Jeff KingFeb 15, 2016
  9. Thomas GummererFeb 15, 2016
  10. Junio C HamanoFeb 15, 2016
  11. 3/4 remote: actually check if remote exitsThomas Gummerer, Feb 15, 2016
  12. Jeff KingFeb 15, 2016
  13. 4/4 remote: use remote_is_configured() for add and renameThomas Gummerer, Feb 15, 2016
  14. Jeff KingFeb 15, 2016
  15. Thomas GummererFeb 15, 2016
  16. Johannes SchindelinFeb 17, 2016
  17. Thomas GummererFeb 17, 2016
  18. Johannes SchindelinFeb 17, 2016

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.