{"thread":{"id":"35358","subject":"[PATCH v2 01/86] strbuf: add starts_with() to be used instead of prefixcmp()","startedAt":"2013-11-17T22:05:52Z","lastAt":"2013-11-17T22:07:18Z","messageCount":6,"participants":["Christian Couder"],"isPatch":true,"patchVersion":2,"patchTotal":86},"messages":[{"id":"230808","messageId":"20131117215732.4386.19345.chriscool@tuxfamily.org","threadId":"35358","inReplyTo":null,"subject":"[PATCH v2 00/86] replace prefixcmp() with starts_with()","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-11-17T22:05:52Z","receivedAt":"2013-11-17T22:05:52Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Here is a resend of a big patch series to replace prefixcmp()\nwith a new starts_with() function.\n\nThe changes since the previous version are the following\n\n\t- the function to replace prefixcmp() is now\n\t  starts_with()\n\t- the mispelling of prefixcmp() in the titles\n\t  of the patches and emails is fixed\n\nThe first patch of this series introduces starts_with() and\nthe last patch removes prefixcmp().\n\nExcept a few patches, it's possible to generate the patches\nin between using a script like the following: \n\n===\n#!/bin/bash\n\nperl -pi -e 's/!prefixcmp\\(/starts_with\\(/g' \"$1\"\nperl -pi -e 's/prefixcmp\\(/!starts_with\\(/g' \"$1\"\n\ngit commit -m \"$1: replace prefixcmp() with starts_with()\" \"$1\"\n===\n\nThe few special cases are the following ones:\n\n        - remote*: replace prefixcmp() with starts_with()\n        - transport*: replace prefixcmp() with starts_with()\n        - environment: replace prefixcmp() with starts_with()\n\nIn first 2 cases above, I processed a few files at the same\ntime instead of just one.\n\nIn the case of \"environment\", I removed \" != 0\" after\n\"!starts_with(...)\" as it is not necessary and makes it\nmore difficult to understand the logic.\n\nOf course it's possible to squash many of the commits\ntogether if it is prefered.\n\n\nChristian Couder (86):\n  strbuf: add starts_with() to be used instead of prefixcmp()\n  diff: replace prefixcmp() with starts_with()\n  fast-import: replace prefixcmp() with starts_with()\n  remote*: replace prefixcmp() with starts_with()\n  daemon: replace prefixcmp() with starts_with()\n  pretty: replace prefixcmp() with starts_with()\n  revision: replace prefixcmp() with starts_with()\n  transport*: replace prefixcmp() with starts_with()\n  config: replace prefixcmp() with starts_with()\n  sha1_name: replace prefixcmp() with starts_with()\n  wt-status: replace prefixcmp() with starts_with()\n  upload-pack: replace prefixcmp() with starts_with()\n  test-line-buffer: replace prefixcmp() with starts_with()\n  parse-options: replace prefixcmp() with starts_with()\n  fetch-pack: replace prefixcmp() with starts_with()\n  git: replace prefixcmp() with starts_with()\n  tag: replace prefixcmp() with starts_with()\n  sequencer: replace prefixcmp() with starts_with()\n  commit: replace prefixcmp() with starts_with()\n  http: replace prefixcmp() with starts_with()\n  imap-send: replace prefixcmp() with starts_with()\n  help: replace prefixcmp() with starts_with()\n  log-tree: replace prefixcmp() with starts_with()\n  merge-recursive: replace prefixcmp() with starts_with()\n  notes: replace prefixcmp() with starts_with()\n  refs: replace prefixcmp() with starts_with()\n  setup: replace prefixcmp() with starts_with()\n  bisect: replace prefixcmp() with starts_with()\n  branch: replace prefixcmp() with starts_with()\n  http-push: replace prefixcmp() with starts_with()\n  send-pack: replace prefixcmp() with starts_with()\n  http-backend: replace prefixcmp() with starts_with()\n  notes-utils: replace prefixcmp() with starts_with()\n  pkt-line: replace prefixcmp() with starts_with()\n  alias: replace prefixcmp() with starts_with()\n  attr: replace prefixcmp() with starts_with()\n  connect: replace prefixcmp() with starts_with()\n  pager: replace prefixcmp() with starts_with()\n  convert: replace prefixcmp() with starts_with()\n  environment: replace prefixcmp() with starts_with()\n  shell: replace prefixcmp() with starts_with()\n  pathspec: replace prefixcmp() with starts_with()\n  submodule: replace prefixcmp() with starts_with()\n  test-string-list: replace prefixcmp() with starts_with()\n  builtin/apply: replace prefixcmp() with starts_with()\n  builtin/archive: replace prefixcmp() with starts_with()\n  builtin/branch: replace prefixcmp() with starts_with()\n  builtin/checkout: replace prefixcmp() with starts_with()\n  builtin/clean: replace prefixcmp() with starts_with()\n  builtin/clone: replace prefixcmp() with starts_with()\n  builtin/column: replace prefixcmp() with starts_with()\n  builtin/commit: replace prefixcmp() with starts_with()\n  builtin/describe: replace prefixcmp() with starts_with()\n  builtin/fast-export: replace prefixcmp() with starts_with()\n  builtin/fetch-pack: replace prefixcmp() with starts_with()\n  builtin/fetch: replace prefixcmp() with starts_with()\n  builtin/fmt-merge-msg: replace prefixcmp() with starts_with()\n  builtin/for-each-ref: replace prefixcmp() with starts_with()\n  builtin/fsck: replace prefixcmp() with starts_with()\n  builtin/help: replace prefixcmp() with starts_with()\n  builtin/index-pack: replace prefixcmp() with starts_with()\n  builtin/init-db: replace prefixcmp() with starts_with()\n  builtin/log: replace prefixcmp() with starts_with()\n  builtin/ls-remote: replace prefixcmp() with starts_with()\n  builtin/mailinfo: replace prefixcmp() with starts_with()\n  builtin/merge-recursive: replace prefixcmp() with starts_with()\n  builtin/merge: replace prefixcmp() with starts_with()\n  builtin/name-rev: replace prefixcmp() with starts_with()\n  builtin/notes: replace prefixcmp() with starts_with()\n  builtin/pack-objects: replace prefixcmp() with starts_with()\n  builtin/prune: replace prefixcmp() with starts_with()\n  builtin/receive-pack: replace prefixcmp() with starts_with()\n  builtin/reflog: replace prefixcmp() with starts_with()\n  builtin/remote: replace prefixcmp() with starts_with()\n  builtin/rev-parse: replace prefixcmp() with starts_with()\n  builtin/send-pack: replace prefixcmp() with starts_with()\n  builtin/shortlog: replace prefixcmp() with starts_with()\n  builtin/show-branch: replace prefixcmp() with starts_with()\n  builtin/show-ref: replace prefixcmp() with starts_with()\n  builtin/symbolic-ref: replace prefixcmp() with starts_with()\n  builtin/tag: replace prefixcmp() with starts_with()\n  builtin/tar-tree: replace prefixcmp() with starts_with()\n  builtin/unpack-objects: replace prefixcmp() with starts_with()\n  builtin/update-ref: replace prefixcmp() with starts_with()\n  builtin/upload-archive: replace prefixcmp() with starts_with()\n  strbuf: remove prefixcmp() as it has been replaced with starts_with()\n\n alias.c                   |  2 +-\n attr.c                    |  2 +-\n bisect.c                  |  4 +--\n branch.c                  |  4 +--\n builtin/apply.c           | 12 +++----\n builtin/archive.c         |  4 +--\n builtin/branch.c          |  6 ++--\n builtin/checkout.c        |  8 ++---\n builtin/clean.c           |  4 +--\n builtin/clone.c           |  6 ++--\n builtin/column.c          |  2 +-\n builtin/commit.c          | 10 +++---\n builtin/describe.c        |  2 +-\n builtin/fast-export.c     |  2 +-\n builtin/fetch-pack.c      |  6 ++--\n builtin/fetch.c           | 16 +++++-----\n builtin/fmt-merge-msg.c   | 10 +++---\n builtin/for-each-ref.c    | 14 ++++-----\n builtin/fsck.c            |  6 ++--\n builtin/help.c            |  8 ++---\n builtin/index-pack.c      |  8 ++---\n builtin/init-db.c         |  2 +-\n builtin/log.c             |  8 ++---\n builtin/ls-remote.c       |  4 +--\n builtin/mailinfo.c        | 16 +++++-----\n builtin/merge-recursive.c |  2 +-\n builtin/merge.c           | 12 +++----\n builtin/name-rev.c        |  6 ++--\n builtin/notes.c           |  2 +-\n builtin/pack-objects.c    |  2 +-\n builtin/prune.c           |  4 +--\n builtin/receive-pack.c    |  6 ++--\n builtin/reflog.c          |  4 +--\n builtin/remote.c          |  8 ++---\n builtin/rev-parse.c       | 24 +++++++-------\n builtin/send-pack.c       |  8 ++---\n builtin/shortlog.c        |  6 ++--\n builtin/show-branch.c     | 20 ++++++------\n builtin/show-ref.c        |  6 ++--\n builtin/symbolic-ref.c    |  2 +-\n builtin/tag.c             |  2 +-\n builtin/tar-tree.c        |  2 +-\n builtin/unpack-objects.c  |  2 +-\n builtin/update-ref.c      | 10 +++---\n builtin/upload-archive.c  |  2 +-\n commit.c                  |  6 ++--\n config.c                  | 16 +++++-----\n connect.c                 |  2 +-\n convert.c                 |  2 +-\n daemon.c                  | 40 ++++++++++++------------\n diff.c                    | 56 ++++++++++++++++-----------------\n environment.c             |  2 +-\n fast-import.c             | 80 +++++++++++++++++++++++------------------------\n fetch-pack.c              | 12 +++----\n git-compat-util.h         |  2 +-\n git.c                     | 12 +++----\n help.c                    |  8 ++---\n http-backend.c            |  4 +--\n http-push.c               |  4 +--\n http.c                    |  8 ++---\n imap-send.c               | 10 +++---\n log-tree.c                |  8 ++---\n merge-recursive.c         |  6 ++--\n notes-utils.c             |  4 +--\n notes.c                   |  8 ++---\n pager.c                   |  2 +-\n parse-options.c           | 12 +++----\n pathspec.c                |  2 +-\n pkt-line.c                |  4 +--\n pretty.c                  | 36 ++++++++++-----------\n refs.c                    | 30 +++++++++---------\n remote-curl.c             | 14 ++++-----\n remote-testsvn.c          | 10 +++---\n remote.c                  | 46 +++++++++++++--------------\n revision.c                | 38 +++++++++++-----------\n send-pack.c               |  4 +--\n sequencer.c               |  8 ++---\n setup.c                   |  4 +--\n sha1_name.c               | 16 +++++-----\n shell.c                   |  2 +-\n strbuf.c                  |  6 ++--\n submodule.c               |  2 +-\n tag.c                     | 10 +++---\n test-line-buffer.c        |  6 ++--\n test-string-list.c        |  2 +-\n transport-helper.c        | 16 +++++-----\n transport.c               | 28 ++++++++---------\n upload-pack.c             | 10 +++---\n wt-status.c               | 16 +++++-----\n 89 files changed, 455 insertions(+), 455 deletions(-)\n\n-- \n1.8.4.1.561.g12affca\n"},{"id":"230807","messageId":"20131117220719.4386.5213.chriscool@tuxfamily.org","threadId":"35358","inReplyTo":"20131117215732.4386.19345.chriscool@tuxfamily.org","subject":"[PATCH v2 01/86] strbuf: add starts_with() to be used instead of prefixcmp()","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-11-17T22:05:53Z","receivedAt":"2013-11-17T22:05:53Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"prefixcmp() cannot be really used as a comparison function as\nit is not antisymmetric:\n\n\tprefixcmp(\"foo\", \"foobar\") < 0\n\tprefixcmp(\"foobar\", \"foo\") == 0\n\nSo it is not suitable as a function for passing to qsort.\nAnd in fact it is used nowhere as a comparison function.\n\nSo we should replace it with a function that just checks for\nequality.\n\nAs a first step toward this goal, this patch introduces\nstarts_with().\n\nSome popular programming languages have functions or methods\ncalled using \"start\" and \"with\" that are doing what we want.\nTherefore it makes sense to use starts_with() as a function\nname to replace prefixcmp().\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n git-compat-util.h | 1 +\n strbuf.c          | 9 +++++++++\n 2 files changed, 10 insertions(+)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 37f0ba0..e441a6b 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -351,6 +351,7 @@ extern void set_error_routine(void (*routine)(const char *err, va_list params));\n extern void set_die_is_recursing_routine(int (*routine)(void));\n \n extern int prefixcmp(const char *str, const char *prefix);\n+extern int starts_with(const char *str, const char *prefix);\n extern int ends_with(const char *str, const char *suffix);\n \n static inline const char *skip_prefix(const char *str, const char *prefix)\ndiff --git a/strbuf.c b/strbuf.c\nindex 2a14fdb..933d998 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -10,6 +10,15 @@ int prefixcmp(const char *str, const char *prefix)\n \t\t\treturn (unsigned char)*prefix - (unsigned char)*str;\n }\n \n+int starts_with(const char *str, const char *prefix)\n+{\n+\tfor (; ; str++, prefix++)\n+\t\tif (!*prefix)\n+\t\t\treturn 1;\n+\t\telse if (*str != *prefix)\n+\t\t\treturn 0;\n+}\n+\n int ends_with(const char *str, const char *suffix)\n {\n \tint len = strlen(str), suflen = strlen(suffix);\n-- \n1.8.4.1.561.g12affca\n"},{"id":"230809","messageId":"20131117220719.4386.53158.chriscool@tuxfamily.org","threadId":"35358","inReplyTo":"20131117215732.4386.19345.chriscool@tuxfamily.org","subject":"[PATCH v2 02/86] diff: replace prefixcmp() with starts_with()","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-11-17T22:05:54Z","receivedAt":"2013-11-17T22:05:54Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n diff.c | 56 ++++++++++++++++++++++++++++----------------------------\n 1 file changed, 28 insertions(+), 28 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex a04a34d..4b42997 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -235,7 +235,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)\n \tif (userdiff_config(var, value) < 0)\n \t\treturn -1;\n \n-\tif (!prefixcmp(var, \"diff.color.\") || !prefixcmp(var, \"color.diff.\")) {\n+\tif (starts_with(var, \"diff.color.\") || starts_with(var, \"color.diff.\")) {\n \t\tint slot = parse_diff_color_slot(var, 11);\n \t\tif (slot < 0)\n \t\t\treturn 0;\n@@ -264,7 +264,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)\n \t\treturn 0;\n \t}\n \n-\tif (!prefixcmp(var, \"submodule.\"))\n+\tif (starts_with(var, \"submodule.\"))\n \t\treturn parse_submodule_config_option(var, value);\n \n \treturn git_default_config(var, value, cb);\n@@ -1215,7 +1215,7 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)\n \t\t\tdiff_words_append(line, len,\n \t\t\t\t\t  &ecbdata->diff_words->plus);\n \t\t\treturn;\n-\t\t} else if (!prefixcmp(line, \"\\\\ \")) {\n+\t\t} else if (starts_with(line, \"\\\\ \")) {\n \t\t\t/*\n \t\t\t * Eat the \"no newline at eof\" marker as if we\n \t\t\t * saw a \"+\" or \"-\" line with nothing on it,\n@@ -2387,9 +2387,9 @@ static void builtin_diff(const char *name_a,\n \t\t\txdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);\n \t\tif (!diffopts)\n \t\t\t;\n-\t\telse if (!prefixcmp(diffopts, \"--unified=\"))\n+\t\telse if (starts_with(diffopts, \"--unified=\"))\n \t\t\txecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);\n-\t\telse if (!prefixcmp(diffopts, \"-u\"))\n+\t\telse if (starts_with(diffopts, \"-u\"))\n \t\t\txecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);\n \t\tif (o->word_diff)\n \t\t\tinit_diff_words_data(&ecbdata, o, one, two);\n@@ -3388,7 +3388,7 @@ int parse_long_opt(const char *opt, const char **argv,\n \tif (arg[0] != '-' || arg[1] != '-')\n \t\treturn 0;\n \targ += strlen(\"--\");\n-\tif (prefixcmp(arg, opt))\n+\tif (!starts_with(arg, opt))\n \t\treturn 0;\n \targ += strlen(opt);\n \tif (*arg == '=') { /* sticked form: --option=value */\n@@ -3419,7 +3419,7 @@ static int stat_opt(struct diff_options *options, const char **av)\n \n \tswitch (*arg) {\n \tcase '-':\n-\t\tif (!prefixcmp(arg, \"-width\")) {\n+\t\tif (starts_with(arg, \"-width\")) {\n \t\t\targ += strlen(\"-width\");\n \t\t\tif (*arg == '=')\n \t\t\t\twidth = strtoul(arg + 1, &end, 10);\n@@ -3429,7 +3429,7 @@ static int stat_opt(struct diff_options *options, const char **av)\n \t\t\t\twidth = strtoul(av[1], &end, 10);\n \t\t\t\targcount = 2;\n \t\t\t}\n-\t\t} else if (!prefixcmp(arg, \"-name-width\")) {\n+\t\t} else if (starts_with(arg, \"-name-width\")) {\n \t\t\targ += strlen(\"-name-width\");\n \t\t\tif (*arg == '=')\n \t\t\t\tname_width = strtoul(arg + 1, &end, 10);\n@@ -3439,7 +3439,7 @@ static int stat_opt(struct diff_options *options, const char **av)\n \t\t\t\tname_width = strtoul(av[1], &end, 10);\n \t\t\t\targcount = 2;\n \t\t\t}\n-\t\t} else if (!prefixcmp(arg, \"-graph-width\")) {\n+\t\t} else if (starts_with(arg, \"-graph-width\")) {\n \t\t\targ += strlen(\"-graph-width\");\n \t\t\tif (*arg == '=')\n \t\t\t\tgraph_width = strtoul(arg + 1, &end, 10);\n@@ -3449,7 +3449,7 @@ static int stat_opt(struct diff_options *options, const char **av)\n \t\t\t\tgraph_width = strtoul(av[1], &end, 10);\n \t\t\t\targcount = 2;\n \t\t\t}\n-\t\t} else if (!prefixcmp(arg, \"-count\")) {\n+\t\t} else if (starts_with(arg, \"-count\")) {\n \t\t\targ += strlen(\"-count\");\n \t\t\tif (*arg == '=')\n \t\t\t\tcount = strtoul(arg + 1, &end, 10);\n@@ -3611,15 +3611,15 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\toptions->output_format |= DIFF_FORMAT_SHORTSTAT;\n \telse if (!strcmp(arg, \"-X\") || !strcmp(arg, \"--dirstat\"))\n \t\treturn parse_dirstat_opt(options, \"\");\n-\telse if (!prefixcmp(arg, \"-X\"))\n+\telse if (starts_with(arg, \"-X\"))\n \t\treturn parse_dirstat_opt(options, arg + 2);\n-\telse if (!prefixcmp(arg, \"--dirstat=\"))\n+\telse if (starts_with(arg, \"--dirstat=\"))\n \t\treturn parse_dirstat_opt(options, arg + 10);\n \telse if (!strcmp(arg, \"--cumulative\"))\n \t\treturn parse_dirstat_opt(options, \"cumulative\");\n \telse if (!strcmp(arg, \"--dirstat-by-file\"))\n \t\treturn parse_dirstat_opt(options, \"files\");\n-\telse if (!prefixcmp(arg, \"--dirstat-by-file=\")) {\n+\telse if (starts_with(arg, \"--dirstat-by-file=\")) {\n \t\tparse_dirstat_opt(options, \"files\");\n \t\treturn parse_dirstat_opt(options, arg + 18);\n \t}\n@@ -3636,17 +3636,17 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\toptions->output_format |= DIFF_FORMAT_NAME_STATUS;\n \telse if (!strcmp(arg, \"-s\") || !strcmp(arg, \"--no-patch\"))\n \t\toptions->output_format |= DIFF_FORMAT_NO_OUTPUT;\n-\telse if (!prefixcmp(arg, \"--stat\"))\n+\telse if (starts_with(arg, \"--stat\"))\n \t\t/* --stat, --stat-width, --stat-name-width, or --stat-count */\n \t\treturn stat_opt(options, av);\n \n \t/* renames options */\n-\telse if (!prefixcmp(arg, \"-B\") || !prefixcmp(arg, \"--break-rewrites=\") ||\n+\telse if (starts_with(arg, \"-B\") || starts_with(arg, \"--break-rewrites=\") ||\n \t\t !strcmp(arg, \"--break-rewrites\")) {\n \t\tif ((options->break_opt = diff_scoreopt_parse(arg)) == -1)\n \t\t\treturn error(\"invalid argument to -B: %s\", arg+2);\n \t}\n-\telse if (!prefixcmp(arg, \"-M\") || !prefixcmp(arg, \"--find-renames=\") ||\n+\telse if (starts_with(arg, \"-M\") || starts_with(arg, \"--find-renames=\") ||\n \t\t !strcmp(arg, \"--find-renames\")) {\n \t\tif ((options->rename_score = diff_scoreopt_parse(arg)) == -1)\n \t\t\treturn error(\"invalid argument to -M: %s\", arg+2);\n@@ -3655,7 +3655,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \telse if (!strcmp(arg, \"-D\") || !strcmp(arg, \"--irreversible-delete\")) {\n \t\toptions->irreversible_delete = 1;\n \t}\n-\telse if (!prefixcmp(arg, \"-C\") || !prefixcmp(arg, \"--find-copies=\") ||\n+\telse if (starts_with(arg, \"-C\") || starts_with(arg, \"--find-copies=\") ||\n \t\t !strcmp(arg, \"--find-copies\")) {\n \t\tif (options->detect_rename == DIFF_DETECT_COPY)\n \t\t\tDIFF_OPT_SET(options, FIND_COPIES_HARDER);\n@@ -3671,7 +3671,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\tDIFF_OPT_CLR(options, RENAME_EMPTY);\n \telse if (!strcmp(arg, \"--relative\"))\n \t\tDIFF_OPT_SET(options, RELATIVE_NAME);\n-\telse if (!prefixcmp(arg, \"--relative=\")) {\n+\telse if (starts_with(arg, \"--relative=\")) {\n \t\tDIFF_OPT_SET(options, RELATIVE_NAME);\n \t\toptions->prefix = arg + 11;\n \t}\n@@ -3724,7 +3724,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\tDIFF_OPT_CLR(options, FOLLOW_RENAMES);\n \telse if (!strcmp(arg, \"--color\"))\n \t\toptions->use_color = 1;\n-\telse if (!prefixcmp(arg, \"--color=\")) {\n+\telse if (starts_with(arg, \"--color=\")) {\n \t\tint value = git_config_colorbool(NULL, arg+8);\n \t\tif (value < 0)\n \t\t\treturn error(\"option `color' expects \\\"always\\\", \\\"auto\\\", or \\\"never\\\"\");\n@@ -3736,7 +3736,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\toptions->use_color = 1;\n \t\toptions->word_diff = DIFF_WORDS_COLOR;\n \t}\n-\telse if (!prefixcmp(arg, \"--color-words=\")) {\n+\telse if (starts_with(arg, \"--color-words=\")) {\n \t\toptions->use_color = 1;\n \t\toptions->word_diff = DIFF_WORDS_COLOR;\n \t\toptions->word_regex = arg + 14;\n@@ -3745,7 +3745,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\tif (options->word_diff == DIFF_WORDS_NONE)\n \t\t\toptions->word_diff = DIFF_WORDS_PLAIN;\n \t}\n-\telse if (!prefixcmp(arg, \"--word-diff=\")) {\n+\telse if (starts_with(arg, \"--word-diff=\")) {\n \t\tconst char *type = arg + 12;\n \t\tif (!strcmp(type, \"plain\"))\n \t\t\toptions->word_diff = DIFF_WORDS_PLAIN;\n@@ -3781,12 +3781,12 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \telse if (!strcmp(arg, \"--ignore-submodules\")) {\n \t\tDIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);\n \t\thandle_ignore_submodules_arg(options, \"all\");\n-\t} else if (!prefixcmp(arg, \"--ignore-submodules=\")) {\n+\t} else if (starts_with(arg, \"--ignore-submodules=\")) {\n \t\tDIFF_OPT_SET(options, OVERRIDE_SUBMODULE_CONFIG);\n \t\thandle_ignore_submodules_arg(options, arg + 20);\n \t} else if (!strcmp(arg, \"--submodule\"))\n \t\tDIFF_OPT_SET(options, SUBMODULE_LOG);\n-\telse if (!prefixcmp(arg, \"--submodule=\"))\n+\telse if (starts_with(arg, \"--submodule=\"))\n \t\treturn parse_submodule_opt(options, arg + 12);\n \n \t/* misc options */\n@@ -3822,7 +3822,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t}\n \telse if (!strcmp(arg, \"--abbrev\"))\n \t\toptions->abbrev = DEFAULT_ABBREV;\n-\telse if (!prefixcmp(arg, \"--abbrev=\")) {\n+\telse if (starts_with(arg, \"--abbrev=\")) {\n \t\toptions->abbrev = strtoul(arg + 9, NULL, 10);\n \t\tif (options->abbrev < MINIMUM_ABBREV)\n \t\t\toptions->abbrev = MINIMUM_ABBREV;\n@@ -3904,15 +3904,15 @@ static int diff_scoreopt_parse(const char *opt)\n \tcmd = *opt++;\n \tif (cmd == '-') {\n \t\t/* convert the long-form arguments into short-form versions */\n-\t\tif (!prefixcmp(opt, \"break-rewrites\")) {\n+\t\tif (starts_with(opt, \"break-rewrites\")) {\n \t\t\topt += strlen(\"break-rewrites\");\n \t\t\tif (*opt == 0 || *opt++ == '=')\n \t\t\t\tcmd = 'B';\n-\t\t} else if (!prefixcmp(opt, \"find-copies\")) {\n+\t\t} else if (starts_with(opt, \"find-copies\")) {\n \t\t\topt += strlen(\"find-copies\");\n \t\t\tif (*opt == 0 || *opt++ == '=')\n \t\t\t\tcmd = 'C';\n-\t\t} else if (!prefixcmp(opt, \"find-renames\")) {\n+\t\t} else if (starts_with(opt, \"find-renames\")) {\n \t\t\topt += strlen(\"find-renames\");\n \t\t\tif (*opt == 0 || *opt++ == '=')\n \t\t\t\tcmd = 'M';\n@@ -4322,7 +4322,7 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)\n \tint new_len;\n \n \t/* Ignore line numbers when computing the SHA1 of the patch */\n-\tif (!prefixcmp(line, \"@@ -\"))\n+\tif (starts_with(line, \"@@ -\"))\n \t\treturn;\n \n \tnew_len = remove_space(line, len);\n-- \n1.8.4.1.561.g12affca\n"},{"id":"230810","messageId":"20131117220719.4386.15982.chriscool@tuxfamily.org","threadId":"35358","inReplyTo":"20131117215732.4386.19345.chriscool@tuxfamily.org","subject":"[PATCH v2 08/86] transport*: replace prefixcmp() with starts_with()","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-11-17T22:06:00Z","receivedAt":"2013-11-17T22:06:00Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n transport-helper.c | 16 ++++++++--------\n transport.c        | 28 ++++++++++++++--------------\n 2 files changed, 22 insertions(+), 22 deletions(-)\n\ndiff --git a/transport-helper.c b/transport-helper.c\nindex b32e2d6..96de26d 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -190,7 +190,7 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tdata->export = 1;\n \t\telse if (!strcmp(capname, \"check-connectivity\"))\n \t\t\tdata->check_connectivity = 1;\n-\t\telse if (!data->refspecs && !prefixcmp(capname, \"refspec \")) {\n+\t\telse if (!data->refspecs && starts_with(capname, \"refspec \")) {\n \t\t\tALLOC_GROW(refspecs,\n \t\t\t\t   refspec_nr + 1,\n \t\t\t\t   refspec_alloc);\n@@ -199,17 +199,17 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tdata->connect = 1;\n \t\t} else if (!strcmp(capname, \"signed-tags\")) {\n \t\t\tdata->signed_tags = 1;\n-\t\t} else if (!prefixcmp(capname, \"export-marks \")) {\n+\t\t} else if (starts_with(capname, \"export-marks \")) {\n \t\t\tstruct strbuf arg = STRBUF_INIT;\n \t\t\tstrbuf_addstr(&arg, \"--export-marks=\");\n \t\t\tstrbuf_addstr(&arg, capname + strlen(\"export-marks \"));\n \t\t\tdata->export_marks = strbuf_detach(&arg, NULL);\n-\t\t} else if (!prefixcmp(capname, \"import-marks\")) {\n+\t\t} else if (starts_with(capname, \"import-marks\")) {\n \t\t\tstruct strbuf arg = STRBUF_INIT;\n \t\t\tstrbuf_addstr(&arg, \"--import-marks=\");\n \t\t\tstrbuf_addstr(&arg, capname + strlen(\"import-marks \"));\n \t\t\tdata->import_marks = strbuf_detach(&arg, NULL);\n-\t\t} else if (!prefixcmp(capname, \"no-private-update\")) {\n+\t\t} else if (starts_with(capname, \"no-private-update\")) {\n \t\t\tdata->no_private_update = 1;\n \t\t} else if (mandatory) {\n \t\t\tdie(\"Unknown mandatory capability %s. This remote \"\n@@ -310,7 +310,7 @@ static int set_helper_option(struct transport *transport,\n \n \tif (!strcmp(buf.buf, \"ok\"))\n \t\tret = 0;\n-\telse if (!prefixcmp(buf.buf, \"error\")) {\n+\telse if (starts_with(buf.buf, \"error\")) {\n \t\tret = -1;\n \t} else if (!strcmp(buf.buf, \"unsupported\"))\n \t\tret = 1;\n@@ -374,7 +374,7 @@ static int fetch_with_fetch(struct transport *transport,\n \twhile (1) {\n \t\trecvline(data, &buf);\n \n-\t\tif (!prefixcmp(buf.buf, \"lock \")) {\n+\t\tif (starts_with(buf.buf, \"lock \")) {\n \t\t\tconst char *name = buf.buf + 5;\n \t\t\tif (transport->pack_lockfile)\n \t\t\t\twarning(\"%s also locked %s\", data->name, name);\n@@ -645,10 +645,10 @@ static int push_update_ref_status(struct strbuf *buf,\n \tchar *refname, *msg;\n \tint status;\n \n-\tif (!prefixcmp(buf->buf, \"ok \")) {\n+\tif (starts_with(buf->buf, \"ok \")) {\n \t\tstatus = REF_STATUS_OK;\n \t\trefname = buf->buf + 3;\n-\t} else if (!prefixcmp(buf->buf, \"error \")) {\n+\t} else if (starts_with(buf->buf, \"error \")) {\n \t\tstatus = REF_STATUS_REMOTE_REJECT;\n \t\trefname = buf->buf + 6;\n \t} else\ndiff --git a/transport.c b/transport.c\nindex 7202b77..8023956 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -169,13 +169,13 @@ static void set_upstreams(struct transport *transport, struct ref *refs,\n \t\tremotename = ref->name;\n \t\ttmp = resolve_ref_unsafe(localname, sha, 1, &flag);\n \t\tif (tmp && flag & REF_ISSYMREF &&\n-\t\t\t!prefixcmp(tmp, \"refs/heads/\"))\n+\t\t\tstarts_with(tmp, \"refs/heads/\"))\n \t\t\tlocalname = tmp;\n \n \t\t/* Both source and destination must be local branches. */\n-\t\tif (!localname || prefixcmp(localname, \"refs/heads/\"))\n+\t\tif (!localname || !starts_with(localname, \"refs/heads/\"))\n \t\t\tcontinue;\n-\t\tif (!remotename || prefixcmp(remotename, \"refs/heads/\"))\n+\t\tif (!remotename || !starts_with(remotename, \"refs/heads/\"))\n \t\t\tcontinue;\n \n \t\tif (!pretend)\n@@ -191,7 +191,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,\n \n static const char *rsync_url(const char *url)\n {\n-\treturn prefixcmp(url, \"rsync://\") ? skip_prefix(url, \"rsync:\") : url;\n+\treturn !starts_with(url, \"rsync://\") ? skip_prefix(url, \"rsync:\") : url;\n }\n \n static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)\n@@ -296,8 +296,8 @@ static int write_one_ref(const char *name, const unsigned char *sha1,\n \tFILE *f;\n \n \t/* when called via for_each_ref(), flags is non-zero */\n-\tif (flags && prefixcmp(name, \"refs/heads/\") &&\n-\t\t\tprefixcmp(name, \"refs/tags/\"))\n+\tif (flags && !starts_with(name, \"refs/heads/\") &&\n+\t\t\t!starts_with(name, \"refs/tags/\"))\n \t\treturn 0;\n \n \tstrbuf_addstr(buf, name);\n@@ -652,7 +652,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)\n \t\tprint_ref_status('-', \"[deleted]\", ref, NULL, NULL, porcelain);\n \telse if (is_null_sha1(ref->old_sha1))\n \t\tprint_ref_status('*',\n-\t\t\t(!prefixcmp(ref->name, \"refs/tags/\") ? \"[new tag]\" :\n+\t\t\t(starts_with(ref->name, \"refs/tags/\") ? \"[new tag]\" :\n \t\t\t\"[new branch]\"),\n \t\t\tref, ref->peer_ref, NULL, porcelain);\n \telse {\n@@ -930,13 +930,13 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \n \t\twhile (is_urlschemechar(p == url, *p))\n \t\t\tp++;\n-\t\tif (!prefixcmp(p, \"::\"))\n+\t\tif (starts_with(p, \"::\"))\n \t\t\thelper = xstrndup(url, p - url);\n \t}\n \n \tif (helper) {\n \t\ttransport_helper_init(ret, helper);\n-\t} else if (!prefixcmp(url, \"rsync:\")) {\n+\t} else if (starts_with(url, \"rsync:\")) {\n \t\tret->get_refs_list = get_refs_via_rsync;\n \t\tret->fetch = fetch_objs_via_rsync;\n \t\tret->push = rsync_transport_push;\n@@ -949,11 +949,11 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \t\tret->disconnect = close_bundle;\n \t\tret->smart_options = NULL;\n \t} else if (!is_url(url)\n-\t\t|| !prefixcmp(url, \"file://\")\n-\t\t|| !prefixcmp(url, \"git://\")\n-\t\t|| !prefixcmp(url, \"ssh://\")\n-\t\t|| !prefixcmp(url, \"git+ssh://\")\n-\t\t|| !prefixcmp(url, \"ssh+git://\")) {\n+\t\t|| starts_with(url, \"file://\")\n+\t\t|| starts_with(url, \"git://\")\n+\t\t|| starts_with(url, \"ssh://\")\n+\t\t|| starts_with(url, \"git+ssh://\")\n+\t\t|| starts_with(url, \"ssh+git://\")) {\n \t\t/* These are builtin smart transports. */\n \t\tstruct git_transport_data *data = xcalloc(1, sizeof(*data));\n \t\tret->data = data;\n-- \n1.8.4.1.561.g12affca\n"},{"id":"230811","messageId":"20131117220719.4386.73779.chriscool@tuxfamily.org","threadId":"35358","inReplyTo":"20131117215732.4386.19345.chriscool@tuxfamily.org","subject":"[PATCH v2 40/86] environment: replace prefixcmp() with starts_with()","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-11-17T22:06:32Z","receivedAt":"2013-11-17T22:06:32Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n environment.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/environment.c b/environment.c\nindex 378254c..1270278 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -176,7 +176,7 @@ const char *get_git_namespace(void)\n \n const char *strip_namespace(const char *namespaced_ref)\n {\n-\tif (prefixcmp(namespaced_ref, get_git_namespace()) != 0)\n+\tif (!starts_with(namespaced_ref, get_git_namespace()))\n \t\treturn NULL;\n \treturn namespaced_ref + namespace_len;\n }\n-- \n1.8.4.1.561.g12affca\n"},{"id":"230812","messageId":"20131117220719.4386.4388.chriscool@tuxfamily.org","threadId":"35358","inReplyTo":"20131117215732.4386.19345.chriscool@tuxfamily.org","subject":"[PATCH v2 86/86] strbuf: remove prefixcmp() as it has been replaced with starts_with()","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-11-17T22:07:18Z","receivedAt":"2013-11-17T22:07:18Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"prefixcmp() is now useless as the previous commit replaced it\neverywhere with starts_with(). So let's now remove it.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n git-compat-util.h | 1 -\n strbuf.c          | 9 ---------\n 2 files changed, 10 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex e441a6b..c4c01e7 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -350,7 +350,6 @@ extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_lis\n extern void set_error_routine(void (*routine)(const char *err, va_list params));\n extern void set_die_is_recursing_routine(int (*routine)(void));\n \n-extern int prefixcmp(const char *str, const char *prefix);\n extern int starts_with(const char *str, const char *prefix);\n extern int ends_with(const char *str, const char *suffix);\n \ndiff --git a/strbuf.c b/strbuf.c\nindex 933d998..ee96dcf 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -1,15 +1,6 @@\n #include \"cache.h\"\n #include \"refs.h\"\n \n-int prefixcmp(const char *str, const char *prefix)\n-{\n-\tfor (; ; str++, prefix++)\n-\t\tif (!*prefix)\n-\t\t\treturn 0;\n-\t\telse if (*str != *prefix)\n-\t\t\treturn (unsigned char)*prefix - (unsigned char)*str;\n-}\n-\n int starts_with(const char *str, const char *prefix)\n {\n \tfor (; ; str++, prefix++)\n-- \n1.8.4.1.561.g12affca\n"}]}