Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Wed, 27 Jun 2007 01:33:24 +0000 (18:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Jun 2007 01:45:29 +0000 (18:45 -0700)
* maint:
config: Change output of --get-regexp for valueless keys
config: Complete documentation of --get-regexp
cleanup merge-base test script
Fix zero-object version-2 packs
Ignore submodule commits when fetching over dumb protocols

1  2 
Documentation/git-config.txt
fetch.c
sha1_file.c
t/t1300-repo-config.sh
index f2c67176f451483abdbe862fd5d1cc8fe6b67aac,387d7bc84123d7a4e694104b5e59fa7535fceda7..bb6dbb0ec430de41a9964b88bbf5b44b394023b4
@@@ -14,6 -14,7 +14,7 @@@ SYNOPSI
  'git-config' [--system | --global] --replace-all name [value [value_regex]]
  'git-config' [--system | --global] [type] --get name [value_regex]
  'git-config' [--system | --global] [type] --get-all name [value_regex]
+ 'git-config' [--system | --global] [type] --get-regexp name_regex [value_regex]
  'git-config' [--system | --global] --unset name [value_regex]
  'git-config' [--system | --global] --unset-all name [value_regex]
  'git-config' [--system | --global] --rename-section old_name new_name
@@@ -73,6 -74,7 +74,7 @@@ OPTION
  
  --get-regexp::
        Like --get-all, but interprets the name as a regular expression.
+       Also outputs the key names.
  
  --global::
        For writing options: write to global ~/.gitconfig file rather than
@@@ -291,3 -293,4 +293,3 @@@ Documentation by Johannes Schindelin, P
  GIT
  ---
  Part of the gitlink:git[7] suite
 -
diff --combined fetch.c
index dda33e548b65e79e22de8a84ab4d67ef13387a05,6f1f420be26ac6dafec366b3dc0671fb7f4940dc..811be87a3c1e0d14d9f2b37650d56575b49caa22
+++ b/fetch.c
@@@ -15,7 -15,7 +15,7 @@@ int get_verbosely = 0
  int get_recover = 0;
  static unsigned char current_commit_sha1[20];
  
 -void pull_say(const char *fmt, const char *hex) 
 +void pull_say(const char *fmt, const char *hex)
  {
        if (get_verbosely)
                fprintf(stderr, fmt, hex);
@@@ -46,6 -46,9 +46,9 @@@ static int process_tree(struct tree *tr
        while (tree_entry(&desc, &entry)) {
                struct object *obj = NULL;
  
 -              if (S_ISDIRLNK(entry.mode))
+               /* submodule commits are not stored in the superproject */
++              if (S_ISGITLINK(entry.mode))
+                       continue;
                if (S_ISDIR(entry.mode)) {
                        struct tree *tree = lookup_tree(entry.sha1);
                        if (tree)
@@@ -153,7 -156,7 +156,7 @@@ static int process(struct object *obj
                        return 0;
                prefetch(obj->sha1);
        }
 -              
 +
        object_list_insert(obj, process_queue_end);
        process_queue_end = &(*process_queue_end)->next;
        return 0;
diff --combined sha1_file.c
index 7628ee97d9137c3cc2eae2e626fc708a88dc444a,b9d07de1564cb0ee8544cbc25428cdfd19a83ffd..f2b1ae0325ea16e4e46152c3d3d2d3d7f2b32e3d
@@@ -193,7 -193,7 +193,7 @@@ char *sha1_pack_name(const unsigned cha
                *buf++ = hex[val >> 4];
                *buf++ = hex[val & 0xf];
        }
 -      
 +
        return base;
  }
  
@@@ -218,7 -218,7 +218,7 @@@ char *sha1_pack_index_name(const unsign
                *buf++ = hex[val >> 4];
                *buf++ = hex[val & 0xf];
        }
 -      
 +
        return base;
  }
  
@@@ -376,12 -376,11 +376,12 @@@ void prepare_alt_odb(void
  {
        const char *alt;
  
 +      if (alt_odb_tail)
 +              return;
 +
        alt = getenv(ALTERNATE_DB_ENVIRONMENT);
        if (!alt) alt = "";
  
 -      if (alt_odb_tail)
 -              return;
        alt_odb_tail = &alt_odb_list;
        link_alt_odb_entries(alt, alt + strlen(alt), ':', NULL, 0);
  
@@@ -413,7 -412,7 +413,7 @@@ static size_t peak_pack_mapped
  static size_t pack_mapped;
  struct packed_git *packed_git;
  
 -void pack_report()
 +void pack_report(void)
  {
        fprintf(stderr,
                "pack_report: getpagesize()            = %10" SZ_FMT "\n"
@@@ -510,7 -509,10 +510,10 @@@ static int check_packed_git_idx(const c
                 * for offsets larger than 2^31.
                 */
                unsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20;
-               if (idx_size < min_size || idx_size > min_size + (nr - 1)*8) {
+               unsigned long max_size = min_size;
+               if (nr)
+                       max_size += (nr - 1)*8;
+               if (idx_size < min_size || idx_size > max_size) {
                        munmap(idx_map, idx_size);
                        return error("wrong index file size in %s", path);
                }
        return 0;
  }
  
 +int open_pack_index(struct packed_git *p)
 +{
 +      char *idx_name;
 +      int ret;
 +
 +      if (p->index_data)
 +              return 0;
 +
 +      idx_name = xstrdup(p->pack_name);
 +      strcpy(idx_name + strlen(idx_name) - strlen(".pack"), ".idx");
 +      ret = check_packed_git_idx(idx_name, p);
 +      free(idx_name);
 +      return ret;
 +}
 +
  static void scan_windows(struct packed_git *p,
        struct packed_git **lru_p,
        struct pack_window **lru_w,
@@@ -621,9 -608,6 +624,9 @@@ static int open_packed_git_1(struct pac
        unsigned char *idx_sha1;
        long fd_flag;
  
 +      if (!p->index_data && open_pack_index(p))
 +              return error("packfile %s index unavailable", p->pack_name);
 +
        p->pack_fd = open(p->pack_name, O_RDONLY);
        if (p->pack_fd < 0 || fstat(p->pack_fd, &st))
                return -1;
@@@ -776,7 -760,8 +779,7 @@@ struct packed_git *add_packed_git(cons
                return NULL;
        memcpy(p->pack_name, path, path_len);
        strcpy(p->pack_name + path_len, ".pack");
 -      if (stat(p->pack_name, &st) || !S_ISREG(st.st_mode) ||
 -          check_packed_git_idx(path, p)) {
 +      if (stat(p->pack_name, &st) || !S_ISREG(st.st_mode)) {
                free(p);
                return NULL;
        }
        /* ok, it looks sane as far as we can check without
         * actually mapping the pack file.
         */
 +      p->index_version = 0;
 +      p->index_data = NULL;
 +      p->index_size = 0;
 +      p->num_objects = 0;
        p->pack_size = st.st_size;
        p->next = NULL;
        p->windows = NULL;
@@@ -959,7 -940,7 +962,7 @@@ int check_sha1_signature(const unsigne
        return hashcmp(sha1, real_sha1) ? -1 : 0;
  }
  
 -void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
 +static void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
  {
        struct stat st;
        void *map;
        return map;
  }
  
 -int legacy_loose_object(unsigned char *map)
 +static int legacy_loose_object(unsigned char *map)
  {
        unsigned int word;
  
@@@ -1056,14 -1037,6 +1059,14 @@@ static int unpack_sha1_header(z_stream 
                return inflate(stream, 0);
        }
  
 +
 +      /*
 +       * There used to be a second loose object header format which
 +       * was meant to mimic the in-pack format, allowing for direct
 +       * copy of the object data.  This format turned up not to be
 +       * really worth it and we don't write it any longer.  But we
 +       * can still read it.
 +       */
        used = unpack_object_header_gently(map, mapsize, &type, &size);
        if (!used || !valid_loose_object_type[type])
                return -1;
@@@ -1139,7 -1112,7 +1142,7 @@@ static int parse_sha1_header(const cha
        unsigned long size;
  
        /*
 -       * The type can be at most ten bytes (including the 
 +       * The type can be at most ten bytes (including the
         * terminating '\0' that we add), and is followed by
         * a space.
         */
@@@ -1594,15 -1567,10 +1597,15 @@@ void *unpack_entry(struct packed_git *p
        return data;
  }
  
 -const unsigned char *nth_packed_object_sha1(const struct packed_git *p,
 +const unsigned char *nth_packed_object_sha1(struct packed_git *p,
                                            uint32_t n)
  {
        const unsigned char *index = p->index_data;
 +      if (!index) {
 +              if (open_pack_index(p))
 +                      return NULL;
 +              index = p->index_data;
 +      }
        if (n >= p->num_objects)
                return NULL;
        index += 4 * 256;
@@@ -1639,12 -1607,6 +1642,12 @@@ off_t find_pack_entry_one(const unsigne
        const unsigned char *index = p->index_data;
        unsigned hi, lo;
  
 +      if (!index) {
 +              if (open_pack_index(p))
 +                      return 0;
 +              level1_ofs = p->index_data;
 +              index = p->index_data;
 +      }
        if (p->index_version > 1) {
                level1_ofs += 2;
                index += 8;
@@@ -1687,25 -1649,20 +1690,25 @@@ static int matches_pack_name(struct pac
  
  static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
  {
 +      static struct packed_git *last_found = (void *)1;
        struct packed_git *p;
        off_t offset;
  
        prepare_packed_git();
 +      if (!packed_git)
 +              return 0;
 +      p = (last_found == (void *)1) ? packed_git : last_found;
  
 -      for (p = packed_git; p; p = p->next) {
 +      do {
                if (ignore_packed) {
                        const char **ig;
                        for (ig = ignore_packed; *ig; ig++)
                                if (!matches_pack_name(p, *ig))
                                        break;
                        if (*ig)
 -                              continue;
 +                              goto next;
                }
 +
                offset = find_pack_entry_one(sha1, p);
                if (offset) {
                        /*
                         */
                        if (p->pack_fd == -1 && open_packed_git(p)) {
                                error("packfile %s cannot be accessed", p->pack_name);
 -                              continue;
 +                              goto next;
                        }
                        e->offset = offset;
                        e->p = p;
                        hashcpy(e->sha1, sha1);
 +                      last_found = p;
                        return 1;
                }
 -      }
 +
 +              next:
 +              if (p == last_found)
 +                      p = packed_git;
 +              else
 +                      p = p->next;
 +              if (p == last_found)
 +                      p = p->next;
 +      } while (p);
        return 0;
  }
  
 -struct packed_git *find_sha1_pack(const unsigned char *sha1, 
 +struct packed_git *find_sha1_pack(const unsigned char *sha1,
                                  struct packed_git *packs)
  {
        struct packed_git *p;
@@@ -2017,6 -1965,40 +2020,6 @@@ static int write_buffer(int fd, const v
        return 0;
  }
  
 -static int write_binary_header(unsigned char *hdr, enum object_type type, unsigned long len)
 -{
 -      int hdr_len;
 -      unsigned char c;
 -
 -      c = (type << 4) | (len & 15);
 -      len >>= 4;
 -      hdr_len = 1;
 -      while (len) {
 -              *hdr++ = c | 0x80;
 -              hdr_len++;
 -              c = (len & 0x7f);
 -              len >>= 7;
 -      }
 -      *hdr = c;
 -      return hdr_len;
 -}
 -
 -static void setup_object_header(z_stream *stream, const char *type, unsigned long len)
 -{
 -      int obj_type, hdrlen;
 -
 -      if (use_legacy_headers) {
 -              while (deflate(stream, 0) == Z_OK)
 -                      /* nothing */;
 -              return;
 -      }
 -      obj_type = type_from_string(type);
 -      hdrlen = write_binary_header(stream->next_out, obj_type, len);
 -      stream->total_out = hdrlen;
 -      stream->next_out += hdrlen;
 -      stream->avail_out -= hdrlen;
 -}
 -
  int hash_sha1_file(const void *buf, unsigned long len, const char *type,
                     unsigned char *sha1)
  {
@@@ -2083,8 -2065,7 +2086,8 @@@ int write_sha1_file(void *buf, unsigne
        /* First header.. */
        stream.next_in = (unsigned char *)hdr;
        stream.avail_in = hdrlen;
 -      setup_object_header(&stream, type, len);
 +      while (deflate(&stream, 0) == Z_OK)
 +              /* nothing */;
  
        /* Then the data itself.. */
        stream.next_in = buf;
diff --combined t/t1300-repo-config.sh
index 7731fa72ceef16ba85b3ce4dcf1c21630f81f634,f1a78b19ac6e426f4475b66cfe23b89e41c7fafa..84977355a3a1e7812964c3bcbc37f1aa9c67e846
@@@ -283,6 -283,12 +283,12 @@@ EO
  test_expect_success 'get variable with no value' \
        'git-config --get novalue.variable ^$'
  
+ echo novalue.variable > expect
+ test_expect_success 'get-regexp variable with no value' \
+       'git-config --get-regexp novalue > output &&
+        cmp output expect'
  git-config > output 2>&1
  
  test_expect_success 'no arguments, but no crash' \
@@@ -514,3 -520,4 +520,3 @@@ git config --list > resul
  test_expect_success 'value continued on next line' 'cmp result expect'
  
  test_done
 -