]> asedeno.scripts.mit.edu Git - git.git/commitdiff
Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 Oct 2007 19:53:54 +0000 (12:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Oct 2007 19:53:54 +0000 (12:53 -0700)
* maint:
  RelNotes-1.5.3.5: describe recent fixes
  merge-recursive.c: mrtree in merge() is not used before set
  sha1_file.c: avoid gcc signed overflow warnings
  Fix a small memory leak in builtin-add
  honor the http.sslVerify option in shell scripts

1  2 
builtin-add.c
merge-recursive.c
sha1_file.c

diff --combined builtin-add.c
index f9a65803d8dcbb9ae7eb3a3c61d8ac345b84d1cd,373f87f9f296917a8d72c93307f2bb94813b6911..b8e6094b21599051c543b1f77c991363d9dfe181
@@@ -44,6 -44,7 +44,7 @@@ static void prune_directory(struct dir_
                        die("pathspec '%s' did not match any files",
                                        pathspec[i]);
        }
+         free(seen);
  }
  
  static void fill_directory(struct dir_struct *dir, const char **pathspec,
        baselen = common_prefix(pathspec);
        path = ".";
        base = "";
 -      if (baselen) {
 -              char *common = xmalloc(baselen + 1);
 -              memcpy(common, *pathspec, baselen);
 -              common[baselen] = 0;
 -              path = base = common;
 -      }
 +      if (baselen)
 +              path = base = xmemdupz(*pathspec, baselen);
  
        /* Read the directory and prune it */
        read_directory(dir, path, base, baselen, pathspec);
@@@ -99,6 -104,7 +100,6 @@@ static void update_callback(struct diff
                        break;
                case DIFF_STATUS_DELETED:
                        remove_file_from_cache(path);
 -                      cache_tree_invalidate_path(active_cache_tree, path);
                        if (verbose)
                                printf("remove '%s'\n", path);
                        break;
@@@ -135,6 -141,7 +136,7 @@@ static void refresh(int verbose, const 
                if (!seen[i])
                        die("pathspec '%s' did not match any files", pathspec[i]);
        }
+         free(seen);
  }
  
  static int git_add_config(const char *var, const char *value)
diff --combined merge-recursive.c
index 4a5c77c3b632a9c0636848b933ef5395b01b7103,c2e1cb69e3e25ccb1851273ee4ee3a06e795dd37..6c6f595fbc7da09a41228e09cd2c5ef48b91f3f0
@@@ -85,59 -85,63 +85,59 @@@ struct stage_dat
        unsigned processed:1;
  };
  
 -struct output_buffer
 -{
 -      struct output_buffer *next;
 -      char *str;
 -};
 -
  static struct path_list current_file_set = {NULL, 0, 0, 1};
  static struct path_list current_directory_set = {NULL, 0, 0, 1};
  
  static int call_depth = 0;
  static int verbosity = 2;
 +static int rename_limit = -1;
  static int buffer_output = 1;
 -static struct output_buffer *output_list, *output_end;
 +static struct strbuf obuf = STRBUF_INIT;
  
 -static int show (int v)
 +static int show(int v)
  {
        return (!call_depth && verbosity >= v) || verbosity >= 5;
  }
  
 -static void output(int v, const char *fmt, ...)
 +static void flush_output(void)
  {
 -      va_list args;
 -      va_start(args, fmt);
 -      if (buffer_output && show(v)) {
 -              struct output_buffer *b = xmalloc(sizeof(*b));
 -              nfvasprintf(&b->str, fmt, args);
 -              b->next = NULL;
 -              if (output_end)
 -                      output_end->next = b;
 -              else
 -                      output_list = b;
 -              output_end = b;
 -      } else if (show(v)) {
 -              int i;
 -              for (i = call_depth; i--;)
 -                      fputs("  ", stdout);
 -              vfprintf(stdout, fmt, args);
 -              fputc('\n', stdout);
 +      if (obuf.len) {
 +              fputs(obuf.buf, stdout);
 +              strbuf_reset(&obuf);
        }
 -      va_end(args);
  }
  
 -static void flush_output(void)
 +static void output(int v, const char *fmt, ...)
  {
 -      struct output_buffer *b, *n;
 -      for (b = output_list; b; b = n) {
 -              int i;
 -              for (i = call_depth; i--;)
 -                      fputs("  ", stdout);
 -              fputs(b->str, stdout);
 -              fputc('\n', stdout);
 -              n = b->next;
 -              free(b->str);
 -              free(b);
 +      int len;
 +      va_list ap;
 +
 +      if (!show(v))
 +              return;
 +
 +      strbuf_grow(&obuf, call_depth * 2 + 2);
 +      memset(obuf.buf + obuf.len, ' ', call_depth * 2);
 +      strbuf_setlen(&obuf, obuf.len + call_depth * 2);
 +
 +      va_start(ap, fmt);
 +      len = vsnprintf(obuf.buf + obuf.len, strbuf_avail(&obuf), fmt, ap);
 +      va_end(ap);
 +
 +      if (len < 0)
 +              len = 0;
 +      if (len >= strbuf_avail(&obuf)) {
 +              strbuf_grow(&obuf, len + 2);
 +              va_start(ap, fmt);
 +              len = vsnprintf(obuf.buf + obuf.len, strbuf_avail(&obuf), fmt, ap);
 +              va_end(ap);
 +              if (len >= strbuf_avail(&obuf)) {
 +                      die("this should not happen, your snprintf is broken");
 +              }
        }
 -      output_list = NULL;
 -      output_end = NULL;
 +      strbuf_setlen(&obuf, obuf.len + len);
 +      strbuf_add(&obuf, "\n", 1);
 +      if (!buffer_output)
 +              flush_output();
  }
  
  static void output_commit_title(struct commit *commit)
@@@ -368,7 -372,6 +368,7 @@@ static struct path_list *get_renames(st
        diff_setup(&opts);
        opts.recursive = 1;
        opts.detect_rename = DIFF_DETECT_RENAME;
 +      opts.rename_limit = rename_limit;
        opts.output_format = DIFF_FORMAT_NO_OUTPUT;
        if (diff_setup_done(&opts) < 0)
                die("diff setup failed");
@@@ -429,15 -432,19 +429,15 @@@ static int update_stages(const char *pa
  
  static int remove_path(const char *name)
  {
 -      int ret, len;
 +      int ret;
        char *slash, *dirs;
  
        ret = unlink(name);
        if (ret)
                return ret;
 -      len = strlen(name);
 -      dirs = xmalloc(len+1);
 -      memcpy(dirs, name, len);
 -      dirs[len] = '\0';
 +      dirs = xstrdup(name);
        while ((slash = strrchr(name, '/'))) {
                *slash = '\0';
 -              len = slash - name;
                if (rmdir(name) != 0)
                        break;
        }
@@@ -571,7 -578,9 +571,7 @@@ static void update_file_flags(const uns
                        flush_buffer(fd, buf, size);
                        close(fd);
                } else if (S_ISLNK(mode)) {
 -                      char *lnk = xmalloc(size + 1);
 -                      memcpy(lnk, buf, size);
 -                      lnk[size] = '\0';
 +                      char *lnk = xmemdupz(buf, size);
                        mkdir_p(path, 0777);
                        unlink(path);
                        symlink(lnk, path);
@@@ -863,9 -872,14 +863,9 @@@ static int read_merge_config(const cha
                if (!strncmp(fn->name, name, namelen) && !fn->name[namelen])
                        break;
        if (!fn) {
 -              char *namebuf;
                fn = xcalloc(1, sizeof(struct ll_merge_driver));
 -              namebuf = xmalloc(namelen + 1);
 -              memcpy(namebuf, name, namelen);
 -              namebuf[namelen] = 0;
 -              fn->name = namebuf;
 +              fn->name = xmemdupz(name, namelen);
                fn->fn = ll_ext_merge;
 -              fn->next = NULL;
                *ll_user_merge_tail = fn;
                ll_user_merge_tail = &(fn->next);
        }
@@@ -1572,7 -1586,7 +1572,7 @@@ static int merge(struct commit *h1
  {
        struct commit_list *iter;
        struct commit *merged_common_ancestors;
-       struct tree *mrtree;
+       struct tree *mrtree = mrtree;
        int clean;
  
        if (show(4)) {
@@@ -1679,10 -1693,6 +1679,10 @@@ static int merge_config(const char *var
                verbosity = git_config_int(var, value);
                return 0;
        }
 +      if (!strcasecmp(var, "diff.renamelimit")) {
 +              rename_limit = git_config_int(var, value);
 +              return 0;
 +      }
        return git_default_config(var, value);
  }
  
diff --combined sha1_file.c
index 83a06a7aed84715db191b703e529d3501df0a8f2,95b5a403d8d7e8c1657fc8d4c1a8efd15c6a4ca3..f007874cbb034ec9efa7f73c42831e0037d452fa
@@@ -521,13 -521,15 +521,15 @@@ static int check_packed_git_idx(const c
                        munmap(idx_map, idx_size);
                        return error("wrong index v2 file size in %s", path);
                }
-               if (idx_size != min_size) {
-                       /* make sure we can deal with large pack offsets */
-                       off_t x = 0x7fffffffUL, y = 0xffffffffUL;
-                       if (x > (x + 1) || y > (y + 1)) {
-                               munmap(idx_map, idx_size);
-                               return error("pack too large for current definition of off_t in %s", path);
-                       }
+               if (idx_size != min_size &&
+                   /*
+                    * make sure we can deal with large pack offsets.
+                    * 31-bit signed offset won't be enough, neither
+                    * 32-bit unsigned one will be.
+                    */
+                   (sizeof(off_t) <= 4)) {
+                       munmap(idx_map, idx_size);
+                       return error("pack too large for current definition of off_t in %s", path);
                }
        }
  
@@@ -1491,8 -1493,11 +1493,8 @@@ found_cache_entry
                ent->lru.next->prev = ent->lru.prev;
                ent->lru.prev->next = ent->lru.next;
                delta_base_cached -= ent->size;
 -      }
 -      else {
 -              ret = xmalloc(ent->size + 1);
 -              memcpy(ret, ent->data, ent->size);
 -              ((char *)ret)[ent->size] = 0;
 +      } else {
 +              ret = xmemdupz(ent->data, ent->size);
        }
        *type = ent->type;
        *base_size = ent->size;
@@@ -1681,22 -1686,22 +1683,22 @@@ off_t find_pack_entry_one(const unsigne
        return 0;
  }
  
 -static int matches_pack_name(struct packed_git *p, const char *ig)
 +int matches_pack_name(struct packed_git *p, const char *name)
  {
        const char *last_c, *c;
  
 -      if (!strcmp(p->pack_name, ig))
 -              return 0;
 +      if (!strcmp(p->pack_name, name))
 +              return 1;
  
        for (c = p->pack_name, last_c = c; *c;)
                if (*c == '/')
                        last_c = ++c;
                else
                        ++c;
 -      if (!strcmp(last_c, ig))
 -              return 0;
 +      if (!strcmp(last_c, name))
 +              return 1;
  
 -      return 1;
 +      return 0;
  }
  
  static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
                if (ignore_packed) {
                        const char **ig;
                        for (ig = ignore_packed; *ig; ig++)
 -                              if (!matches_pack_name(p, *ig))
 +                              if (matches_pack_name(p, *ig))
                                        break;
                        if (*ig)
                                goto next;
@@@ -1869,9 -1874,12 +1871,9 @@@ void *read_sha1_file(const unsigned cha
  
        co = find_cached_object(sha1);
        if (co) {
 -              buf = xmalloc(co->size + 1);
 -              memcpy(buf, co->buf, co->size);
 -              ((char*)buf)[co->size] = 0;
                *type = co->type;
                *size = co->size;
 -              return buf;
 +              return xmemdupz(co->buf, co->size);
        }
  
        buf = read_packed_sha1(sha1, type, size);
@@@ -2296,25 -2304,68 +2298,25 @@@ int has_sha1_file(const unsigned char *
        return find_sha1_file(sha1, &st) ? 1 : 0;
  }
  
 -/*
 - * reads from fd as long as possible into a supplied buffer of size bytes.
 - * If necessary the buffer's size is increased using realloc()
 - *
 - * returns 0 if anything went fine and -1 otherwise
 - *
 - * The buffer is always NUL-terminated, not including it in returned size.
 - *
 - * NOTE: both buf and size may change, but even when -1 is returned
 - * you still have to free() it yourself.
 - */
 -int read_fd(int fd, char **return_buf, unsigned long *return_size)
 -{
 -      char *buf = *return_buf;
 -      unsigned long size = *return_size;
 -      ssize_t iret;
 -      unsigned long off = 0;
 -
 -      if (!buf || size <= 1) {
 -              size = 1024;
 -              buf = xrealloc(buf, size);
 -      }
 -
 -      do {
 -              iret = xread(fd, buf + off, (size - 1) - off);
 -              if (iret > 0) {
 -                      off += iret;
 -                      if (off == size - 1) {
 -                              size = alloc_nr(size);
 -                              buf = xrealloc(buf, size);
 -                      }
 -              }
 -      } while (iret > 0);
 -
 -      buf[off] = '\0';
 -
 -      *return_buf = buf;
 -      *return_size = off;
 -
 -      if (iret < 0)
 -              return -1;
 -      return 0;
 -}
 -
  int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)
  {
 -      unsigned long size = 4096;
 -      char *buf = xmalloc(size);
 +      struct strbuf buf;
        int ret;
  
 -      if (read_fd(fd, &buf, &size)) {
 -              free(buf);
 +      strbuf_init(&buf, 0);
 +      if (strbuf_read(&buf, fd, 4096) < 0) {
 +              strbuf_release(&buf);
                return -1;
        }
  
        if (!type)
                type = blob_type;
        if (write_object)
 -              ret = write_sha1_file(buf, size, type, sha1);
 +              ret = write_sha1_file(buf.buf, buf.len, type, sha1);
        else
 -              ret = hash_sha1_file(buf, size, type, sha1);
 -      free(buf);
 +              ret = hash_sha1_file(buf.buf, buf.len, type, sha1);
 +      strbuf_release(&buf);
 +
        return ret;
  }
  
@@@ -2336,11 -2387,12 +2338,11 @@@ int index_fd(unsigned char *sha1, int f
         * Convert blobs to git internal format
         */
        if ((type == OBJ_BLOB) && S_ISREG(st->st_mode)) {
 -              unsigned long nsize = size;
 -              char *nbuf = convert_to_git(path, buf, &nsize);
 -              if (nbuf) {
 +              struct strbuf nbuf;
 +              strbuf_init(&nbuf, 0);
 +              if (convert_to_git(path, buf, size, &nbuf)) {
                        munmap(buf, size);
 -                      size = nsize;
 -                      buf = nbuf;
 +                      buf = strbuf_detach(&nbuf, &size);
                        re_allocated = 1;
                }
        }