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

[PATCH 03/86] fast-import: replace prefixcmd() with has_prefix()

From
Christian Couder <chriscool@tuxfamily.org>
Date
Nov 9, 2013, 07:05 UTC
Message-ID
<20131109070720.18178.66984.chriscool@tuxfamily.org>
In-Reply-To
<20131109070358.18178.40248.chriscool@tuxfamily.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 fast-import.c | 80 +++++++++++++++++++++++++++++------------------------------
 1 file changed, 40 insertions(+), 40 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index f4d9969..14f69a1 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1877,8 +1877,8 @@ static int read_next_command(void)
 				return EOF;
 
 			if (!seen_data_command
-				&& prefixcmp(command_buf.buf, "feature ")
-				&& prefixcmp(command_buf.buf, "option ")) {
+				&& !has_prefix(command_buf.buf, "feature ")
+				&& !has_prefix(command_buf.buf, "option ")) {
 				parse_argv();
 			}
 
@@ -1898,7 +1898,7 @@ static int read_next_command(void)
 			rc->prev->next = rc;
 			cmd_tail = rc;
 		}
-		if (!prefixcmp(command_buf.buf, "cat-blob ")) {
+		if (has_prefix(command_buf.buf, "cat-blob ")) {
 			parse_cat_blob();
 			continue;
 		}
@@ -1917,7 +1917,7 @@ static void skip_optional_lf(void)
 
 static void parse_mark(void)
 {
-	if (!prefixcmp(command_buf.buf, "mark :")) {
+	if (has_prefix(command_buf.buf, "mark :")) {
 		next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
 		read_next_command();
 	}
@@ -1929,10 +1929,10 @@ static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
 {
 	strbuf_reset(sb);
 
-	if (prefixcmp(command_buf.buf, "data "))
+	if (!has_prefix(command_buf.buf, "data "))
 		die("Expected 'data n' command, found: %s", command_buf.buf);
 
-	if (!prefixcmp(command_buf.buf + 5, "<<")) {
+	if (has_prefix(command_buf.buf + 5, "<<")) {
 		char *term = xstrdup(command_buf.buf + 5 + 2);
 		size_t term_len = command_buf.len - 5 - 2;
 
@@ -2306,7 +2306,7 @@ static void file_change_m(struct branch *b)
 	if (*p == ':') {
 		oe = find_mark(parse_mark_ref_space(&p));
 		hashcpy(sha1, oe->idx.sha1);
-	} else if (!prefixcmp(p, "inline ")) {
+	} else if (has_prefix(p, "inline ")) {
 		inline_data = 1;
 		oe = NULL; /* not used with inline_data, but makes gcc happy */
 		p += strlen("inline");  /* advance to space */
@@ -2479,7 +2479,7 @@ static void note_change_n(struct branch *b, unsigned char *old_fanout)
 	if (*p == ':') {
 		oe = find_mark(parse_mark_ref_space(&p));
 		hashcpy(sha1, oe->idx.sha1);
-	} else if (!prefixcmp(p, "inline ")) {
+	} else if (has_prefix(p, "inline ")) {
 		inline_data = 1;
 		oe = NULL; /* not used with inline_data, but makes gcc happy */
 		p += strlen("inline");  /* advance to space */
@@ -2590,7 +2590,7 @@ static int parse_from(struct branch *b)
 	const char *from;
 	struct branch *s;
 
-	if (prefixcmp(command_buf.buf, "from "))
+	if (!has_prefix(command_buf.buf, "from "))
 		return 0;
 
 	if (b->branch_tree.tree) {
@@ -2636,7 +2636,7 @@ static struct hash_list *parse_merge(unsigned int *count)
 	struct branch *s;
 
 	*count = 0;
-	while (!prefixcmp(command_buf.buf, "merge ")) {
+	while (has_prefix(command_buf.buf, "merge ")) {
 		from = strchr(command_buf.buf, ' ') + 1;
 		n = xmalloc(sizeof(*n));
 		s = lookup_branch(from);
@@ -2687,11 +2687,11 @@ static void parse_new_commit(void)
 
 	read_next_command();
 	parse_mark();
-	if (!prefixcmp(command_buf.buf, "author ")) {
+	if (has_prefix(command_buf.buf, "author ")) {
 		author = parse_ident(command_buf.buf + 7);
 		read_next_command();
 	}
-	if (!prefixcmp(command_buf.buf, "committer ")) {
+	if (has_prefix(command_buf.buf, "committer ")) {
 		committer = parse_ident(command_buf.buf + 10);
 		read_next_command();
 	}
@@ -2712,19 +2712,19 @@ static void parse_new_commit(void)
 
 	/* file_change* */
 	while (command_buf.len > 0) {
-		if (!prefixcmp(command_buf.buf, "M "))
+		if (has_prefix(command_buf.buf, "M "))
 			file_change_m(b);
-		else if (!prefixcmp(command_buf.buf, "D "))
+		else if (has_prefix(command_buf.buf, "D "))
 			file_change_d(b);
-		else if (!prefixcmp(command_buf.buf, "R "))
+		else if (has_prefix(command_buf.buf, "R "))
 			file_change_cr(b, 1);
-		else if (!prefixcmp(command_buf.buf, "C "))
+		else if (has_prefix(command_buf.buf, "C "))
 			file_change_cr(b, 0);
-		else if (!prefixcmp(command_buf.buf, "N "))
+		else if (has_prefix(command_buf.buf, "N "))
 			note_change_n(b, &prev_fanout);
 		else if (!strcmp("deleteall", command_buf.buf))
 			file_change_deleteall(b);
-		else if (!prefixcmp(command_buf.buf, "ls "))
+		else if (has_prefix(command_buf.buf, "ls "))
 			parse_ls(b);
 		else {
 			unread_command_buf = 1;
@@ -2793,7 +2793,7 @@ static void parse_new_tag(void)
 	read_next_command();
 
 	/* from ... */
-	if (prefixcmp(command_buf.buf, "from "))
+	if (!has_prefix(command_buf.buf, "from "))
 		die("Expected from command, got %s", command_buf.buf);
 	from = strchr(command_buf.buf, ' ') + 1;
 	s = lookup_branch(from);
@@ -2821,7 +2821,7 @@ static void parse_new_tag(void)
 	read_next_command();
 
 	/* tagger ... */
-	if (!prefixcmp(command_buf.buf, "tagger ")) {
+	if (has_prefix(command_buf.buf, "tagger ")) {
 		tagger = parse_ident(command_buf.buf + 7);
 		read_next_command();
 	} else
@@ -3209,7 +3209,7 @@ static void option_export_pack_edges(const char *edges)
 
 static int parse_one_option(const char *option)
 {
-	if (!prefixcmp(option, "max-pack-size=")) {
+	if (has_prefix(option, "max-pack-size=")) {
 		unsigned long v;
 		if (!git_parse_ulong(option + 14, &v))
 			return 0;
@@ -3221,20 +3221,20 @@ static int parse_one_option(const char *option)
 			v = 1024 * 1024;
 		}
 		max_packsize = v;
-	} else if (!prefixcmp(option, "big-file-threshold=")) {
+	} else if (has_prefix(option, "big-file-threshold=")) {
 		unsigned long v;
 		if (!git_parse_ulong(option + 19, &v))
 			return 0;
 		big_file_threshold = v;
-	} else if (!prefixcmp(option, "depth=")) {
+	} else if (has_prefix(option, "depth=")) {
 		option_depth(option + 6);
-	} else if (!prefixcmp(option, "active-branches=")) {
+	} else if (has_prefix(option, "active-branches=")) {
 		option_active_branches(option + 16);
-	} else if (!prefixcmp(option, "export-pack-edges=")) {
+	} else if (has_prefix(option, "export-pack-edges=")) {
 		option_export_pack_edges(option + 18);
-	} else if (!prefixcmp(option, "quiet")) {
+	} else if (has_prefix(option, "quiet")) {
 		show_stats = 0;
-	} else if (!prefixcmp(option, "stats")) {
+	} else if (has_prefix(option, "stats")) {
 		show_stats = 1;
 	} else {
 		return 0;
@@ -3245,14 +3245,14 @@ static int parse_one_option(const char *option)
 
 static int parse_one_feature(const char *feature, int from_stream)
 {
-	if (!prefixcmp(feature, "date-format=")) {
+	if (has_prefix(feature, "date-format=")) {
 		option_date_format(feature + 12);
-	} else if (!prefixcmp(feature, "import-marks=")) {
+	} else if (has_prefix(feature, "import-marks=")) {
 		option_import_marks(feature + 13, from_stream, 0);
-	} else if (!prefixcmp(feature, "import-marks-if-exists=")) {
+	} else if (has_prefix(feature, "import-marks-if-exists=")) {
 		option_import_marks(feature + strlen("import-marks-if-exists="),
 					from_stream, 1);
-	} else if (!prefixcmp(feature, "export-marks=")) {
+	} else if (has_prefix(feature, "export-marks=")) {
 		option_export_marks(feature + 13);
 	} else if (!strcmp(feature, "cat-blob")) {
 		; /* Don't die - this feature is supported */
@@ -3350,7 +3350,7 @@ static void parse_argv(void)
 		if (parse_one_feature(a + 2, 0))
 			continue;
 
-		if (!prefixcmp(a + 2, "cat-blob-fd=")) {
+		if (has_prefix(a + 2, "cat-blob-fd=")) {
 			option_cat_blob_fd(a + 2 + strlen("cat-blob-fd="));
 			continue;
 		}
@@ -3404,25 +3404,25 @@ int main(int argc, char **argv)
 	while (read_next_command() != EOF) {
 		if (!strcmp("blob", command_buf.buf))
 			parse_new_blob();
-		else if (!prefixcmp(command_buf.buf, "ls "))
+		else if (has_prefix(command_buf.buf, "ls "))
 			parse_ls(NULL);
-		else if (!prefixcmp(command_buf.buf, "commit "))
+		else if (has_prefix(command_buf.buf, "commit "))
 			parse_new_commit();
-		else if (!prefixcmp(command_buf.buf, "tag "))
+		else if (has_prefix(command_buf.buf, "tag "))
 			parse_new_tag();
-		else if (!prefixcmp(command_buf.buf, "reset "))
+		else if (has_prefix(command_buf.buf, "reset "))
 			parse_reset_branch();
 		else if (!strcmp("checkpoint", command_buf.buf))
 			parse_checkpoint();
 		else if (!strcmp("done", command_buf.buf))
 			break;
-		else if (!prefixcmp(command_buf.buf, "progress "))
+		else if (has_prefix(command_buf.buf, "progress "))
 			parse_progress();
-		else if (!prefixcmp(command_buf.buf, "feature "))
+		else if (has_prefix(command_buf.buf, "feature "))
 			parse_feature();
-		else if (!prefixcmp(command_buf.buf, "option git "))
+		else if (has_prefix(command_buf.buf, "option git "))
 			parse_option();
-		else if (!prefixcmp(command_buf.buf, "option "))
+		else if (has_prefix(command_buf.buf, "option "))
 			/* ignore non-git options*/;
 		else
 			die("Unsupported command: %s", command_buf.buf);
-- 
1.8.4.1.566.geca833c
Previous: Christian CouderNext: Christian Couder
Message 4 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.