Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Wed, 25 Mar 2009 02:45:57 +0000 (19:45 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Mar 2009 02:45:57 +0000 (19:45 -0700)
* maint:
Increase the size of the die/warning buffer to avoid truncation
close_sha1_file(): make it easier to diagnose errors
avoid possible overflow in delta size filtering computation

1  2 
builtin-pack-objects.c
sha1_file.c
diff --combined builtin-pack-objects.c
index 1c6d2c498bae77aab0aaf32ba6f857fbb7ead44f,8ca46c8deb09a4c7d32947033eab804b108e0a34..2000d97ec406a439db81542684f77ebbec9d0172
@@@ -1293,7 -1293,7 +1293,7 @@@ static int try_delta(struct unpacked *t
                max_size = trg_entry->delta_size;
                ref_depth = trg->depth;
        }
-       max_size = max_size * (max_depth - src->depth) /
+       max_size = (uint64_t)max_size * (max_depth - src->depth) /
                                                (max_depth - ref_depth + 1);
        if (max_size == 0)
                return 0;
@@@ -1966,7 -1966,11 +1966,7 @@@ static void add_objects_in_unpacked_pac
                const unsigned char *sha1;
                struct object *o;
  
 -              for (i = 0; i < revs->num_ignore_packed; i++) {
 -                      if (matches_pack_name(p, revs->ignore_packed[i]))
 -                              break;
 -              }
 -              if (revs->num_ignore_packed <= i)
 +              if (p->pack_keep)
                        continue;
                if (open_pack_index(p))
                        die("cannot open pack index");
@@@ -2002,7 -2006,11 +2002,7 @@@ static void loosen_unused_packed_object
        const unsigned char *sha1;
  
        for (p = packed_git; p; p = p->next) {
 -              for (i = 0; i < revs->num_ignore_packed; i++) {
 -                      if (matches_pack_name(p, revs->ignore_packed[i]))
 -                              break;
 -              }
 -              if (revs->num_ignore_packed <= i)
 +              if (p->pack_keep)
                        continue;
  
                if (open_pack_index(p))
@@@ -2200,7 -2208,7 +2200,7 @@@ int cmd_pack_objects(int argc, const ch
                        continue;
                }
                if (!strcmp("--unpacked", arg) ||
 -                  !prefixcmp(arg, "--unpacked=") ||
 +                  !strcmp("--kept-pack-only", arg) ||
                    !strcmp("--reflog", arg) ||
                    !strcmp("--all", arg)) {
                        use_internal_rev_list = 1;
diff --combined sha1_file.c
index 456317356f323eb744c207d787a2e7598ad9601e,a07aa4e5c491d16f65bc109673e806e24efb2274..54972f97e004e2794416baac2f79806a608dc88e
@@@ -1919,8 -1919,25 +1919,8 @@@ off_t find_pack_entry_one(const unsigne
        return 0;
  }
  
 -int matches_pack_name(struct packed_git *p, const char *name)
 -{
 -      const char *last_c, *c;
 -
 -      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, name))
 -              return 1;
 -
 -      return 0;
 -}
 -
 -static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
 +static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e,
 +                       int kept_pack_only)
  {
        static struct packed_git *last_found = (void *)1;
        struct packed_git *p;
        p = (last_found == (void *)1) ? packed_git : last_found;
  
        do {
 -              if (ignore_packed) {
 -                      const char **ig;
 -                      for (ig = ignore_packed; *ig; ig++)
 -                              if (matches_pack_name(p, *ig))
 -                                      break;
 -                      if (*ig)
 -                              goto next;
 -              }
 -
 +              if (kept_pack_only && !p->pack_keep)
 +                      goto next;
                if (p->num_bad_objects) {
                        unsigned i;
                        for (i = 0; i < p->num_bad_objects; i++)
        return 0;
  }
  
 +static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
 +{
 +      return find_pack_ent(sha1, e, 0);
 +}
 +
 +static int find_kept_pack_entry(const unsigned char *sha1, struct pack_entry *e)
 +{
 +      return find_pack_ent(sha1, e, 1);
 +}
 +
  struct packed_git *find_sha1_pack(const unsigned char *sha1,
                                  struct packed_git *packs)
  {
@@@ -2024,7 -2038,7 +2024,7 @@@ int sha1_object_info(const unsigned cha
        struct pack_entry e;
        int status;
  
 -      if (!find_pack_entry(sha1, &e, NULL)) {
 +      if (!find_pack_entry(sha1, &e)) {
                /* Most likely it's a loose object. */
                status = sha1_loose_object_info(sha1, sizep);
                if (status >= 0)
  
                /* Not a loose object; someone else may have just packed it. */
                reprepare_packed_git();
 -              if (!find_pack_entry(sha1, &e, NULL))
 +              if (!find_pack_entry(sha1, &e))
                        return status;
        }
  
@@@ -2051,7 -2065,7 +2051,7 @@@ static void *read_packed_sha1(const uns
        struct pack_entry e;
        void *data;
  
 -      if (!find_pack_entry(sha1, &e, NULL))
 +      if (!find_pack_entry(sha1, &e))
                return NULL;
        data = cache_or_unpack_entry(e.p, e.offset, size, type, 1);
        if (!data) {
@@@ -2287,7 -2301,7 +2287,7 @@@ static void close_sha1_file(int fd
                fsync_or_die(fd, "sha1 file");
        fchmod(fd, 0444);
        if (close(fd) != 0)
-               die("unable to write sha1 file");
+               die("error when closing sha1 file (%s)", strerror(errno));
  }
  
  /* Size of directory component, including the ending '/' */
@@@ -2450,23 -2464,17 +2450,23 @@@ int has_pack_file(const unsigned char *
        return 1;
  }
  
 -int has_sha1_pack(const unsigned char *sha1, const char **ignore_packed)
 +int has_sha1_pack(const unsigned char *sha1)
 +{
 +      struct pack_entry e;
 +      return find_pack_entry(sha1, &e);
 +}
 +
 +int has_sha1_kept_pack(const unsigned char *sha1)
  {
        struct pack_entry e;
 -      return find_pack_entry(sha1, &e, ignore_packed);
 +      return find_kept_pack_entry(sha1, &e);
  }
  
  int has_sha1_file(const unsigned char *sha1)
  {
        struct pack_entry e;
  
 -      if (find_pack_entry(sha1, &e, NULL))
 +      if (find_pack_entry(sha1, &e))
                return 1;
        return has_loose_object(sha1);
  }