git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/86] replace prefixcmp() with starts_with()
@ 2013-11-17 22:05 Christian Couder
  2013-11-17 22:05 ` [PATCH v2 01/86] strbuf: add starts_with() to be used instead of prefixcmp() Christian Couder
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Christian Couder @ 2013-11-17 22:05 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Avery Pennarun, Johannes Schindelin, Jonathan Nieder,
	Jeff King, Max Horn, Andreas Ericsson

Here is a resend of a big patch series to replace prefixcmp()
with a new starts_with() function.

The changes since the previous version are the following

	- the function to replace prefixcmp() is now
	  starts_with()
	- the mispelling of prefixcmp() in the titles
	  of the patches and emails is fixed

The first patch of this series introduces starts_with() and
the last patch removes prefixcmp().

Except a few patches, it's possible to generate the patches
in between using a script like the following: 

===
#!/bin/bash

perl -pi -e 's/!prefixcmp\(/starts_with\(/g' "$1"
perl -pi -e 's/prefixcmp\(/!starts_with\(/g' "$1"

git commit -m "$1: replace prefixcmp() with starts_with()" "$1"
===

The few special cases are the following ones:

        - remote*: replace prefixcmp() with starts_with()
        - transport*: replace prefixcmp() with starts_with()
        - environment: replace prefixcmp() with starts_with()

In first 2 cases above, I processed a few files at the same
time instead of just one.

In the case of "environment", I removed " != 0" after
"!starts_with(...)" as it is not necessary and makes it
more difficult to understand the logic.

Of course it's possible to squash many of the commits
together if it is prefered.


Christian Couder (86):
  strbuf: add starts_with() to be used instead of prefixcmp()
  diff: replace prefixcmp() with starts_with()
  fast-import: replace prefixcmp() with starts_with()
  remote*: replace prefixcmp() with starts_with()
  daemon: replace prefixcmp() with starts_with()
  pretty: replace prefixcmp() with starts_with()
  revision: replace prefixcmp() with starts_with()
  transport*: replace prefixcmp() with starts_with()
  config: replace prefixcmp() with starts_with()
  sha1_name: replace prefixcmp() with starts_with()
  wt-status: replace prefixcmp() with starts_with()
  upload-pack: replace prefixcmp() with starts_with()
  test-line-buffer: replace prefixcmp() with starts_with()
  parse-options: replace prefixcmp() with starts_with()
  fetch-pack: replace prefixcmp() with starts_with()
  git: replace prefixcmp() with starts_with()
  tag: replace prefixcmp() with starts_with()
  sequencer: replace prefixcmp() with starts_with()
  commit: replace prefixcmp() with starts_with()
  http: replace prefixcmp() with starts_with()
  imap-send: replace prefixcmp() with starts_with()
  help: replace prefixcmp() with starts_with()
  log-tree: replace prefixcmp() with starts_with()
  merge-recursive: replace prefixcmp() with starts_with()
  notes: replace prefixcmp() with starts_with()
  refs: replace prefixcmp() with starts_with()
  setup: replace prefixcmp() with starts_with()
  bisect: replace prefixcmp() with starts_with()
  branch: replace prefixcmp() with starts_with()
  http-push: replace prefixcmp() with starts_with()
  send-pack: replace prefixcmp() with starts_with()
  http-backend: replace prefixcmp() with starts_with()
  notes-utils: replace prefixcmp() with starts_with()
  pkt-line: replace prefixcmp() with starts_with()
  alias: replace prefixcmp() with starts_with()
  attr: replace prefixcmp() with starts_with()
  connect: replace prefixcmp() with starts_with()
  pager: replace prefixcmp() with starts_with()
  convert: replace prefixcmp() with starts_with()
  environment: replace prefixcmp() with starts_with()
  shell: replace prefixcmp() with starts_with()
  pathspec: replace prefixcmp() with starts_with()
  submodule: replace prefixcmp() with starts_with()
  test-string-list: replace prefixcmp() with starts_with()
  builtin/apply: replace prefixcmp() with starts_with()
  builtin/archive: replace prefixcmp() with starts_with()
  builtin/branch: replace prefixcmp() with starts_with()
  builtin/checkout: replace prefixcmp() with starts_with()
  builtin/clean: replace prefixcmp() with starts_with()
  builtin/clone: replace prefixcmp() with starts_with()
  builtin/column: replace prefixcmp() with starts_with()
  builtin/commit: replace prefixcmp() with starts_with()
  builtin/describe: replace prefixcmp() with starts_with()
  builtin/fast-export: replace prefixcmp() with starts_with()
  builtin/fetch-pack: replace prefixcmp() with starts_with()
  builtin/fetch: replace prefixcmp() with starts_with()
  builtin/fmt-merge-msg: replace prefixcmp() with starts_with()
  builtin/for-each-ref: replace prefixcmp() with starts_with()
  builtin/fsck: replace prefixcmp() with starts_with()
  builtin/help: replace prefixcmp() with starts_with()
  builtin/index-pack: replace prefixcmp() with starts_with()
  builtin/init-db: replace prefixcmp() with starts_with()
  builtin/log: replace prefixcmp() with starts_with()
  builtin/ls-remote: replace prefixcmp() with starts_with()
  builtin/mailinfo: replace prefixcmp() with starts_with()
  builtin/merge-recursive: replace prefixcmp() with starts_with()
  builtin/merge: replace prefixcmp() with starts_with()
  builtin/name-rev: replace prefixcmp() with starts_with()
  builtin/notes: replace prefixcmp() with starts_with()
  builtin/pack-objects: replace prefixcmp() with starts_with()
  builtin/prune: replace prefixcmp() with starts_with()
  builtin/receive-pack: replace prefixcmp() with starts_with()
  builtin/reflog: replace prefixcmp() with starts_with()
  builtin/remote: replace prefixcmp() with starts_with()
  builtin/rev-parse: replace prefixcmp() with starts_with()
  builtin/send-pack: replace prefixcmp() with starts_with()
  builtin/shortlog: replace prefixcmp() with starts_with()
  builtin/show-branch: replace prefixcmp() with starts_with()
  builtin/show-ref: replace prefixcmp() with starts_with()
  builtin/symbolic-ref: replace prefixcmp() with starts_with()
  builtin/tag: replace prefixcmp() with starts_with()
  builtin/tar-tree: replace prefixcmp() with starts_with()
  builtin/unpack-objects: replace prefixcmp() with starts_with()
  builtin/update-ref: replace prefixcmp() with starts_with()
  builtin/upload-archive: replace prefixcmp() with starts_with()
  strbuf: remove prefixcmp() as it has been replaced with starts_with()

 alias.c                   |  2 +-
 attr.c                    |  2 +-
 bisect.c                  |  4 +--
 branch.c                  |  4 +--
 builtin/apply.c           | 12 +++----
 builtin/archive.c         |  4 +--
 builtin/branch.c          |  6 ++--
 builtin/checkout.c        |  8 ++---
 builtin/clean.c           |  4 +--
 builtin/clone.c           |  6 ++--
 builtin/column.c          |  2 +-
 builtin/commit.c          | 10 +++---
 builtin/describe.c        |  2 +-
 builtin/fast-export.c     |  2 +-
 builtin/fetch-pack.c      |  6 ++--
 builtin/fetch.c           | 16 +++++-----
 builtin/fmt-merge-msg.c   | 10 +++---
 builtin/for-each-ref.c    | 14 ++++-----
 builtin/fsck.c            |  6 ++--
 builtin/help.c            |  8 ++---
 builtin/index-pack.c      |  8 ++---
 builtin/init-db.c         |  2 +-
 builtin/log.c             |  8 ++---
 builtin/ls-remote.c       |  4 +--
 builtin/mailinfo.c        | 16 +++++-----
 builtin/merge-recursive.c |  2 +-
 builtin/merge.c           | 12 +++----
 builtin/name-rev.c        |  6 ++--
 builtin/notes.c           |  2 +-
 builtin/pack-objects.c    |  2 +-
 builtin/prune.c           |  4 +--
 builtin/receive-pack.c    |  6 ++--
 builtin/reflog.c          |  4 +--
 builtin/remote.c          |  8 ++---
 builtin/rev-parse.c       | 24 +++++++-------
 builtin/send-pack.c       |  8 ++---
 builtin/shortlog.c        |  6 ++--
 builtin/show-branch.c     | 20 ++++++------
 builtin/show-ref.c        |  6 ++--
 builtin/symbolic-ref.c    |  2 +-
 builtin/tag.c             |  2 +-
 builtin/tar-tree.c        |  2 +-
 builtin/unpack-objects.c  |  2 +-
 builtin/update-ref.c      | 10 +++---
 builtin/upload-archive.c  |  2 +-
 commit.c                  |  6 ++--
 config.c                  | 16 +++++-----
 connect.c                 |  2 +-
 convert.c                 |  2 +-
 daemon.c                  | 40 ++++++++++++------------
 diff.c                    | 56 ++++++++++++++++-----------------
 environment.c             |  2 +-
 fast-import.c             | 80 +++++++++++++++++++++++------------------------
 fetch-pack.c              | 12 +++----
 git-compat-util.h         |  2 +-
 git.c                     | 12 +++----
 help.c                    |  8 ++---
 http-backend.c            |  4 +--
 http-push.c               |  4 +--
 http.c                    |  8 ++---
 imap-send.c               | 10 +++---
 log-tree.c                |  8 ++---
 merge-recursive.c         |  6 ++--
 notes-utils.c             |  4 +--
 notes.c                   |  8 ++---
 pager.c                   |  2 +-
 parse-options.c           | 12 +++----
 pathspec.c                |  2 +-
 pkt-line.c                |  4 +--
 pretty.c                  | 36 ++++++++++-----------
 refs.c                    | 30 +++++++++---------
 remote-curl.c             | 14 ++++-----
 remote-testsvn.c          | 10 +++---
 remote.c                  | 46 +++++++++++++--------------
 revision.c                | 38 +++++++++++-----------
 send-pack.c               |  4 +--
 sequencer.c               |  8 ++---
 setup.c                   |  4 +--
 sha1_name.c               | 16 +++++-----
 shell.c                   |  2 +-
 strbuf.c                  |  6 ++--
 submodule.c               |  2 +-
 tag.c                     | 10 +++---
 test-line-buffer.c        |  6 ++--
 test-string-list.c        |  2 +-
 transport-helper.c        | 16 +++++-----
 transport.c               | 28 ++++++++---------
 upload-pack.c             | 10 +++---
 wt-status.c               | 16 +++++-----
 89 files changed, 455 insertions(+), 455 deletions(-)

-- 
1.8.4.1.561.g12affca

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 01/86] strbuf: add starts_with() to be used instead of prefixcmp()
  2013-11-17 22:05 [PATCH v2 00/86] replace prefixcmp() with starts_with() Christian Couder
@ 2013-11-17 22:05 ` Christian Couder
  2013-11-17 22:05 ` [PATCH v2 02/86] diff: replace prefixcmp() with starts_with() Christian Couder
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Couder @ 2013-11-17 22:05 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Avery Pennarun, Johannes Schindelin, Jonathan Nieder,
	Jeff King, Max Horn, Andreas Ericsson

prefixcmp() cannot be really used as a comparison function as
it is not antisymmetric:

	prefixcmp("foo", "foobar") < 0
	prefixcmp("foobar", "foo") == 0

So it is not suitable as a function for passing to qsort.
And in fact it is used nowhere as a comparison function.

So we should replace it with a function that just checks for
equality.

As a first step toward this goal, this patch introduces
starts_with().

Some popular programming languages have functions or methods
called using "start" and "with" that are doing what we want.
Therefore it makes sense to use starts_with() as a function
name to replace prefixcmp().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-compat-util.h | 1 +
 strbuf.c          | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/git-compat-util.h b/git-compat-util.h
index 37f0ba0..e441a6b 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -351,6 +351,7 @@ extern void set_error_routine(void (*routine)(const char *err, va_list params));
 extern void set_die_is_recursing_routine(int (*routine)(void));
 
 extern int prefixcmp(const char *str, const char *prefix);
+extern int starts_with(const char *str, const char *prefix);
 extern int ends_with(const char *str, const char *suffix);
 
 static inline const char *skip_prefix(const char *str, const char *prefix)
diff --git a/strbuf.c b/strbuf.c
index 2a14fdb..933d998 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -10,6 +10,15 @@ int prefixcmp(const char *str, const char *prefix)
 			return (unsigned char)*prefix - (unsigned char)*str;
 }
 
+int starts_with(const char *str, const char *prefix)
+{
+	for (; ; str++, prefix++)
+		if (!*prefix)
+			return 1;
+		else if (*str != *prefix)
+			return 0;
+}
+
 int ends_with(const char *str, const char *suffix)
 {
 	int len = strlen(str), suflen = strlen(suffix);
-- 
1.8.4.1.561.g12affca

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 02/86] diff: replace prefixcmp() with starts_with()
  2013-11-17 22:05 [PATCH v2 00/86] replace prefixcmp() with starts_with() Christian Couder
  2013-11-17 22:05 ` [PATCH v2 01/86] strbuf: add starts_with() to be used instead of prefixcmp() Christian Couder
