Merge branch 'rs/more-uses-of-skip-prefix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 14 Oct 2014 17:50:07 +0000 (10:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Oct 2014 17:50:07 +0000 (10:50 -0700)
* rs/more-uses-of-skip-prefix:
use skip_prefix() to avoid more magic numbers

1  2 
builtin/apply.c
builtin/checkout.c
builtin/commit.c
diff --combined builtin/apply.c
index 69efb0e4df1514cf20830d180165fd58dc633fd7,97f7e8e499a69d7cb34be723a2f881365aa90347..6696ea4c3ffd4f7af04f3f56609a78a74a0a0b55
@@@ -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 570bb09c4f176ff21d593361261ec008c3a89739,cef1996d1663fb2f5d4b910bfd1661ebe2fe042b..b4decd5b19c6ec9399f80c7a063343331fe8fd38
@@@ -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 c2300185ec99ee26fdebba0197f24c23001552c9,cff7802f8f32a174c91e2182f224496f702740b3..81dc622a3b72040daca199f05d0a3322f316e6f6
@@@ -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;
                        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"));
                        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"));
                        warning(_("Failed to update main cache tree"));
  
                commit_style = COMMIT_NORMAL;
 -              return index_lock.filename;
 +              return index_lock.filename.buf;
        }
  
        /*
                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;
        }
  
        /*
                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);
                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;