Merge branch 'jk/clang-pedantic' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 5 Feb 2016 22:54:09 +0000 (14:54 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Feb 2016 22:54:09 +0000 (14:54 -0800)
A few unportable C construct have been spotted by clang compiler
and have been fixed.

* jk/clang-pedantic:
bswap: add NO_UNALIGNED_LOADS define
avoid shifting signed integers 31 bits

1  2 
builtin/receive-pack.c
cache.h
diff --combined builtin/receive-pack.c
index ca38131873aad1c5dd5b8001aceb39ed906b3c2d,e35ed404371052a9ba0ecfdd1c02e03fb20d2039..2b3b746fb40d7a3da9cefd4688b6f60efde10c24
@@@ -195,6 -195,9 +195,6 @@@ static int receive_pack_config(const ch
  
  static void show_ref(const char *path, const unsigned char *sha1)
  {
 -      if (ref_is_hidden(path))
 -              return;
 -
        if (sent_capabilities) {
                packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
        } else {
        }
  }
  
 -static int show_ref_cb(const char *path, const struct object_id *oid, int flag, void *unused)
 +static int show_ref_cb(const char *path_full, const struct object_id *oid,
 +                     int flag, void *unused)
  {
 -      path = strip_namespace(path);
 +      const char *path = strip_namespace(path_full);
 +
 +      if (ref_is_hidden(path, path_full))
 +              return 0;
 +
        /*
         * Advertise refs outside our current namespace as ".have"
         * refs, so that the client can use them to minimize data
@@@ -246,7 -244,7 +246,7 @@@ static void show_one_alternate_sha1(con
  static void collect_one_alternate_ref(const struct ref *ref, void *data)
  {
        struct sha1_array *sa = data;
 -      sha1_array_append(sa, ref->old_sha1);
 +      sha1_array_append(sa, ref->old_oid.hash);
  }
  
  static void write_head_info(void)
@@@ -282,10 -280,10 +282,10 @@@ static void rp_warning(const char *err
  
  static void report_message(const char *prefix, const char *err, va_list params)
  {
 -      int sz = strlen(prefix);
 +      int sz;
        char msg[4096];
  
 -      strncpy(msg, prefix, sz);
 +      sz = xsnprintf(msg, sizeof(msg), "%s", prefix);
        sz += vsnprintf(msg + sz, sizeof(msg) - sz, err, params);
        if (sz > (sizeof(msg) - 1))
                sz = sizeof(msg) - 1;
@@@ -1073,11 -1071,8 +1073,11 @@@ static void check_aliased_update(struc
        const char *dst_name;
        struct string_list_item *item;
        struct command *dst_cmd;
 -      unsigned char sha1[20];
 -      char cmd_oldh[41], cmd_newh[41], dst_oldh[41], dst_newh[41];
 +      unsigned char sha1[GIT_SHA1_RAWSZ];
 +      char cmd_oldh[GIT_SHA1_HEXSZ + 1],
 +           cmd_newh[GIT_SHA1_HEXSZ + 1],
 +           dst_oldh[GIT_SHA1_HEXSZ + 1],
 +           dst_newh[GIT_SHA1_HEXSZ + 1];
        int flag;
  
        strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
  
        dst_cmd->skip_update = 1;
  
 -      strcpy(cmd_oldh, find_unique_abbrev(cmd->old_sha1, DEFAULT_ABBREV));
 -      strcpy(cmd_newh, find_unique_abbrev(cmd->new_sha1, DEFAULT_ABBREV));
 -      strcpy(dst_oldh, find_unique_abbrev(dst_cmd->old_sha1, DEFAULT_ABBREV));
 -      strcpy(dst_newh, find_unique_abbrev(dst_cmd->new_sha1, DEFAULT_ABBREV));
 +      find_unique_abbrev_r(cmd_oldh, cmd->old_sha1, DEFAULT_ABBREV);
 +      find_unique_abbrev_r(cmd_newh, cmd->new_sha1, DEFAULT_ABBREV);
 +      find_unique_abbrev_r(dst_oldh, dst_cmd->old_sha1, DEFAULT_ABBREV);
 +      find_unique_abbrev_r(dst_newh, dst_cmd->new_sha1, DEFAULT_ABBREV);
        rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
                 " its target '%s' (%s..%s)",
                 cmd->ref_name, cmd_oldh, cmd_newh,
@@@ -1197,29 -1192,16 +1197,29 @@@ static int iterate_receive_command_list
  
  static void reject_updates_to_hidden(struct command *commands)
  {
 +      struct strbuf refname_full = STRBUF_INIT;
 +      size_t prefix_len;
        struct command *cmd;
  
 +      strbuf_addstr(&refname_full, get_git_namespace());
 +      prefix_len = refname_full.len;
 +
        for (cmd = commands; cmd; cmd = cmd->next) {
 -              if (cmd->error_string || !ref_is_hidden(cmd->ref_name))
 +              if (cmd->error_string)
 +                      continue;
 +
 +              strbuf_setlen(&refname_full, prefix_len);
 +              strbuf_addstr(&refname_full, cmd->ref_name);
 +
 +              if (!ref_is_hidden(cmd->ref_name, refname_full.buf))
                        continue;
                if (is_null_sha1(cmd->new_sha1))
                        cmd->error_string = "deny deleting a hidden ref";
                else
                        cmd->error_string = "deny updating a hidden ref";
        }
 +
 +      strbuf_release(&refname_full);
  }
  
  static int should_process_cmd(struct command *cmd)
@@@ -1539,18 -1521,15 +1539,18 @@@ static const char *unpack(int err_fd, s
                if (status)
                        return "unpack-objects abnormal exit";
        } else {
 -              int s;
 -              char keep_arg[256];
 -
 -              s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid());
 -              if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
 -                      strcpy(keep_arg + s, "localhost");
 +              char hostname[256];
  
                argv_array_pushl(&child.args, "index-pack",
 -                               "--stdin", hdr_arg, keep_arg, NULL);
 +                               "--stdin", hdr_arg, NULL);
 +
 +              if (gethostname(hostname, sizeof(hostname)))
 +                      xsnprintf(hostname, sizeof(hostname), "localhost");
 +              argv_array_pushf(&child.args,
 +                               "--keep=receive-pack %"PRIuMAX" on %s",
 +                               (uintmax_t)getpid(),
 +                               hostname);
 +
                if (fsck_objects)
                        argv_array_pushf(&child.args, "--strict%s",
                                fsck_msg_types.buf);
@@@ -1618,7 -1597,7 +1618,7 @@@ static void prepare_shallow_update(stru
                                continue;
                        si->need_reachability_test[i]++;
                        for (k = 0; k < 32; k++)
-                               if (si->used_shallow[i][j] & (1 << k))
+                               if (si->used_shallow[i][j] & (1U << k))
                                        si->shallow_ref[j * 32 + k]++;
                }
  
diff --combined cache.h
index c63fcc113a6e511a53f0170a07bd5dbbf12cc120,908884318cadd239b8b7acb153727e366e69348c..ee0adc89927aafa3d666aa5c18bf72503157ba1e
+++ b/cache.h
@@@ -214,7 -214,7 +214,7 @@@ struct cache_entry 
  #define CE_INTENT_TO_ADD     (1 << 29)
  #define CE_SKIP_WORKTREE     (1 << 30)
  /* CE_EXTENDED2 is for future extension */
- #define CE_EXTENDED2         (1 << 31)
+ #define CE_EXTENDED2         (1U << 31)
  
  #define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
  
@@@ -750,8 -750,6 +750,8 @@@ extern char *mksnpath(char *buf, size_
        __attribute__((format (printf, 3, 4)));
  extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
        __attribute__((format (printf, 2, 3)));
 +extern char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
 +      __attribute__((format (printf, 2, 3)));
  extern void strbuf_git_path_submodule(struct strbuf *sb, const char *path,
                                      const char *fmt, ...)
        __attribute__((format (printf, 3, 4)));
@@@ -812,26 -810,8 +812,26 @@@ extern char *sha1_pack_name(const unsig
   */
  extern char *sha1_pack_index_name(const unsigned char *sha1);
  
 -extern const char *find_unique_abbrev(const unsigned char *sha1, int);
 +/*
 + * Return an abbreviated sha1 unique within this repository's object database.
 + * The result will be at least `len` characters long, and will be NUL
 + * terminated.
 + *
 + * The non-`_r` version returns a static buffer which will be overwritten by
 + * subsequent calls.
 + *
 + * The `_r` variant writes to a buffer supplied by the caller, which must be at
 + * least `GIT_SHA1_HEXSZ + 1` bytes. The return value is the number of bytes
 + * written (excluding the NUL terminator).
 + *
 + * Note that while this version avoids the static buffer, it is not fully
 + * reentrant, as it calls into other non-reentrant git code.
 + */
 +extern const char *find_unique_abbrev(const unsigned char *sha1, int len);
 +extern int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len);
 +
  extern const unsigned char null_sha1[GIT_SHA1_RAWSZ];
 +extern const struct object_id null_oid;
  
  static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
  {
@@@ -1049,9 -1029,6 +1049,9 @@@ static inline int has_sha1_file(const u
        return has_sha1_file_with_flags(sha1, 0);
  }
  
 +/* Same as the above, except for struct object_id. */
 +extern int has_object_file(const struct object_id *oid);
 +
  /*
   * Return true iff an alternate object database has a loose object
   * with the specified name.  This function does not respect replace
@@@ -1115,18 -1092,6 +1115,18 @@@ extern int for_each_abbrev(const char *
  extern int get_sha1_hex(const char *hex, unsigned char *sha1);
  extern int get_oid_hex(const char *hex, struct object_id *sha1);
  
 +/*
 + * Convert a binary sha1 to its hex equivalent. The `_r` variant is reentrant,
 + * and writes the NUL-terminated output to the buffer `out`, which must be at
 + * least `GIT_SHA1_HEXSZ + 1` bytes, and returns a pointer to out for
 + * convenience.
 + *
 + * The non-`_r` variant returns a static buffer, but uses a ring of 4
 + * buffers, making it safe to make multiple calls for a single statement, like:
 + *
 + *   printf("%s -> %s", sha1_to_hex(one), sha1_to_hex(two));
 + */
 +extern char *sha1_to_hex_r(char *out, const unsigned char *sha1);
  extern char *sha1_to_hex(const unsigned char *sha1);  /* static buffer result! */
  extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
  
@@@ -1153,6 -1118,7 +1153,6 @@@ struct date_mode 
                DATE_NORMAL = 0,
                DATE_RELATIVE,
                DATE_SHORT,
 -              DATE_LOCAL,
                DATE_ISO8601,
                DATE_ISO8601_STRICT,
                DATE_RFC2822,
                DATE_RAW
        } type;
        const char *strftime_fmt;
 +      int local;
  };
  
  /*
@@@ -1344,7 -1309,7 +1344,7 @@@ extern void close_all_packs(void)
  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 struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
  
  /*
   * Return the SHA-1 of the nth object within the specified packfile.
@@@ -1772,12 -1737,4 +1772,12 @@@ void stat_validity_update(struct stat_v
  int versioncmp(const char *s1, const char *s2);
  void sleep_millisec(int millisec);
  
 +/*
 + * Create a directory and (if share is nonzero) adjust its permissions
 + * according to the shared_repository setting. Only use this for
 + * directories under $GIT_DIR.  Don't use it for working tree
 + * directories.
 + */
 +void safe_create_dir(const char *dir, int share);
 +
  #endif /* CACHE_H */