Merge branch 'jk/squelch-compiler-warning-from-funny-error-macro'
authorJunio C Hamano <gitster@pobox.com>
Fri, 6 Jun 2014 18:21:36 +0000 (11:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Jun 2014 18:21:36 +0000 (11:21 -0700)
* jk/squelch-compiler-warning-from-funny-error-macro:
let clang use the constant-return error() macro
inline constant return from error() function

1  2 
cache.h
git-compat-util.h
parse-options.h
diff --combined cache.h
index 62a4d39efcfa5f0cbf4257acfbbb9f8fdd5d2859,86be95e6d9c85095508b4c396207cca1a50ac413..8c6cdc29deca2eb60d5f76f9b44d6cfa1bd2d8ae
+++ b/cache.h
@@@ -3,7 -3,7 +3,7 @@@
  
  #include "git-compat-util.h"
  #include "strbuf.h"
 -#include "hash.h"
 +#include "hashmap.h"
  #include "advice.h"
  #include "gettext.h"
  #include "convert.h"
@@@ -74,21 -74,6 +74,21 @@@ unsigned long git_deflate_bound(git_zst
  #define S_IFGITLINK   0160000
  #define S_ISGITLINK(m)        (((m) & S_IFMT) == S_IFGITLINK)
  
 +/*
 + * Some mode bits are also used internally for computations.
 + *
 + * They *must* not overlap with any valid modes, and they *must* not be emitted
 + * to outside world - i.e. appear on disk or network. In other words, it's just
 + * temporary fields, which we internally use, but they have to stay in-house.
 + *
 + * ( such approach is valid, as standard S_IF* fits into 16 bits, and in Git
 + *   codebase mode is `unsigned int` which is assumed to be at least 32 bits )
 + */
 +
 +/* used internally in tree-diff */
 +#define S_DIFFTREE_IFXMIN_NEQ 0x80000000
 +
 +
  /*
   * Intensive research over the course of many years has shown that
   * port 9418 is totally unused by anything else. Or
@@@ -145,12 -130,12 +145,12 @@@ struct stat_data 
  };
  
  struct cache_entry {
 +      struct hashmap_entry ent;
        struct stat_data ce_stat_data;
        unsigned int ce_mode;
        unsigned int ce_flags;
        unsigned int ce_namelen;
        unsigned char sha1[20];
 -      struct cache_entry *next;
        char name[FLEX_ARRAY]; /* more */
  };
  
  #define CE_ADDED             (1 << 19)
  
  #define CE_HASHED            (1 << 20)
 -#define CE_UNHASHED          (1 << 21)
  #define CE_WT_REMOVE         (1 << 22) /* remove in work directory */
  #define CE_CONFLICTED        (1 << 23)
  
@@@ -209,18 -195,17 +209,18 @@@ struct pathspec
   * Copy the sha1 and stat state of a cache entry from one to
   * another. But we never change the name, or the hash state!
   */
 -#define CE_STATE_MASK (CE_HASHED | CE_UNHASHED)
  static inline void copy_cache_entry(struct cache_entry *dst,
                                    const struct cache_entry *src)
  {
 -      unsigned int state = dst->ce_flags & CE_STATE_MASK;
 +      unsigned int state = dst->ce_flags & CE_HASHED;
  
        /* Don't copy hash chain and name */
 -      memcpy(dst, src, offsetof(struct cache_entry, next));
 +      memcpy(&dst->ce_stat_data, &src->ce_stat_data,
 +                      offsetof(struct cache_entry, name) -
 +                      offsetof(struct cache_entry, ce_stat_data));
  
        /* Restore the hash state */
 -      dst->ce_flags = (dst->ce_flags & ~CE_STATE_MASK) | state;
 +      dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state;
  }
  
  static inline unsigned create_ce_flags(unsigned stage)
@@@ -292,9 -277,8 +292,9 @@@ struct index_state 
        struct cache_time timestamp;
        unsigned name_hash_initialized : 1,
                 initialized : 1;
 -      struct hash_table name_hash;
 -      struct hash_table dir_hash;
 +      struct hashmap name_hash;
 +      struct hashmap dir_hash;
 +      unsigned char sha1[20];
  };
  
  extern struct index_state the_index;
