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

[PATCH 04/86] remote*: replace prefixcmd() with has_prefix()

From
Christian Couder <chriscool@tuxfamily.org>
Date
Nov 9, 2013, 07:05 UTC
Message-ID
<20131109070720.18178.98413.chriscool@tuxfamily.org>
In-Reply-To
<20131109070358.18178.40248.chriscool@tuxfamily.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 remote-curl.c    | 14 +++++++-------
 remote-testsvn.c | 10 +++++-----
 remote.c         | 46 +++++++++++++++++++++++-----------------------
 3 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index b5ebe01..437b863 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -212,7 +212,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
 	free_discovery(last);
 
 	strbuf_addf(&buffer, "%sinfo/refs", url);
-	if ((!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) &&
+	if ((has_prefix(url, "http://") || has_prefix(url, "https://")) &&
 	     git_env_bool("GIT_SMART_HTTP", 1)) {
 		maybe_smart = 1;
 		if (!strchr(url, '?'))
@@ -740,7 +740,7 @@ static void parse_fetch(struct strbuf *buf)
 	int alloc_heads = 0, nr_heads = 0;
 
 	do {
-		if (!prefixcmp(buf->buf, "fetch ")) {
+		if (has_prefix(buf->buf, "fetch ")) {
 			char *p = buf->buf + strlen("fetch ");
 			char *name;
 			struct ref *ref;
@@ -863,7 +863,7 @@ static void parse_push(struct strbuf *buf)
 	int alloc_spec = 0, nr_spec = 0, i, ret;
 
 	do {
-		if (!prefixcmp(buf->buf, "push ")) {
+		if (has_prefix(buf->buf, "push ")) {
 			ALLOC_GROW(specs, nr_spec + 1, alloc_spec);
 			specs[nr_spec++] = xstrdup(buf->buf + 5);
 		}
@@ -928,19 +928,19 @@ int main(int argc, const char **argv)
 		}
 		if (buf.len == 0)
 			break;
-		if (!prefixcmp(buf.buf, "fetch ")) {
+		if (has_prefix(buf.buf, "fetch ")) {
 			if (nongit)
 				die("Fetch attempted without a local repo");
 			parse_fetch(&buf);
 
-		} else if (!strcmp(buf.buf, "list") || !prefixcmp(buf.buf, "list ")) {
+		} else if (!strcmp(buf.buf, "list") || has_prefix(buf.buf, "list ")) {
 			int for_push = !!strstr(buf.buf + 4, "for-push");
 			output_refs(get_refs(for_push));
 
-		} else if (!prefixcmp(buf.buf, "push ")) {
+		} else if (has_prefix(buf.buf, "push ")) {
 			parse_push(&buf);
 
-		} else if (!prefixcmp(buf.buf, "option ")) {
+		} else if (has_prefix(buf.buf, "option ")) {
 			char *name = buf.buf + strlen("option ");
 			char *value = strchr(name, ' ');
 			int result;
diff --git a/remote-testsvn.c b/remote-testsvn.c
index d7cd5d2..7a5d4c8 100644
--- a/remote-testsvn.c
+++ b/remote-testsvn.c
@@ -82,7 +82,7 @@ static int parse_rev_note(const char *msg, struct rev_note *res)
 		len = end ? end - msg : strlen(msg);
 
 		key = "Revision-number: ";
-		if (!prefixcmp(msg, key)) {
+		if (has_prefix(msg, key)) {
 			long i;
 			char *end;
 			value = msg + strlen(key);
@@ -154,7 +154,7 @@ static void check_or_regenerate_marks(int latestrev)
 	} else {
 		strbuf_addf(&sb, ":%d ", latestrev);
 		while (strbuf_getline(&line, marksfile, '\n') != EOF) {
-			if (!prefixcmp(line.buf, sb.buf)) {
+			if (has_prefix(line.buf, sb.buf)) {
 				found++;
 				break;
 			}
@@ -264,7 +264,7 @@ static int do_command(struct strbuf *line)
 		return 1;	/* end of command stream, quit */
 	}
 	if (batch_cmd) {
-		if (prefixcmp(batch_cmd->name, line->buf))
+		if (!has_prefix(batch_cmd->name, line->buf))
 			die("Active %s batch interrupted by %s", batch_cmd->name, line->buf);
 		/* buffer batch lines */
 		string_list_append(&batchlines, line->buf);
@@ -272,7 +272,7 @@ static int do_command(struct strbuf *line)
 	}
 
 	for (p = input_command_list; p->name; p++) {
-		if (!prefixcmp(line->buf, p->name) && (strlen(p->name) == line->len ||
+		if (has_prefix(line->buf, p->name) && (strlen(p->name) == line->len ||
 				line->buf[strlen(p->name)] == ' ')) {
 			if (p->batchable) {
 				batch_cmd = p;
@@ -304,7 +304,7 @@ int main(int argc, char **argv)
 	remote = remote_get(argv[1]);
 	url_in = (argc == 3) ? argv[2] : remote->url[0];
 
-	if (!prefixcmp(url_in, "file://")) {
+	if (has_prefix(url_in, "file://")) {
 		dump_from_file = 1;
 		url = url_decode(url_in + sizeof("file://")-1);
 	} else {
diff --git a/remote.c b/remote.c
index e9fedfa..84c0d9f 100644
--- a/remote.c
+++ b/remote.c
@@ -76,7 +76,7 @@ static const char *alias_url(const char *url, struct rewrites *r)
 		if (!r->rewrite[i])
 			continue;
 		for (j = 0; j < r->rewrite[i]->instead_of_nr; j++) {
-			if (!prefixcmp(url, r->rewrite[i]->instead_of[j].s) &&
+			if (has_prefix(url, r->rewrite[i]->instead_of[j].s) &&
 			    (!longest ||
 			     longest->len < r->rewrite[i]->instead_of[j].len)) {
 				longest = &(r->rewrite[i]->instead_of[j]);
@@ -239,13 +239,13 @@ static void read_remotes_file(struct remote *remote)
 		int value_list;
 		char *s, *p;
 
-		if (!prefixcmp(buffer, "URL:")) {
+		if (has_prefix(buffer, "URL:")) {
 			value_list = 0;
 			s = buffer + 4;
-		} else if (!prefixcmp(buffer, "Push:")) {
+		} else if (has_prefix(buffer, "Push:")) {
 			value_list = 1;
 			s = buffer + 5;
-		} else if (!prefixcmp(buffer, "Pull:")) {
+		} else if (has_prefix(buffer, "Pull:")) {
 			value_list = 2;
 			s = buffer + 5;
 		} else
@@ -337,7 +337,7 @@ static int handle_config(const char *key, const char *value, void *cb)
 	const char *subkey;
 	struct remote *remote;
 	struct branch *branch;
-	if (!prefixcmp(key, "branch.")) {
+	if (has_prefix(key, "branch.")) {
 		name = key + 7;
 		subkey = strrchr(name, '.');
 		if (!subkey)
@@ -361,7 +361,7 @@ static int handle_config(const char *key, const char *value, void *cb)
 		}
 		return 0;
 	}
-	if (!prefixcmp(key, "url.")) {
+	if (has_prefix(key, "url.")) {
 		struct rewrite *rewrite;
 		name = key + 4;
 		subkey = strrchr(name, '.');
@@ -380,7 +380,7 @@ static int handle_config(const char *key, const char *value, void *cb)
 		}
 	}
 
-	if (prefixcmp(key,  "remote."))
+	if (!has_prefix(key,  "remote."))
 		return 0;
 	name = key + 7;
 
@@ -487,7 +487,7 @@ static void read_config(void)
 	current_branch = NULL;
 	head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
 	if (head_ref && (flag & REF_ISSYMREF) &&
-	    !prefixcmp(head_ref, "refs/heads/")) {
+	    has_prefix(head_ref, "refs/heads/")) {
 		current_branch =
 			make_branch(head_ref + strlen("refs/heads/"), 0);
 	}
@@ -982,8 +982,8 @@ static int count_refspec_match(const char *pattern,
 		 */
 		if (namelen != patlen &&
 		    patlen != namelen - 5 &&
-		    prefixcmp(name, "refs/heads/") &&
-		    prefixcmp(name, "refs/tags/")) {
+		    !has_prefix(name, "refs/heads/") &&
+		    !has_prefix(name, "refs/tags/")) {
 			/* We want to catch the case where only weak
 			 * matches are found and there are multiple
 			 * matches, and where more than one strong
@@ -1054,9 +1054,9 @@ static char *guess_ref(const char *name, struct ref *peer)
 	if (!r)
 		return NULL;
 
-	if (!prefixcmp(r, "refs/heads/"))
+	if (has_prefix(r, "refs/heads/"))
 		strbuf_addstr(&buf, "refs/heads/");
-	else if (!prefixcmp(r, "refs/tags/"))
+	else if (has_prefix(r, "refs/tags/"))
 		strbuf_addstr(&buf, "refs/tags/");
 	else
 		return NULL;
@@ -1104,7 +1104,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
 		dst_value = resolve_ref_unsafe(matched_src->name, sha1, 1, &flag);
 		if (!dst_value ||
 		    ((flag & REF_ISSYMREF) &&
-		     prefixcmp(dst_value, "refs/heads/")))
+		     !has_prefix(dst_value, "refs/heads/")))
 			die("%s cannot be resolved to branch.",
 			    matched_src->name);
 	}
@@ -1193,7 +1193,7 @@ static char *get_ref_match(const struct refspec *rs, int rs_nr, const struct ref
 		 * including refs outside refs/heads/ hierarchy, but
 		 * that does not make much sense these days.
 		 */
-		if (!send_mirror && prefixcmp(ref->name, "refs/heads/"))
+		if (!send_mirror && !has_prefix(ref->name, "refs/heads/"))
 			return NULL;
 		name = xstrdup(ref->name);
 	}
@@ -1248,7 +1248,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 			add_to_tips(&sent_tips, ref->peer_ref->new_sha1);
 		else
 			add_to_tips(&sent_tips, ref->old_sha1);
-		if (!prefixcmp(ref->name, "refs/tags/"))
+		if (has_prefix(ref->name, "refs/tags/"))
 			string_list_append(&dst_tag, ref->name);
 	}
 	clear_commit_marks_many(sent_tips.nr, sent_tips.tip, TMP_MARK);
@@ -1257,7 +1257,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 
 	/* Collect tags they do not have. */
 	for (ref = src; ref; ref = ref->next) {
-		if (prefixcmp(ref->name, "refs/tags/"))
+		if (!has_prefix(ref->name, "refs/tags/"))
 			continue; /* not a tag */
 		if (string_list_has_string(&dst_tag, ref->name))
 			continue; /* they already have it */
@@ -1481,7 +1481,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 		 */
 
 		else if (!ref->deletion && !is_null_sha1(ref->old_sha1)) {
-			if (!prefixcmp(ref->name, "refs/tags/"))
+			if (has_prefix(ref->name, "refs/tags/"))
 				reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
 			else if (!has_sha1_file(ref->old_sha1))
 				reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
@@ -1607,12 +1607,12 @@ static struct ref *get_local_ref(const char *name)
 	if (!name || name[0] == '\0')
 		return NULL;
 
-	if (!prefixcmp(name, "refs/"))
+	if (has_prefix(name, "refs/"))
 		return alloc_ref(name);
 
-	if (!prefixcmp(name, "heads/") ||
-	    !prefixcmp(name, "tags/") ||
-	    !prefixcmp(name, "remotes/"))
+	if (has_prefix(name, "heads/") ||
+	    has_prefix(name, "tags/") ||
+	    has_prefix(name, "remotes/"))
 		return alloc_ref_with_prefix("refs/", 5, name);
 
 	return alloc_ref_with_prefix("refs/heads/", 11, name);
@@ -1647,7 +1647,7 @@ int get_fetch_map(const struct ref *remote_refs,
 
 	for (rmp = &ref_map; *rmp; ) {
 		if ((*rmp)->peer_ref) {
-			if (prefixcmp((*rmp)->peer_ref->name, "refs/") ||
+			if (!has_prefix((*rmp)->peer_ref->name, "refs/") ||
 			    check_refname_format((*rmp)->peer_ref->name, 0)) {
 				struct ref *ignore = *rmp;
 				error("* Ignoring funny ref '%s' locally",
@@ -1931,7 +1931,7 @@ struct ref *guess_remote_head(const struct ref *head,
 	/* Look for another ref that points there */
 	for (r = refs; r; r = r->next) {
 		if (r != head &&
-		    !prefixcmp(r->name, "refs/heads/") &&
+		    has_prefix(r->name, "refs/heads/") &&
 		    !hashcmp(r->old_sha1, head->old_sha1)) {
 			*tail = copy_ref(r);
 			tail = &((*tail)->next);
-- 
1.8.4.1.566.geca833c
Previous: Christian CouderNext: Christian Couder
Message 5 of 100 in “replace prefixcmp() with has_prefix()”
  1. 00/86 replace prefixcmp() with has_prefix()Christian Couder, Nov 9, 2013
  2. 01/86 strbuf: add has_prefix() to be used instead of prefixcmp()Christian Couder, Nov 9, 2013
  3. 02/86 diff: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  4. 03/86 fast-import: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  5. 04/86 remote*: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  6. 05/86 daemon: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  7. 06/86 pretty: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  8. 07/86 revision: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  9. 08/86 transport*: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  10. 09/86 config: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  11. 10/86 sha1_name: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  12. 11/86 wt-status: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  13. 12/86 upload-pack: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  14. 13/86 test-line-buffer: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  15. 14/86 parse-options: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  16. 15/86 fetch-pack: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  17. 16/86 git: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  18. 17/86 tag: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  19. 18/86 sequencer: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  20. 19/86 commit: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  21. 20/86 http: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  22. 21/86 imap-send: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  23. 22/86 help: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  24. 23/86 log-tree: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  25. 24/86 merge-recursive: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  26. 25/86 notes: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  27. 26/86 refs: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  28. 27/86 setup: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  29. 28/86 bisect: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  30. 29/86 branch: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  31. 30/86 http-push: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  32. 31/86 send-pack: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  33. 32/86 http-backend: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  34. 33/86 notes-utils: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  35. 34/86 pkt-line: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  36. 35/86 alias: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  37. 36/86 attr: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  38. 37/86 connect: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  39. 38/86 pager: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  40. 39/86 convert: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  41. 40/86 environment: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  42. 41/86 shell: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  43. 42/86 pathspec: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  44. 43/86 submodule: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  45. 44/86 test-string-list: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  46. 45/86 builtin/apply: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  47. 46/86 builtin/archive: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  48. 47/86 builtin/branch: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  49. 48/86 builtin/checkout: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  50. 49/86 builtin/clean: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  51. 50/86 builtin/clone: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  52. 51/86 builtin/column: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  53. 52/86 builtin/commit: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  54. 53/86 builtin/describe: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  55. 54/86 builtin/fast-export: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  56. 55/86 builtin/fetch-pack: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  57. 56/86 builtin/fetch: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  58. 57/86 builtin/fmt-merge-msg: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  59. 58/86 builtin/for-each-ref: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  60. 59/86 builtin/fsck: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  61. 60/86 builtin/help: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  62. 61/86 builtin/index-pack: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  63. 62/86 builtin/init-db: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  64. 63/86 builtin/log: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  65. 64/86 builtin/ls-remote: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  66. 65/86 builtin/mailinfo: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  67. 66/86 builtin/merge-recursive: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  68. 67/86 builtin/merge: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  69. 68/86 builtin/name-rev: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  70. 69/86 builtin/notes: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  71. 70/86 builtin/pack-objects: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  72. 71/86 builtin/prune: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  73. 72/86 builtin/receive-pack: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  74. 73/86 builtin/reflog: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  75. 74/86 builtin/remote: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  76. 75/86 builtin/rev-parse: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  77. 76/86 builtin/send-pack: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  78. 77/86 builtin/shortlog: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  79. 78/86 builtin/show-branch: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  80. 79/86 builtin/show-ref: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  81. 80/86 builtin/symbolic-ref: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  82. 81/86 builtin/tag: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  83. 82/86 builtin/tar-tree: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  84. 83/86 builtin/unpack-objects: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  85. 84/86 builtin/update-ref: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  86. 85/86 builtin/upload-archive: replace prefixcmd() with has_prefix()Christian Couder, Nov 9, 2013
  87. 86/86 strbuf: remove prefixcmp() as it has been replaced with has_prefix()Christian Couder, Nov 9, 2013
  88. Thomas RastNov 9, 2013
  89. Christian CouderNov 12, 2013
  90. Andreas EricssonNov 11, 2013
  91. Jeff KingNov 12, 2013
  92. Junio C HamanoNov 12, 2013
  93. Jeff KingNov 12, 2013
  94. Christian CouderNov 12, 2013
  95. Junio C HamanoNov 12, 2013
  96. Christian CouderNov 13, 2013
  97. Jeff KingNov 13, 2013
  98. Christian CouderNov 17, 2013
  99. Christian CouderNov 18, 2013
  100. Junio C HamanoNov 19, 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.