Sync with 2.3.9
authorJunio C Hamano <gitster@pobox.com>
Fri, 4 Sep 2015 17:34:19 +0000 (10:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 4 Sep 2015 17:34:19 +0000 (10:34 -0700)
1  2 
Documentation/git.txt
builtin/show-branch.c
sha1_file.c

diff --combined Documentation/git.txt
@@@ -43,22 -43,10 +43,23 @@@ unreleased) version of Git, that is ava
  branch of the `git.git` repository.
  Documentation for older releases are available here:
  
- * link:v2.3.8/git.html[documentation for release 2.3.8]
 +* link:v2.4.8/git.html[documentation for release 2.4.8]
 +
 +* release notes for
 +  link:RelNotes/2.4.8.txt[2.4.8],
 +  link:RelNotes/2.4.7.txt[2.4.7],
 +  link:RelNotes/2.4.6.txt[2.4.6],
 +  link:RelNotes/2.4.5.txt[2.4.5],
 +  link:RelNotes/2.4.4.txt[2.4.4],
 +  link:RelNotes/2.4.3.txt[2.4.3],
 +  link:RelNotes/2.4.2.txt[2.4.2],
 +  link:RelNotes/2.4.1.txt[2.4.1],
 +  link:RelNotes/2.4.0.txt[2.4].
 +
+ * link:v2.3.9/git.html[documentation for release 2.3.9]
  
  * release notes for
+   link:RelNotes/2.3.9.txt[2.3.9],
    link:RelNotes/2.3.8.txt[2.3.8],
    link:RelNotes/2.3.7.txt[2.3.7],
    link:RelNotes/2.3.6.txt[2.3.6],
    link:RelNotes/2.3.1.txt[2.3.1],
    link:RelNotes/2.3.0.txt[2.3].
  
- * link:v2.2.2/git.html[documentation for release 2.2.2]
+ * link:v2.2.3/git.html[documentation for release 2.2.3]
  
  * release notes for
+   link:RelNotes/2.2.3.txt[2.2.3],
    link:RelNotes/2.2.2.txt[2.2.2],
    link:RelNotes/2.2.1.txt[2.2.1],
    link:RelNotes/2.2.0.txt[2.2].
@@@ -938,7 -927,7 +940,7 @@@ for further details
        If this environment variable is set, then Git commands which need to
        acquire passwords or passphrases (e.g. for HTTP or IMAP authentication)
        will call this program with a suitable prompt as command-line argument
 -      and read the password from its STDOUT. See also the 'core.askpass'
 +      and read the password from its STDOUT. See also the 'core.askPass'
        option in linkgit:git-config[1].
  
  'GIT_TERMINAL_PROMPT'::
diff --combined builtin/show-branch.c
@@@ -6,11 -6,11 +6,11 @@@
  #include "parse-options.h"
  
  static const char* show_branch_usage[] = {
 -    N_("git show-branch [-a|--all] [-r|--remotes] [--topo-order | --date-order]\n"
 +    N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
         "              [--current] [--color[=<when>] | --no-color] [--sparse]\n"
         "              [--more=<n> | --list | --independent | --merge-base]\n"
         "              [--no-name | --sha1-name] [--topics] [(<rev> | <glob>)...]"),
 -    N_("git show-branch (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]"),
 +    N_("git show-branch (-g | --reflog)[=<n>[,<base>]] [--list] [<ref>]"),
      NULL
  };
  
@@@ -723,7 -723,6 +723,6 @@@ int cmd_show_branch(int ac, const char 
  
        if (reflog) {
                unsigned char sha1[20];
-               char nth_desc[256];
                char *ref;
                int base = 0;
                unsigned int flags = 0;
  
                for (i = 0; i < reflog; i++) {
                        char *logmsg;
+                       char *nth_desc;
                        const char *msg;
                        unsigned long timestamp;
                        int tz;
                                                show_date(timestamp, tz, 1),
                                                msg);
                        free(logmsg);
-                       sprintf(nth_desc, "%s@{%d}", *av, base+i);
+                       nth_desc = xstrfmt("%s@{%d}", *av, base+i);
                        append_ref(nth_desc, sha1, 1);
+                       free(nth_desc);
                }
                free(ref);
        }