@@@ -332,6 -316,7 +332,6 @@@ extern void free_name_hash(struct index
  #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
  #define cache_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen))
  #define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))
 -#define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase))
  #define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))
  #define resolve_undo_clear() resolve_undo_clear_index(&the_index)
  #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)
@@@ -449,7 -434,6 +449,7 @@@ extern int set_git_dir_init(const char 
  extern int init_db(const char *template_dir, unsigned int flags);
  
  extern void sanitize_stdfds(void);
 +extern int daemonize(void);
  
  #define alloc_nr(x) (((x)+16)*3/2)
  
@@@ -483,6 -467,7 +483,6 @@@ extern int unmerged_index(const struct 
  extern int verify_path(const char *path);
  extern struct cache_entry *index_dir_exists(struct index_state *istate, const char *name, int namelen);
  extern struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
 -extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int igncase);
  extern int index_name_pos(const struct index_state *, const char *name, int namelen);
  #define ADD_CACHE_OK_TO_ADD 1         /* Ok to add */
  #define ADD_CACHE_OK_TO_REPLACE 2     /* Ok to replace file/directory */
@@@ -499,11 -484,11 +499,11 @@@ extern int remove_file_from_index(struc
  #define ADD_CACHE_IGNORE_ERRORS       4
  #define ADD_CACHE_IGNORE_REMOVAL 8
  #define ADD_CACHE_INTENT 16
 -#define ADD_CACHE_IMPLICIT_DOT 32     /* internal to "git add -u/-A" */
  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 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);
  extern void *read_blob_data_from_index(struct index_state *, const char *, unsigned long *);
  
@@@ -597,17 -582,7 +597,17 @@@ extern size_t packed_git_limit
  extern size_t delta_base_cache_limit;
  extern unsigned long big_file_threshold;
  extern unsigned long pack_size_limit_cfg;
 -extern int read_replace_refs;
 +
 +/*
 + * Do replace refs need to be checked this run?  This variable is
 + * initialized to true unless --no-replace-object is used or
 + * $GIT_NO_REPLACE_OBJECTS is set, but is set to false by some
 + * commands that do not want replace references to be active.  As an
 + * optimization it is also set to false if replace references have
 + * been sought but there were none.
 + */
 +extern int check_replace_refs;
 +
  extern int fsync_object_files;
  extern int core_preload_index;
  extern int core_apply_sparse_checkout;
@@@ -686,28 -661,9 +686,28 @@@ extern char *git_path(const char *fmt, 
  extern char *git_path_submodule(const char *path, const char *fmt, ...)
        __attribute__((format (printf, 2, 3)));
  
 -extern char *sha1_file_name(const unsigned char *sha1);
 +/*
 + * Return the name of the file in the local object database that would
 + * be used to store a loose object with the specified sha1.  The
 + * return value is a pointer to a statically allocated buffer that is
 + * overwritten each time the function is called.
 + */
 +extern const char *sha1_file_name(const unsigned char *sha1);
 +
 +/*
 + * Return the name of the (local) packfile with the specified sha1 in
 + * its name.  The return value is a pointer to memory that is
 + * overwritten each time this function is called.
 + */
  extern char *sha1_pack_name(const unsigned char *sha1);
 +
 +/*
 + * Return the name of the (local) pack index file with the specified
 + * sha1 in its name.  The return value is a pointer to memory that is
 + * overwritten each time this function is called.
 + */
  extern char *sha1_pack_index_name(const unsigned char *sha1);
 +
  extern const char *find_unique_abbrev(const unsigned char *sha1, int);
  extern const unsigned char null_sha1[20];
  
@@@ -834,26 -790,13 +834,26 @@@ static inline void *read_sha1_file(cons
  {
        return read_sha1_file_extended(sha1, type, size, LOOKUP_REPLACE_OBJECT);
  }
 +
 +/*
 + * This internal function is only declared here for the benefit of
 + * lookup_replace_object().  Please do not call it directly.
 + */
  extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
 +
 +/*
 + * If object sha1 should be replaced, return the replacement object's
 + * name (replaced recursively, if necessary).  The return value is
 + * either sha1 or a pointer to a permanently-allocated value.  When
 + * object replacement is suppressed, always return sha1.
 + */
  static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
  {
 -      if (!read_replace_refs)
 +      if (!check_replace_refs)
                return sha1;
        return do_lookup_replace_object(sha1);
  }
 +
  static inline const unsigned char *lookup_replace_object_extended(const unsigned char *sha1, unsigned flag)
  {
        if (!(flag & LOOKUP_REPLACE_OBJECT))
@@@ -867,7 -810,6 +867,7 @@@ extern int hash_sha1_file(const void *b
  extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
  extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
  extern int force_object_loose(const unsigned char *sha1, time_t mtime);
 +extern int git_open_noatime(const char *name);
  extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
  extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
  extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
@@@ -880,19 -822,7 +880,19 @@@ extern int check_sha1_signature(const u
  extern int move_temp_to_file(const char *tmpfile, const char *filename);
  
  extern int has_sha1_pack(const unsigned char *sha1);
 +
 +/*
 + * Return true iff we have an object named sha1, whether local or in
 + * an alternate object database, and whether packed or loose.  This
 + * function does not respect replace references.
 + */
  extern int has_sha1_file(const unsigned char *sha1);
 +
 +/*
 + * Return true iff an alternate object database has a loose object
 + * with the specified name.  This function does not respect replace
 + * references.
 + */
  extern int has_loose_object_nonlocal(const unsigned char *sha1);
  
  extern int has_pack_index(const unsigned char *sha1);
@@@ -1061,13 -991,6 +1061,13 @@@ struct ident_split 
   */
  extern int split_ident_line(struct ident_split *, const char *, int);
  
 +/*
 + * Like show_date, but pull the timestamp and tz parameters from
 + * the ident_split. It will also sanity-check the values and produce
 + * a well-known sentinel date if they appear bogus.
 + */
 +const char *show_ident_date(const struct ident_split *id, enum date_mode mode);
 +
  /*
   * Compare split idents for equality or strict ordering. Note that we
   * compare only the ident part of the line, ignoring any timestamp.
@@@ -1163,46 -1086,17 +1163,46 @@@ extern struct packed_git *find_sha1_pac
                                         struct packed_git *packs);
  
  extern void pack_report(void);
 +
 +/*
 + * mmap the index file for the specified packfile (if it is not
 + * already mmapped).  Return 0 on success.
 + */
  extern int open_pack_index(struct packed_git *);
 +
 +/*
 + * munmap the index file for the specified packfile (if it is
 + * currently mmapped).
 + */
  extern void close_pack_index(struct packed_git *);
 +
  extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
  extern void close_pack_windows(struct packed_git *);
  extern void unuse_pack(struct pack_window **);
  extern void free_pack_by_name(const char *);
  extern void clear_delta_base_cache(void);
  extern struct packed_git *add_packed_git(const char *, int, int);
 -extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t);
 -extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t);
 -extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *);
 +
 +/*
 + * Return the SHA-1 of the nth object within the specified packfile.
 + * Open the index if it is not already open.  The return value points
 + * at the SHA-1 within the mmapped index.  Return NULL if there is an
 + * error.
 + */
 +extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);
 +
 +/*
 + * Return the offset of the nth object within the specified packfile.
 + * The index must already be opened.
 + */
 +extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t n);
 +
 +/*
 + * If the object named sha1 is present in the specified packfile,
 + * return its offset within the packfile; otherwise, return 0.
 + */
 +extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *);
 +
  extern int is_pack_valid(struct packed_git *);
  extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
  extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
@@@ -1255,12 -1149,6 +1255,12 @@@ extern int update_server_info(int)
  #define CONFIG_INVALID_PATTERN 6
  #define CONFIG_GENERIC_ERROR 7
  
 +struct git_config_source {
 +      unsigned int use_stdin:1;
 +      const char *file;
 +      const char *blob;
 +};
 +
  typedef int (*config_fn_t)(const char *, const char *, void *);
  extern int git_default_config(const char *, const char *, void *);
  extern int git_config_from_file(config_fn_t fn, const char *, void *);
@@@ -1270,7 -1158,8 +1270,7 @@@ extern void git_config_push_parameter(c
  extern int git_config_from_parameters(config_fn_t fn, void *data);
  extern int git_config(config_fn_t fn, void *);
  extern int git_config_with_options(config_fn_t fn, void *,
 -                                 const char *filename,
 -                                 const char *blob_ref,
 +                                 struct git_config_source *config_source,
                                   int respect_includes);
  extern int git_config_early(config_fn_t fn, void *, const char *repo_config);
  extern int git_parse_ulong(const char *, unsigned long *);
@@@ -1294,8 -1183,8 +1294,8 @@@ extern int check_repository_format_vers
  extern int git_env_bool(const char *, int);
  extern int git_config_system(void);
  extern int config_error_nonbool(const char *);
- #if defined(__GNUC__) && ! defined(__clang__)
- #define config_error_nonbool(s) (config_error_nonbool(s), -1)
+ #if defined(__GNUC__)
+ #define config_error_nonbool(s) (config_error_nonbool(s), const_error())
  #endif
  extern const char *get_log_output_encoding(void);
  extern const char *get_commit_output_encoding(void);
@@@ -1345,8 -1234,6 +1345,8 @@@ extern void fsync_or_die(int fd, const 
  
  extern ssize_t read_in_full(int fd, void *buf, size_t count);
  extern ssize_t write_in_full(int fd, const void *buf, size_t count);
 +extern ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
 +
  static inline ssize_t write_str_in_full(int fd, const char *str)
  {
        return write_in_full(fd, str, strlen(str));
@@@ -1483,6 -1370,4 +1483,6 @@@ int stat_validity_check(struct stat_val
   */
  void stat_validity_update(struct stat_validity *sv, int fd);
  
 +int versioncmp(const char *s1, const char *s2);
 +
  #endif /* CACHE_H */
diff --combined git-compat-util.h
index 76910e6cd16f128be9430ac86f35a8e06d390e0f,38ff8030700466004ac7657777c028ce161ab973..7849d314051a1de351c9c985516135397042a091
  #include <sys/time.h>
  #include <time.h>
  #include <signal.h>
 -#ifndef USE_WILDMATCH
 -#include <fnmatch.h>
 -#endif
  #include <assert.h>
  #include <regex.h>
  #include <utime.h>
@@@ -301,7 -304,16 +301,7 @@@ extern char *gitbasename(char *)
  
  #include "compat/bswap.h"
  
 -#ifdef USE_WILDMATCH
  #include "wildmatch.h"
 -#define FNM_PATHNAME WM_PATHNAME
 -#define FNM_CASEFOLD WM_CASEFOLD
 -#define FNM_NOMATCH  WM_NOMATCH
 -static inline int fnmatch(const char *pattern, const char *string, int flags)
 -{
 -      return wildmatch(pattern, string, flags, NULL);
 -}
 -#endif
  
  /* General helper functions */
  extern void vreportf(const char *prefix, const char *err, va_list params);
@@@ -330,8 -342,12 +330,12 @@@ extern void warning(const char *err, ..
   * trying to help gcc, anyway, it's OK; other compilers will fall back to
   * using the function as usual.
   */
- #if defined(__GNUC__) && ! defined(__clang__)
- #define error(...) (error(__VA_ARGS__), -1)
+ #if defined(__GNUC__)
+ static inline int const_error(void)
+ {
+       return -1;
+ }
+ #define error(...) (error(__VA_ARGS__), const_error())
  #endif
  
  extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
@@@ -339,15 -355,14 +343,15 @@@ extern void set_error_routine(void (*ro
  extern void set_die_is_recursing_routine(int (*routine)(void));
  
  extern int starts_with(const char *str, const char *prefix);
 -extern int prefixcmp(const char *str, const char *prefix);
  extern int ends_with(const char *str, const char *suffix);
 -extern int suffixcmp(const char *str, const char *suffix);
  
  static inline const char *skip_prefix(const char *str, const char *prefix)
  {
 -      size_t len = strlen(prefix);
 -      return strncmp(str, prefix, len) ? NULL : str + len;
 +      do {
 +              if (!*prefix)
 +                      return str;
 +      } while (*str++ == *prefix++);
 +      return NULL;
  }
  
  #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
@@@ -469,15 -484,9 +473,15 @@@ extern FILE *git_fopen(const char*, con
  #endif
  
  #ifdef SNPRINTF_RETURNS_BOGUS
 +#ifdef snprintf
 +#undef snprintf
 +#endif
  #define snprintf git_snprintf
  extern int git_snprintf(char *str, size_t maxsize,
                        const char *format, ...);
 +#ifdef vsnprintf
 +#undef vsnprintf
 +#endif
  #define vsnprintf git_vsnprintf
  extern int git_vsnprintf(char *str, size_t maxsize,
                         const char *format, va_list ap);
@@@ -521,14 -530,6 +525,14 @@@ extern void release_pack_memory(size_t)
  typedef void (*try_to_free_t)(size_t);
  extern try_to_free_t set_try_to_free_routine(try_to_free_t);
  
 +#ifdef HAVE_ALLOCA_H
 +# include <alloca.h>
 +# define xalloca(size)      (alloca(size))
 +# define xalloca_free(p)    do {} while (0)
 +#else
 +# define xalloca(size)      (xmalloc(size))
 +# define xalloca_free(p)    (free(p))
 +#endif
  extern char *xstrdup(const char *str);
  extern void *xmalloc(size_t size);
  extern void *xmallocz(size_t size);
@@@ -539,13 -540,12 +543,13 @@@ extern void *xcalloc(size_t nmemb, size
  extern void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
  extern ssize_t xread(int fd, void *buf, size_t len);
  extern ssize_t xwrite(int fd, const void *buf, size_t len);
 +extern ssize_t xpread(int fd, void *buf, size_t len, off_t offset);
  extern int xdup(int fd);
  extern FILE *xfdopen(int fd, const char *mode);
  extern int xmkstemp(char *template);
  extern int xmkstemp_mode(char *template, int mode);
  extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
 -extern int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1);
 +extern int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1);
  
  static inline size_t xsize_t(off_t len)
  {
diff --combined parse-options.h
index 3189676695bc173cf6475445cfb6365d08a37906,0a2b2e19a5019ba52552ae4c4c8fc35eb374bae0..7940bc71af4c6dacd65d042091454c8fa83c53c7
@@@ -12,6 -12,7 +12,6 @@@ enum parse_opt_type 
        OPTION_NEGBIT,
        OPTION_COUNTUP,
        OPTION_SET_INT,
 -      OPTION_SET_PTR,
        OPTION_CMDMODE,
        /* options with arguments (usually) */
        OPTION_STRING,
@@@ -95,7 -96,7 +95,7 @@@ typedef int parse_opt_ll_cb(struct pars
   *
   * `defval`::
   *   default value to fill (*->value) with for PARSE_OPT_OPTARG.
 - *   OPTION_{BIT,SET_INT,SET_PTR} store the {mask,integer,pointer} to put in
 + *   OPTION_{BIT,SET_INT} store the {mask,integer,pointer} to put in
   *   the value when met.
   *   CALLBACKS can use it like they want.
   */
@@@ -127,6 -128,8 +127,6 @@@ struct option 
  #define OPT_BOOL(s, l, v, h)        OPT_SET_INT(s, l, v, h, 1)
  #define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \
                                      (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
 -#define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, \
 -                                    (h), PARSE_OPT_NOARG, NULL, (p) }
  #define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
                                      (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }
  #define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
        { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0,    \
          parse_opt_approxidate_cb }
  #define OPT_EXPIRY_DATE(s, l, v, h) \
 -      { OPTION_CALLBACK, (s), (l), (v), N_("expiry date"),(h), 0,     \
 +      { OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0,     \
          parse_opt_expiry_date_cb }
  #define OPT_CALLBACK(s, l, v, a, h, f) \
        { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
@@@ -176,8 -179,8 +176,8 @@@ extern NORETURN void usage_msg_opt(cons
  
  extern int optbug(const struct option *opt, const char *reason);
  extern int opterror(const struct option *opt, const char *reason, int flags);
- #if defined(__GNUC__) && ! defined(__clang__)
- #define opterror(o,r,f) (opterror((o),(r),(f)), -1)
+ #if defined(__GNUC__)
+ #define opterror(o,r,f) (opterror((o),(r),(f)), const_error())
  #endif
  
  /*----- incremental advanced APIs -----*/