Merge branch 'jk/bug-to-abort'
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 May 2017 03:34:45 +0000 (12:34 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 May 2017 03:34:45 +0000 (12:34 +0900)
Introduce the BUG() macro to improve die("BUG: ...").

* jk/bug-to-abort:
usage: add NORETURN to BUG() function definitions
config: complain about --local outside of a git repo
setup_git_env: convert die("BUG") to BUG()
usage.c: add BUG() function

1  2 
environment.c
git-compat-util.h
diff --combined environment.c
index 560408953c8f76a30a093a59505e52c828d8d20b,1f0bda5afabe901bea250e7dabcc39c5325baf88..aa478e71de9d9c233593de050d6823e96be77b88
@@@ -169,7 -169,7 +169,7 @@@ static void setup_git_env(void
        git_dir = getenv(GIT_DIR_ENVIRONMENT);
        if (!git_dir) {
                if (!startup_info->have_repository)
-                       die("BUG: setup_git_env called without repository");
+                       BUG("setup_git_env called without repository");
                git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
        }
        gitfile = read_gitfile(git_dir);
@@@ -217,8 -217,6 +217,8 @@@ const char *get_git_dir(void
  
  const char *get_git_common_dir(void)
  {
 +      if (!git_dir)
 +              setup_git_env();
        return git_common_dir;
  }
  
diff --combined git-compat-util.h
index ab7552a7ce2e292df2875258fef6f8bd0438e115,4575b3890b22599d147211576d2f1ea6e7c6833e..98670a3c9af15cdc662ed1535a6b322e2a7b8a38
@@@ -319,11 -319,6 +319,11 @@@ extern char *gitdirname(char *)
  #define PRIo32 "o"
  #endif
  
 +typedef uintmax_t timestamp_t;
 +#define PRItime PRIuMAX
 +#define parse_timestamp strtoumax
 +#define TIME_MAX UINTMAX_MAX
 +
  #ifndef PATH_SEP
  #define PATH_SEP ':'
  #endif
@@@ -621,7 -616,7 +621,7 @@@ extern int git_lstat(const char *, stru
  #endif
  
  #define DEFAULT_PACKED_GIT_LIMIT \
 -      ((1024L * 1024L) * (size_t)(sizeof(void*) >= 8 ? 8192 : 256))
 +      ((1024L * 1024L) * (size_t)(sizeof(void*) >= 8 ? (32 * 1024L * 1024L) : 256))
  
  #ifdef NO_PREAD
  #define pread git_pread
@@@ -1069,6 -1064,15 +1069,15 @@@ static inline int regexec_buf(const reg
  #define HAVE_VARIADIC_MACROS 1
  #endif
  
+ #ifdef HAVE_VARIADIC_MACROS
+ __attribute__((format (printf, 3, 4))) NORETURN
+ void BUG_fl(const char *file, int line, const char *fmt, ...);
+ #define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)
+ #else
+ __attribute__((format (printf, 1, 2))) NORETURN
+ void BUG(const char *fmt, ...);
+ #endif
  /*
   * Preserves errno, prints a message, but gives no warning for ENOENT.
   * Returns 0 on success, which includes trying to unlink an object that does