Merge branch 'jk/error-const-return'
authorJunio C Hamano <gitster@pobox.com>
Sun, 6 Jan 2013 07:42:00 +0000 (23:42 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 6 Jan 2013 07:42:00 +0000 (23:42 -0800)
Help compilers' flow analysis by making it more explicit that
error() always returns -1, to reduce false "variable used
uninitialized" warnings. Looks somewhat ugly but not too much.

* jk/error-const-return:
silence some -Wuninitialized false positives
make error()'s constant return value more visible

1  2 
cache.h
config.c
git-compat-util.h
diff --combined cache.h
index 8ceb6b8e8d4a51bcbe3bc165bf7dd745788ee095,0e8e5d8002724451e1229bd61460486ac1d04cbd..e1df1e40dd64e990581c4554e8440bed44006e5d
+++ b/cache.h
@@@ -473,8 -473,6 +473,8 @@@ extern int index_name_is_other(const st
  extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
  extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
  
 +#define PATHSPEC_ONESTAR 1    /* the pathspec pattern sastisfies GFNM_ONESTAR */
 +
  struct pathspec {
        const char **raw; /* get_pathspec() result, not freed by free_pathspec() */
        int nr;
        struct pathspec_item {
                const char *match;
                int len;
 -              unsigned int use_wildcard:1;
 +              int nowildcard_len;
 +              int flags;
        } *items;
  };
  
@@@ -717,11 -714,10 +717,11 @@@ static inline int is_absolute_path(cons
  }
  int is_directory(const char *);
  const char *real_path(const char *path);
 +const char *real_path_if_valid(const char *path);
  const char *absolute_path(const char *path);
  const char *relative_path(const char *abs, const char *base);
  int normalize_path_copy(char *dst, const char *src);
 -int longest_ancestor_length(const char *path, const char *prefix_list);
 +int longest_ancestor_length(const char *path, struct string_list *prefixes);
  char *strip_path_suffix(const char *path, const char *suffix);
  int daemon_avoid_alias(const char *path);
  int offset_1st_component(const char *path);
@@@ -1003,19 -999,14 +1003,19 @@@ struct ref 
        unsigned char old_sha1[20];
        unsigned char new_sha1[20];
        char *symref;
 -      unsigned int force:1,
 +      unsigned int
 +              force:1,
 +              requires_force:1,
                merge:1,
                nonfastforward:1,
 +              not_forwardable:1,
 +              update:1,
                deletion:1;
        enum {
                REF_STATUS_NONE = 0,
                REF_STATUS_OK,
                REF_STATUS_REJECT_NONFASTFORWARD,
 +              REF_STATUS_REJECT_ALREADY_EXISTS,
                REF_STATUS_REJECT_NODELETE,
                REF_STATUS_UPTODATE,
                REF_STATUS_REMOTE_REJECT,
@@@ -1145,6 -1136,9 +1145,9 @@@ 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 *);
+ #ifdef __GNUC__
+ #define config_error_nonbool(s) (config_error_nonbool(s), -1)
+ #endif
  extern const char *get_log_output_encoding(void);
  extern const char *get_commit_output_encoding(void);
  
@@@ -1164,7 -1158,6 +1167,7 @@@ extern int author_ident_sufficiently_gi
  extern const char *git_commit_encoding;
  extern const char *git_log_output_encoding;
  extern const char *git_mailmap_file;
 +extern const char *git_mailmap_blob;
  
  /* IO helper functions */
  extern void maybe_flush_or_die(FILE *, const char *);
diff --combined config.c
index 97364c03fc1ee0e0200b5977e7eea48f384cdaf7,526f6823740bc266a15ea7488b4c834a36f58029..053970f369588b42b600ae32557af0828c7d283c
+++ b/config.c
@@@ -839,8 -839,6 +839,8 @@@ static int git_default_mailmap_config(c
  {
        if (!strcmp(var, "mailmap.file"))
                return git_config_string(&git_mailmap_file, var, value);
 +      if (!strcmp(var, "mailmap.blob"))
 +              return git_config_string(&git_mailmap_blob, var, value);
  
        /* Add other config variables here and to Documentation/config.txt. */
        return 0;
@@@ -1662,6 -1660,7 +1662,7 @@@ int git_config_rename_section(const cha
   * Call this to report error for your variable that should not
   * get a boolean value (i.e. "[my] var" means "true").
   */
+ #undef config_error_nonbool
  int config_error_nonbool(const char *var)
  {
        return error("Missing value for '%s'", var);
diff --combined git-compat-util.h
index 610e6b7ea49384b032cf9bd642cf4927955e9588,9002bca28e1a91d88a95b66e0a9a924880bb62a0..9661bc9f7371fec67627151a04e2a7a5094065fc
@@@ -75,7 -75,7 +75,7 @@@
  # endif
  #elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && \
        !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) && \
 -      !defined(__TANDEM)
 +      !defined(__TANDEM) && !defined(__QNX__)
  #define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */
  #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
  #endif
  #include <stdlib.h>
  #include <stdarg.h>
  #include <string.h>
 -#ifdef __TANDEM /* or HAVE_STRINGS_H or !NO_STRINGS_H? */
 +#ifdef HAVE_STRINGS_H
  #include <strings.h> /* for strcasecmp() */
  #endif
  #include <errno.h>
  #include <limits.h>
 +#ifdef NEEDS_SYS_PARAM_H
  #include <sys/param.h>
 +#endif
  #include <sys/types.h>
  #include <dirent.h>
  #include <sys/time.h>
@@@ -290,6 -288,17 +290,17 @@@ extern NORETURN void die_errno(const ch
  extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
  extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
  
+ /*
+  * Let callers be aware of the constant return value; this can help
+  * gcc with -Wuninitialized analysis. We have to restrict this trick to
+  * gcc, though, because of the variadic macro and the magic ## comma pasting
+  * behavior. But since we're only trying to help gcc, anyway, it's OK; other
+  * compilers will fall back to using the function as usual.
+  */
+ #ifdef __GNUC__
+ #define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
+ #endif
  extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
  extern void set_error_routine(void (*routine)(const char *err, va_list params));
  
@@@ -413,10 -422,6 +424,10 @@@ void *gitmemmem(const void *haystack, s
                  const void *needle, size_t needlelen);
  #endif
  
 +#ifdef NO_GETPAGESIZE
 +#define getpagesize() sysconf(_SC_PAGESIZE)
 +#endif
 +
  #ifdef FREAD_READS_DIRECTORIES
  #ifdef fopen
  #undef fopen