diff --combined sha1_file.c
@@@ -377,15 -377,12 +377,12 @@@ void read_info_alternates(const char * 
        char *map;
        size_t mapsz;
        struct stat st;
-       const char alt_file_name[] = "info/alternates";
-       /* Given that relative_base is no longer than PATH_MAX,
-          ensure that "path" has enough space to append "/", the
-          file name, "info/alternates", and a trailing NUL.  */
-       char path[PATH_MAX + 1 + sizeof alt_file_name];
+       char *path;
        int fd;
  
-       sprintf(path, "%s/%s", relative_base, alt_file_name);
+       path = xstrfmt("%s/info/alternates", relative_base);
        fd = git_open_noatime(path);
+       free(path);
        if (fd < 0)
                return;
        if (fstat(fd, &st) || (st.st_size == 0)) {
@@@ -443,7 -440,6 +440,7 @@@ void prepare_alt_odb(void
        read_info_alternates(get_object_directory(), 0);
  }
  
 +/* Returns 1 if we have successfully freshened the file, 0 otherwise. */
  static int freshen_file(const char *fn)
  {
        struct utimbuf t;
        return !utime(fn, &t);
  }
  
 +/*
 + * All of the check_and_freshen functions return 1 if the file exists and was
 + * freshened (if freshening was requested), 0 otherwise. If they return
 + * 0, you should not assume that it is safe to skip a write of the object (it
 + * either does not exist on disk, or has a stale mtime and may be subject to
 + * pruning).
 + */
  static int check_and_freshen_file(const char *fn, int freshen)
  {
        if (access(fn, F_OK))
                return 0;
 -      if (freshen && freshen_file(fn))
 +      if (freshen && !freshen_file(fn))
                return 0;
        return 1;
  }
@@@ -715,8 -704,8 +712,8 @@@ static void mmap_limit_check(size_t len
                    (uintmax_t)length, (uintmax_t)limit);
  }
  
 -void *xmmap(void *start, size_t length,
 -      int prot, int flags, int fd, off_t offset)
 +void *xmmap_gently(void *start, size_t length,
 +                int prot, int flags, int fd, off_t offset)
  {
        void *ret;
  
                        return NULL;
                release_pack_memory(length);
                ret = mmap(start, length, prot, flags, fd, offset);
 -              if (ret == MAP_FAILED)
 -                      die_errno("Out of memory? mmap failed");
        }
        return ret;
  }
  
 +void *xmmap(void *start, size_t length,
 +      int prot, int flags, int fd, off_t offset)
 +{
 +      void *ret = xmmap_gently(start, length, prot, flags, fd, offset);
 +      if (ret == MAP_FAILED)
 +              die_errno("mmap failed");
 +      return ret;
 +}
 +
  void close_pack_windows(struct packed_git *p)
  {
        while (p->windows) {
@@@ -2488,8 -2470,10 +2485,8 @@@ static int fill_pack_entry(const unsign
         * answer, as it may have been deleted since the index was
         * loaded!
         */
 -      if (!is_pack_valid(p)) {
 -              warning("packfile %s cannot be accessed", p->pack_name);
 +      if (!is_pack_valid(p))
                return 0;
 -      }
        e->offset = offset;
        e->p = p;
        hashcpy(e->sha1, sha1);
@@@ -3012,18 -2996,12 +3009,18 @@@ static int freshen_loose_object(const u
  static int freshen_packed_object(const unsigned char *sha1)
  {
        struct pack_entry e;
 -      return find_pack_entry(sha1, &e) && freshen_file(e.p->pack_name);
 +      if (!find_pack_entry(sha1, &e))
 +              return 0;
 +      if (e.p->freshened)
 +              return 1;
 +      if (!freshen_file(e.p->pack_name))
 +              return 0;
 +      e.p->freshened = 1;
 +      return 1;
  }
  
 -int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *returnsha1)
 +int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1)
  {
 -      unsigned char sha1[20];
        char hdr[32];
        int hdrlen;
  
         * it out into .git/objects/??/?{38} file.
         */
        write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
 -      if (returnsha1)
 -              hashcpy(returnsha1, sha1);
 -      if (freshen_loose_object(sha1) || freshen_packed_object(sha1))
 +      if (freshen_packed_object(sha1) || freshen_loose_object(sha1))
                return 0;
        return write_loose_object(sha1, hdr, hdrlen, buf, len, 0);
  }
  
 +int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type,
 +                           unsigned char *sha1, unsigned flags)
 +{
 +      char *header;
 +      int hdrlen, status = 0;
 +
 +      /* type string, SP, %lu of the length plus NUL must fit this */
 +      header = xmalloc(strlen(type) + 32);
 +      write_sha1_file_prepare(buf, len, type, sha1, header, &hdrlen);
 +
 +      if (!(flags & HASH_WRITE_OBJECT))
 +              goto cleanup;
 +      if (freshen_packed_object(sha1) || freshen_loose_object(sha1))
 +              goto cleanup;
 +      status = write_loose_object(sha1, header, hdrlen, buf, len, 0);
 +
 +cleanup:
 +      free(header);
 +      return status;
 +}
 +
  int force_object_loose(const unsigned char *sha1, time_t mtime)
  {
        void *buf;
@@@ -3092,7 -3051,7 +3089,7 @@@ int has_sha1_pack(const unsigned char *
        return find_pack_entry(sha1, &e);
  }
  
 -int has_sha1_file(const unsigned char *sha1)
 +int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
  {
        struct pack_entry e;
  
                return 1;
        if (has_loose_object(sha1))
                return 1;
 +      if (flags & HAS_SHA1_QUICK)
 +              return 0;
        reprepare_packed_git();
        return find_pack_entry(sha1, &e);
  }
@@@ -3219,7 -3176,7 +3216,7 @@@ static int index_core(unsigned char *sh
        int ret;
  
        if (!size) {
 -              ret = index_mem(sha1, NULL, size, type, path, flags);
 +              ret = index_mem(sha1, "", size, type, path, flags);
        } else if (size <= SMALL_FILE_SIZE) {
                char *buf = xmalloc(size);
                if (size == read_in_full(fd, buf, size))
@@@ -3458,7 -3415,7 +3455,7 @@@ static int loose_from_alt_odb(struct al
        return r;
  }
  
 -int for_each_loose_object(each_loose_object_fn cb, void *data)
 +int for_each_loose_object(each_loose_object_fn cb, void *data, unsigned flags)
  {
        struct loose_alt_odb_data alt;
        int r;
        if (r)
                return r;
  
 +      if (flags & FOR_EACH_OBJECT_LOCAL_ONLY)
 +              return 0;
 +
        alt.cb = cb;
        alt.data = data;
        return foreach_alt_odb(loose_from_alt_odb, &alt);
@@@ -3495,15 -3449,13 +3492,15 @@@ static int for_each_object_in_pack(stru
        return r;
  }
  
 -int for_each_packed_object(each_packed_object_fn cb, void *data)
 +int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
  {
        struct packed_git *p;
        int r = 0;
  
        prepare_packed_git();
        for (p = packed_git; p; p = p->next) {
 +              if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
 +                      continue;
                r = for_each_object_in_pack(p, cb, data);
                if (r)
                        break;