@ 2013-11-17 22:05 ` Christian Couder
  2013-11-17 22:06 ` [PATCH v2 08/86] transport*: " Christian Couder
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Couder @ 2013-11-17 22:05 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Avery Pennarun, Johannes Schindelin, Jonathan Nieder,
	Jeff King, Max Horn, Andreas Ericsson

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..4b42997 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 (starts_with(var, "diff.color.") || starts_with(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 (starts_with(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 (starts_with(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 (starts_with(diffopts, "--unified="))
 			xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
-		else if (!prefixcmp(diffopts, "-u"))
+		else if (starts_with(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 (!starts_with(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 (starts_with(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 (starts_with(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 (starts_with(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 (starts_with(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 (starts_with(arg, "-X"))
 		return parse_dirstat_opt(options, arg + 2);
-	else if (!prefixcmp(arg, "--dirstat="))
+	else if (starts_with(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 (starts_with(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 (starts_with(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 (starts_with(arg, "-B") || starts_with(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 (starts_with(arg, "-M") || starts_with(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 (starts_with(arg, "-C") || starts_with(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 (starts_with(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 (starts_with(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 (starts_with(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 (starts_with(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 (starts_with(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 (starts_with(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 (starts_with(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 (starts_with(opt, "break-rewrites")) {
 			opt += strlen("break-rewrites");
 			if (*opt == 0 || *opt++ == '=')
 				cmd = 'B';
-		} else if (!prefixcmp(opt, "find-copies")) {
+		} else if (starts_with(opt, "find-copies")) {
 			opt += strlen("find-copies");
 			if (*opt == 0 || *opt++ == '=')
 				cmd = 'C';
-		} else if (!prefixcmp(opt, "find-renames")) {
+		} else if (starts_with(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 (starts_with(line, "@@ -"))
 		return;
 
 	new_len = remove_space(line, len);
-- 
1.8.4.1.561.g12affca

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 08/86] transport*: replace prefixcmp() with starts_with()
  2013-11-17 22:05 [PATCH v2 00/86] replace prefixcmp() with starts_with() Christian Couder
  2013-11-17 22:05 ` [PATCH v2 01/86] strbuf: add starts_with() to be used instead of prefixcmp() Christian Couder
  2013-11-17 22:05 ` [PATCH v2 02/86] diff: replace prefixcmp() with starts_with() Christian Couder
@ 2013-11-17 22:06 ` Christian Couder
  2013-11-17 22:06 ` [PATCH v2 40/86] environment: " Christian Couder
  2013-11-17 22:07 ` [PATCH v2 86/86] strbuf: remove prefixcmp() as it has been replaced " Christian Couder
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Couder @ 2013-11-17 22:06 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Avery Pennarun, Johannes Schindelin, Jonathan Nieder,
	Jeff King, Max Horn, Andreas Ericsson

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 transport-helper.c | 16 ++++++++--------
 transport.c        | 28 ++++++++++++++--------------
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/transport-helper.c b/transport-helper.c
index b32e2d6..96de26d 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -190,7 +190,7 @@ static struct child_process *get_helper(struct transport *transport)
 			data->export = 1;
 		else if (!strcmp(capname, "check-connectivity"))
 			data->check_connectivity = 1;
-		else if (!data->refspecs && !prefixcmp(capname, "refspec ")) {
+		else if (!data->refspecs && starts_with(capname, "refspec ")) {
 			ALLOC_GROW(refspecs,
 				   refspec_nr + 1,
 				   refspec_alloc);
@@ -199,17 +199,17 @@ static struct child_process *get_helper(struct transport *transport)
 			data->connect = 1;
 		} else if (!strcmp(capname, "signed-tags")) {
 			data->signed_tags = 1;
-		} else if (!prefixcmp(capname, "export-marks ")) {
+		} else if (starts_with(capname, "export-marks ")) {
 			struct strbuf arg = STRBUF_INIT;
 			strbuf_addstr(&arg, "--export-marks=");
 			strbuf_addstr(&arg, capname + strlen("export-marks "));
 			data->export_marks = strbuf_detach(&arg, NULL);
-		} else if (!prefixcmp(capname, "import-marks")) {
+		} else if (starts_with(capname, "import-marks")) {
 			struct strbuf arg = STRBUF_INIT;
 			strbuf_addstr(&arg, "--import-marks=");
 			strbuf_addstr(&arg, capname + strlen("import-marks "));
 			data->import_marks = strbuf_detach(&arg, NULL);
-		} else if (!prefixcmp(capname, "no-private-update")) {
+		} else if (starts_with(capname, "no-private-update")) {
 			data->no_private_update = 1;
 		} else if (mandatory) {
 			die("Unknown mandatory capability %s. This remote "
@@ -310,7 +310,7 @@ static int set_helper_option(struct transport *transport,
 
 	if (!strcmp(buf.buf, "ok"))
 		ret = 0;
-	else if (!prefixcmp(buf.buf, "error")) {
+	else if (starts_with(buf.buf, "error")) {
 		ret = -1;
 	} else if (!strcmp(buf.buf, "unsupported"))
 		ret = 1;
@@ -374,7 +374,7 @@ static int fetch_with_fetch(struct transport *transport,
 	while (1) {
 		recvline(data, &buf);
 
-		if (!prefixcmp(buf.buf, "lock ")) {
+		if (starts_with(buf.buf, "lock ")) {
 			const char *name = buf.buf + 5;
 			if (transport->pack_lockfile)
 				warning("%s also locked %s", data->name, name);
@@ -645,10 +645,10 @@ static int push_update_ref_status(struct strbuf *buf,
 	char *refname, *msg;
 	int status;
 
-	if (!prefixcmp(buf->buf, "ok ")) {
+	if (starts_with(buf->buf, "ok ")) {
 		status = REF_STATUS_OK;
 		refname = buf->buf + 3;
-	} else if (!prefixcmp(buf->buf, "error ")) {
+	} else if (starts_with(buf->buf, "error ")) {
 		status = REF_STATUS_REMOTE_REJECT;
 		refname = buf->buf + 6;
 	} else
diff --git a/transport.c b/transport.c
index 7202b77..8023956 100644
--- a/transport.c
+++ b/transport.c
@@ -169,13 +169,13 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 		remotename = ref->name;
 		tmp = resolve_ref_unsafe(localname, sha, 1, &flag);
 		if (tmp && flag & REF_ISSYMREF &&
-			!prefixcmp(tmp, "refs/heads/"))
+			starts_with(tmp, "refs/heads/"))
 			localname = tmp;
 
 		/* Both source and destination must be local branches. */
-		if (!localname || prefixcmp(localname, "refs/heads/"))
+		if (!localname || !starts_with(localname, "refs/heads/"))
 			continue;
-		if (!remotename || prefixcmp(remotename, "refs/heads/"))
+		if (!remotename || !starts_with(remotename, "refs/heads/"))
 			continue;
 
 		if (!pretend)
@@ -191,7 +191,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 
 static const char *rsync_url(const char *url)
 {
-	return prefixcmp(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
+	return !starts_with(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
 }
 
 static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
@@ -296,8 +296,8 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
 	FILE *f;
 
 	/* when called via for_each_ref(), flags is non-zero */
-	if (flags && prefixcmp(name, "refs/heads/") &&
-			prefixcmp(name, "refs/tags/"))
+	if (flags && !starts_with(name, "refs/heads/") &&
+			!starts_with(name, "refs/tags/"))
 		return 0;
 
 	strbuf_addstr(buf, name);
@@ -652,7 +652,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
 		print_ref_status('-', "[deleted]", ref, NULL, NULL, porcelain);
 	else if (is_null_sha1(ref->old_sha1))
 		print_ref_status('*',
-			(!prefixcmp(ref->name, "refs/tags/") ? "[new tag]" :
+			(starts_with(ref->name, "refs/tags/") ? "[new tag]" :
 			"[new branch]"),
 			ref, ref->peer_ref, NULL, porcelain);
 	else {
@@ -930,13 +930,13 @@ struct transport *transport_get(struct remote *remote, const char *url)
 
 		while (is_urlschemechar(p == url, *p))
 			p++;
-		if (!prefixcmp(p, "::"))
+		if (starts_with(p, "::"))
 			helper = xstrndup(url, p - url);
 	}
 
 	if (helper) {
 		transport_helper_init(ret, helper);
-	} else if (!prefixcmp(url, "rsync:")) {
+	} else if (starts_with(url, "rsync:")) {
 		ret->get_refs_list = get_refs_via_rsync;
 		ret->fetch = fetch_objs_via_rsync;
 		ret->push = rsync_transport_push;
@@ -949,11 +949,11 @@ struct transport *transport_get(struct remote *remote, const char *url)
 		ret->disconnect = close_bundle;
 		ret->smart_options = NULL;
 	} else if (!is_url(url)
-		|| !prefixcmp(url, "file://")
-		|| !prefixcmp(url, "git://")
-		|| !prefixcmp(url, "ssh://")
-		|| !prefixcmp(url, "git+ssh://")
-		|| !prefixcmp(url, "ssh+git://")) {
+		|| starts_with(url, "file://")
+		|| starts_with(url, "git://")
+		|| starts_with(url, "ssh://")
+		|| starts_with(url, "git+ssh://")
+		|| starts_with(url, "ssh+git://")) {
 		/* These are builtin smart transports. */
 		struct git_transport_data *data = xcalloc(1, sizeof(*data));
 		ret->data = data;
-- 
1.8.4.1.561.g12affca

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 40/86] environment: replace prefixcmp() with starts_with()
  2013-11-17 22:05 [PATCH v2 00/86] replace prefixcmp() with starts_with() Christian Couder
                   ` (2 preceding siblings ...)
  2013-11-17 22:06 ` [PATCH v2 08/86] transport*: " Christian Couder
@ 2013-11-17 22:06 ` Christian Couder
  2013-11-17 22:07 ` [PATCH v2 86/86] strbuf: remove prefixcmp() as it has been replaced " Christian Couder
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Couder @ 2013-11-17 22:06 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Avery Pennarun, Johannes Schindelin, Jonathan Nieder,
	Jeff King, Max Horn, Andreas Ericsson

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 environment.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/environment.c b/environment.c
index 378254c..1270278 100644
--- a/environment.c
+++ b/environment.c
@@ -176,7 +176,7 @@ const char *get_git_namespace(void)
 
 const char *strip_namespace(const char *namespaced_ref)
 {
-	if (prefixcmp(namespaced_ref, get_git_namespace()) != 0)
+	if (!starts_with(namespaced_ref, get_git_namespace()))
 		return NULL;
 	return namespaced_ref + namespace_len;
 }
-- 
1.8.4.1.561.g12affca

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 86/86] strbuf: remove prefixcmp() as it has been replaced with starts_with()
  2013-11-17 22:05 [PATCH v2 00/86] replace prefixcmp() with starts_with() Christian Couder
                   ` (3 preceding siblings ...)
  2013-11-17 22:06 ` [PATCH v2 40/86] environment: " Christian Couder
@ 2013-11-17 22:07 ` Christian Couder
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Couder @ 2013-11-17 22:07 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Avery Pennarun, Johannes Schindelin, Jonathan Nieder,
	Jeff King, Max Horn, Andreas Ericsson

prefixcmp() is now useless as the previous commit replaced it
everywhere with starts_with(). So let's now remove it.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-compat-util.h | 1 -
 strbuf.c          | 9 ---------
 2 files changed, 10 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index e441a6b..c4c01e7 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -350,7 +350,6 @@ extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_lis
 extern void set_error_routine(void (*routine)(const char *err, va_list params));
 extern void set_die_is_recursing_routine(int (*routine)(void));
 
-extern int prefixcmp(const char *str, const char *prefix);
 extern int starts_with(const char *str, const char *prefix);
 extern int ends_with(const char *str, const char *suffix);
 
diff --git a/strbuf.c b/strbuf.c
index 933d998..ee96dcf 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,15 +1,6 @@
 #include "cache.h"
 #include "refs.h"
 
-int prefixcmp(const char *str, const char *prefix)
-{
-	for (; ; str++, prefix++)
-		if (!*prefix)
-			return 0;
-		else if (*str != *prefix)
-			return (unsigned char)*prefix - (unsigned char)*str;
-}
-
 int starts_with(const char *str, const char *prefix)
 {
 	for (; ; str++, prefix++)
-- 
1.8.4.1.561.g12affca

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-11-19 21:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-17 22:05 [PATCH v2 00/86] replace prefixcmp() with starts_with() Christian Couder
2013-11-17 22:05 ` [PATCH v2 01/86] strbuf: add starts_with() to be used instead of prefixcmp() Christian Couder
2013-11-17 22:05 ` [PATCH v2 02/86] diff: replace prefixcmp() with starts_with() Christian Couder
2013-11-17 22:06 ` [PATCH v2 08/86] transport*: " Christian Couder
2013-11-17 22:06 ` [PATCH v2 40/86] environment: " Christian Couder
2013-11-17 22:07 ` [PATCH v2 86/86] strbuf: remove prefixcmp() as it has been replaced " Christian Couder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).