Merge branch 'rs/checkout-init-macro'
authorJunio C Hamano <gitster@pobox.com>
Mon, 26 Sep 2016 23:09:21 +0000 (16:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Sep 2016 23:09:21 +0000 (16:09 -0700)
Code cleanup.

* rs/checkout-init-macro:
introduce CHECKOUT_INIT

1  2 
builtin/checkout.c
cache.h
diff --combined builtin/checkout.c
index f4b24a432a5df8e25891134b1632b3e5c6d7f0d2,4c8627208708adad9da51bb9b98917c48a5d838a..9b2a5b31d423ae2f27756df8deab2d9f2fe18ddc
@@@ -239,7 -239,7 +239,7 @@@ static int checkout_paths(const struct 
                          const char *revision)
  {
        int pos;
-       struct checkout state;
+       struct checkout state = CHECKOUT_INIT;
        static char *ps_matched;
        struct object_id rev;
        struct commit *head;
                return 1;
  
        /* Now we are committed to check them out */
-       memset(&state, 0, sizeof(state));
        state.force = 1;
        state.refresh_cache = 1;
        state.istate = &the_index;
@@@ -548,7 -547,7 +547,7 @@@ static int merge_working_tree(const str
                         * entries in the index.
                         */
  
 -                      add_files_to_cache(NULL, NULL, 0, 0);
 +                      add_files_to_cache(NULL, NULL, 0);
                        /*
                         * NEEDSWORK: carrying over local changes
                         * when branches have different end-of-line
@@@ -985,7 -984,7 +984,7 @@@ static int parse_branchname_arg(int arg
                int recover_with_dwim = dwim_new_local_branch_ok;
  
                if (!has_dash_dash &&
 -                  (check_filename(NULL, arg) || !no_wildcard(arg)))
 +                  (check_filename(opts->prefix, arg) || !no_wildcard(arg)))
                        recover_with_dwim = 0;
                /*
                 * Accept "git checkout foo" and "git checkout foo --"
  
        if (!*source_tree)                   /* case (1): want a tree */
                die(_("reference is not a tree: %s"), arg);
 -      if (!has_dash_dash) {/* case (3).(d) -> (1) */
 +      if (!has_dash_dash) {   /* case (3).(d) -> (1) */
                /*
                 * Do not complain the most common case
                 *      git checkout branch
                 * it would be extremely annoying.
                 */
                if (argc)
 -                      verify_non_filename(NULL, arg);
 +                      verify_non_filename(opts->prefix, arg);
        } else {
                argcount++;
                argv++;
diff --combined cache.h
index 1a56f81f3357eb6bed624309b22ae0795bd8c0ac,5d9116c0c4ddc5efb546e51019c304aea887bb22..ed3d5dfce1b9eb2d6273edac45901632304d4be2
+++ b/cache.h
@@@ -367,9 -367,8 +367,9 @@@ extern void free_name_hash(struct index
  #define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))
  #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos))
  #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
 -#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags), 0)
 -#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags), 0)
 +#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))
 +#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))
 +#define chmod_cache_entry(ce, flip) chmod_index_entry(&the_index, (ce), (flip))
  #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
  #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
  #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
@@@ -588,10 -587,9 +588,10 @@@ extern int remove_file_from_index(struc
  #define ADD_CACHE_IGNORE_ERRORS       4
  #define ADD_CACHE_IGNORE_REMOVAL 8
  #define ADD_CACHE_INTENT 16
 -extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags, int force_mode);
 -extern int add_file_to_index(struct index_state *, const char *path, int flags, int force_mode);
 +extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
 +extern int add_file_to_index(struct index_state *, const char *path, int flags);
  extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);
 +extern int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
  extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
  extern void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
  extern int index_name_is_other(const struct index_state *, const char *, int);
@@@ -1356,6 -1354,7 +1356,7 @@@ struct checkout 
                 not_new:1,
                 refresh_cache:1;
  };
+ #define CHECKOUT_INIT { NULL, "" }
  
  #define TEMPORARY_FILENAME_LENGTH 25
  extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
@@@ -1860,7 -1859,7 +1861,7 @@@ void packet_trace_identity(const char *
   * return 0 if success, 1 - if addition of a file failed and
   * ADD_FILES_IGNORE_ERRORS was specified in flags
   */
 -int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags, int force_mode);
 +int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags);
  
  /* diff.c */
  extern int diff_auto_refresh_index;