From: Junio C Hamano Date: Tue, 14 Oct 2014 17:50:07 +0000 (-0700) Subject: Merge branch 'rs/more-uses-of-skip-prefix' X-Git-Tag: v2.2.0-rc0~49 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/145c590df8131abe510adde677eb3121cf52d31e?ds=inline;hp=-c Merge branch 'rs/more-uses-of-skip-prefix' * rs/more-uses-of-skip-prefix: use skip_prefix() to avoid more magic numbers --- 145c590df8131abe510adde677eb3121cf52d31e diff --combined builtin/apply.c index 69efb0e4df,97f7e8e499..6696ea4c3f --- a/builtin/apply.c +++ b/builtin/apply.c @@@ -7,7 -7,6 +7,7 @@@ * */ #include "cache.h" +#include "lockfile.h" #include "cache-tree.h" #include "quote.h" #include "blob.h" @@@ -436,7 -435,7 +436,7 @@@ static unsigned long linelen(const cha static int is_dev_null(const char *str) { - return !memcmp("/dev/null", str, 9) && isspace(str[9]); + return skip_prefix(str, "/dev/null", &str) && isspace(*str); } #define TERM_SPACE 1 diff --combined builtin/checkout.c index 570bb09c4f,cef1996d16..b4decd5b19 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -1,5 -1,5 +1,5 @@@ -#include "cache.h" #include "builtin.h" +#include "lockfile.h" #include "parse-options.h" #include "refs.h" #include "commit.h" @@@ -1150,10 -1150,8 +1150,8 @@@ int cmd_checkout(int argc, const char * const char *argv0 = argv[0]; if (!argc || !strcmp(argv0, "--")) die (_("--track needs a branch name")); - if (starts_with(argv0, "refs/")) - argv0 += 5; - if (starts_with(argv0, "remotes/")) - argv0 += 8; + skip_prefix(argv0, "refs/", &argv0); + skip_prefix(argv0, "remotes/", &argv0); argv0 = strchr(argv0, '/'); if (!argv0 || !argv0[1]) die (_("Missing branch name; try -b")); diff --combined builtin/commit.c index c2300185ec,cff7802f8f..81dc622a3b --- a/builtin/commit.c +++ b/builtin/commit.c @@@ -6,7 -6,6 +6,7 @@@ */ #include "cache.h" +#include "lockfile.h" #include "cache-tree.h" #include "color.h" #include "dir.h" @@@ -316,8 -315,8 +316,8 @@@ static void refresh_cache_or_die(int re die_resolve_conflict("commit"); } -static char *prepare_index(int argc, const char **argv, const char *prefix, - const struct commit *current_head, int is_status) +static const char *prepare_index(int argc, const char **argv, const char *prefix, + const struct commit *current_head, int is_status) { struct string_list partial; struct pathspec pathspec; @@@ -342,7 -341,7 +342,7 @@@ die(_("unable to create temporary index")); old_index_env = getenv(INDEX_ENVIRONMENT); - setenv(INDEX_ENVIRONMENT, index_lock.filename, 1); + setenv(INDEX_ENVIRONMENT, index_lock.filename.buf, 1); if (interactive_add(argc, argv, prefix, patch_interactive) != 0) die(_("interactive add failed")); @@@ -353,7 -352,7 +353,7 @@@ unsetenv(INDEX_ENVIRONMENT); discard_cache(); - read_cache_from(index_lock.filename); + read_cache_from(index_lock.filename.buf); if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) { if (reopen_lock_file(&index_lock) < 0) die(_("unable to write index file")); @@@ -363,7 -362,7 +363,7 @@@ warning(_("Failed to update main cache tree")); commit_style = COMMIT_NORMAL; - return index_lock.filename; + return index_lock.filename.buf; } /* @@@ -386,7 -385,7 +386,7 @@@ if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK)) die(_("unable to write new_index file")); commit_style = COMMIT_NORMAL; - return index_lock.filename; + return index_lock.filename.buf; } /* @@@ -473,9 -472,9 +473,9 @@@ die(_("unable to write temporary index file")); discard_cache(); - read_cache_from(false_lock.filename); + read_cache_from(false_lock.filename.buf); - return false_lock.filename; + return false_lock.filename.buf; } static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn, @@@ -1295,6 -1294,7 +1295,7 @@@ static int parse_status_slot(const cha static int git_status_config(const char *k, const char *v, void *cb) { struct wt_status *s = cb; + const char *slot_name; if (starts_with(k, "column.")) return git_column_config(k, v, "status", &s->colopts); @@@ -1324,8 -1324,9 +1325,9 @@@ s->display_comment_prefix = git_config_bool(k, v); return 0; } - if (starts_with(k, "status.color.") || starts_with(k, "color.status.")) { - int slot = parse_status_slot(k, 13); + if (skip_prefix(k, "status.color.", &slot_name) || + skip_prefix(k, "color.status.", &slot_name)) { + int slot = parse_status_slot(k, slot_name - k); if (slot < 0) return 0; if (!v) @@@ -1514,13 -1515,11 +1516,11 @@@ static void print_summary(const char *p diff_setup_done(&rev.diffopt); head = resolve_ref_unsafe("HEAD", junk_sha1, 0, NULL); - printf("[%s%s ", - starts_with(head, "refs/heads/") ? - head + 11 : - !strcmp(head, "HEAD") ? - _("detached HEAD") : - head, - initial_commit ? _(" (root-commit)") : ""); + if (!strcmp(head, "HEAD")) + head = _("detached HEAD"); + else + skip_prefix(head, "refs/heads/", &head); + printf("[%s%s ", head, initial_commit ? _(" (root-commit)") : ""); if (!log_tree_commit(&rev, commit)) { rev.always_show_header = 1;