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

[PATCH 02/86] diff: replace prefixcmd() with has_prefix()

From
Christian Couder <chriscool@tuxfamily.org>
Date
Nov 9, 2013, 07:05 UTC
Message-ID
<20131109070720.18178.51034.chriscool@tuxfamily.org>
In-Reply-To
<20131109070358.18178.40248.chriscool@tuxfamily.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 diff.c | 56 ++++++++++++++++++++++++++++----------------------------
 1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/diff.c b/diff.c
index a04a34d..b42523a 100644
--- a/diff.c
+++ b/diff.c
@@ -235,7 +235,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
 	if (userdiff_config(var, value) < 0)
 		return -1;
 
-	if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) {
+	if (has_prefix(var, "diff.color.") || has_prefix(var, "color.diff.")) {
 		int slot = parse_diff_color_slot(var, 11);
 		if (slot < 0)
 			return 0;
@@ -264,7 +264,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
-	if (!prefixcmp(var, "submodule."))
+	if (has_prefix(var, "submodule."))
 		return parse_submodule_config_option(var, value);
 
 	return git_default_config(var, value, cb);
@@ -1215,7 +1215,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 			diff_words_append(line, len,
 					  &ecbdata->diff_words->plus);
 			return;
-		} else if (!prefixcmp(line, "\\ ")) {
+		} else if (has_prefix(line, "\\ ")) {
 			/*
 			 * Eat the "no newline at eof" marker as if we
 			 * saw a "+" or "-" line with nothing on it,
@@ -2387,9 +2387,9 @@ static void builtin_diff(const char *name_a,
 			xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
 		if (!diffopts)
 			;
-		else if (!prefixcmp(diffopts, "--unified="))
+		else if (has_prefix(diffopts, "--unified="))
 			xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
-		else if (!prefixcmp(diffopts, "-u"))
+		else if (has_prefix(diffopts, "-u"))
 			xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
 		if (o->word_diff)
 			init_diff_words_data(&ecbdata, o, one, two);
@@ -3388,7 +3388,7 @@ int parse_long_opt(const char *opt, const char **argv,
 	if (arg[0] != '-' || arg[1] != '-')
 		return 0;
 	arg += strlen("--");
-	if (prefixcmp(arg, opt))
+	if (!has_prefix(arg, opt))
 		return 0;
 	arg += strlen(opt);
 	if (*arg == '=') { /* sticked form: --option=value */
@@ -3419,7 +3419,7 @@ static int stat_opt(struct diff_options *options, const char **av)
 
 	switch (*arg) {
 	case '-':
-		if (!prefixcmp(arg, "-width")) {
+		if (has_prefix(arg, "-width")) {
 			arg += strlen("-width");
 			if (*arg == '=')
 				width = strtoul(arg + 1, &end, 10);
@@ -3429,7 +3429,7 @@ static int stat_opt(struct diff_options *options, const char **av)
 				width = strtoul(av[1], &end, 10);
 				argcount = 2;
 			}
-		} else if (!prefixcmp(arg, "-name-width")) {
+		} else if (has_prefix(arg, "-name-width")) {
 			arg += strlen("-name-width");
 			if (*arg == '=')
 				name_width = strtoul(arg + 1, &end, 10);
@@ -3439,7 +3439,7 @@ static int stat_opt(struct diff_options *options, const char **av)
 				name_width = strtoul(av[1], &end, 10);
 				argcount = 2;
 			}
-		} else if (!prefixcmp(arg, "-graph-width")) {
+		} else if (has_prefix(arg, "-graph-width")) {
 			arg += strlen("-graph-width");
 			if (*arg == '=')
 				graph_width = strtoul(arg + 1, &end, 10);
@@ -3449,7 +3449,7 @@ static int stat_opt(struct diff_options *options, const char **av)
 				graph_width = strtoul(av[1], &end, 10);
 				argcount = 2;
 			}
-		} else if (!prefixcmp(arg, "-count")) {
+		} else if (has_prefix(arg, "-count")) {
 			arg += strlen("-count");
 			if (*arg == '=')
 				count = strtoul(arg + 1, &end, 10);
@@ -3611,15 +3611,15 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		options->output_format |= DIFF_FORMAT_SHORTSTAT;
 	else if (!strcmp(arg, "-X") || !strcmp(arg, "--dirstat"))
 		return parse_dirstat_opt(options, "");
-	else if (!prefixcmp(arg, "-X"))
+	else if (has_prefix(arg, "-X"))
 		return parse_dirstat_opt(options, arg + 2);
-	else if (!prefixcmp(arg, "--dirstat="))
+	else if (has_prefix(arg, "--dirstat="))
 		return parse_dirstat_opt(options, arg + 10);
 	else if (!strcmp(arg, "--cumulative"))
 		return parse_dirstat_opt(options, "cumulative");
 	else if (!strcmp(arg, "--dirstat-by-file"))
 		return parse_dirstat_opt(options, "files");
-	else if (!prefixcmp(arg, "--dirstat-by-file=")) {
+	else if (has_prefix(arg, "--dirstat-by-file=")) {
 		parse_dirstat_opt(options, "files");
 		return parse_dirstat_opt(options, arg + 18);
 	}
@@ -3636,17 +3636,17 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		options->output_format |= DIFF_FORMAT_NAME_STATUS;
 	else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
 		options->output_format |= DIFF_FORMAT_NO_OUTPUT;
-	else if (!prefixcmp(arg, "--stat"))
+	else if (has_prefix(arg, "--stat"))
 		/* --stat, --stat-width, --stat-name-width, or --stat-count */
 		return stat_opt(options, av);
 
 	/* renames options */
-	else if (!prefixcmp(arg, "-B") || !prefixcmp(arg, "--break-rewrites=") ||
+	else if (has_prefix(arg, "-B") || has_prefix(arg, "--break-rewrites=") ||
 		 !strcmp(arg, "--break-rewrites")) {
 		if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
 			return error("invalid argument to -B: %s", arg+2);
 	}
-	else if (!prefixcmp(arg, "-M") || !prefixcmp(arg, "--find-renames=") ||
+	else if (has_prefix(arg, "-M") || has_prefix(arg, "--find-renames=") ||
 		 !strcmp(arg, "--find-renames")) {
 		if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
 			return error("invalid argument to -M: %s", arg+2);
@@ -3655,7 +3655,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 	else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
 		options->irreversible_delete = 1;
 	}
-	else if (!prefixcmp(arg, "-C") || !prefixcmp(arg, "--find-copies=") ||
+	else if (has_prefix(arg, "-C") || has_prefix(arg, "--find-copies=") ||
 		 !strcmp(arg, "--find-copies")) {
 		if (options->detect_rename == DIFF_DETECT_COPY)
 			DIFF_OPT_SET(options, FIND_COPIES_HARDER);
@@ -3671,7 +3671,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		DIFF_OPT_CLR(options, RENAME_EMPTY);
 	else if (!strcmp(arg, "--relative"))
 		DIFF_OPT_SET(options, RELATIVE_NAME);
-	else if (!prefixcmp(arg, "--relative=")) {
+	else if (has_prefix(arg, "--relative=")) {
 		DIFF_OPT_SET(options, RELATIVE_NAME);
 		options->prefix = arg + 11;
 	}
@@ -3724,7 +3724,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		DIFF_OPT_CLR(options, FOLLOW_RENAMES);
 	else if (!strcmp(arg, "--color"))
 		options->use_color = 1;
-	else if (!prefixcmp(arg, "--color=")) {
+	else if (has_prefix(arg, "--color=")) {
 		int value = git_config_colorbool(NULL, arg+8);
 		if (value < 0)
 			return error("option `color' expects \"always\", \"auto\", or \"never\"");
@@ -3736,7 +3736,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		options->use_color = 1;
 		options->word_diff = DIFF_WORDS_COLOR;
 	}
-	else if (!prefixcmp(arg, "--color-words=")) {
+	else if (has_prefix(arg, "--color-words=")) {
 		options->use_color = 1;
 		options->word_diff = DIFF_WORDS_COLOR;
 		options->word_regex = arg + 14;
@@ -3745,7 +3745,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		if (options->word_diff == DIFF_WORDS_NONE)
 			options->word_diff = DIFF_WORDS_PLAIN;
 	}
-	else if (!prefixcmp(arg, "--word-diff=")) {
+	else if (has_prefix(arg, "--word-diff=")) {
 		const char *type = arg + 12;
 		if (!strcmp(type, "plain"))
 			options->word_diff = DIFF_WORDS_PLAIN;
@@ -3781,12 +3781,12 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 	else if (!strcmp(arg, "--ignore-submodules")) {
 		DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
 		handle_ignore_submodules_arg(options, "all");
-	} else if (!prefixcmp(arg, "--ignore-submodules=")) {
+	} else if (has_prefix(arg, "--ignore-submodules=")) {
 		DIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);
 		handle_ignore_submodules_arg(options, arg + 20);
 	} else if (!strcmp(arg, "--submodule"))
 		DIFF_OPT_SET(options, SUBMODULE_LOG);
-	else if (!prefixcmp(arg, "--submodule="))
+	else if (has_prefix(arg, "--submodule="))
 		return parse_submodule_opt(options, arg + 12);
 
 	/* misc options */
@@ -3822,7 +3822,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 	}
 	else if (!strcmp(arg, "--abbrev"))
 		options->abbrev = DEFAULT_ABBREV;
-	else if (!prefixcmp(arg, "--abbrev=")) {
+	else if (has_prefix(arg, "--abbrev=")) {
 		options->abbrev = strtoul(arg + 9, NULL, 10);
 		if (options->abbrev < MINIMUM_ABBREV)
 			options->abbrev = MINIMUM_ABBREV;
@@ -3904,15 +3904,15 @@ static int diff_scoreopt_parse(const char *opt)
 	cmd = *opt++;
 	if (cmd == '-') {
 		/* convert the long-form arguments into short-form versions */
-		if (!prefixcmp(opt, "break-rewrites")) {
+		if (has_prefix(opt, "break-rewrites")) {
 			opt += strlen("break-rewrites");
 			if (*opt == 0 || *opt++ == '=')
 				cmd = 'B';
-		} else if (!prefixcmp(opt, "find-copies")) {
+		} else if (has_prefix(opt, "find-copies")) {
 			opt += strlen("find-copies");
 			if (*opt == 0 || *opt++ == '=')
 				cmd = 'C';
-		} else if (!prefixcmp(opt, "find-renames")) {
+		} else if (has_prefix(opt, "find-renames")) {
 			opt += strlen("find-renames");
 			if (*opt == 0 || *opt++ == '=')
 				cmd = 'M';
@@ -4322,7 +4322,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
 	int new_len;
 
 	/* Ignore line numbers when computing the SHA1 of the patch */
-	if (!prefixcmp(line, "@@ -"))
+	if (has_prefix(line, "@@ -"))
 		return;
 
 	new_len = remove_space(line, len);
-- 
1.8.4.1.566.geca833c
Previous: Christian CouderNext: Christian Couder
Message 3 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.