Merge branch 'np/types'
authorJunio C Hamano <junkio@cox.net>
Wed, 28 Feb 2007 19:58:27 +0000 (11:58 -0800)
committerJunio C Hamano <junkio@cox.net>
Wed, 28 Feb 2007 19:58:27 +0000 (11:58 -0800)
* np/types:
  Cleanup check_valid in commit-tree.
  make sure enum object_type is signed
  get rid of lookup_object_type()
  convert object type handling from a string to a number
  formalize typename(), and add its reverse type_from_string()
  sha1_file.c: don't ignore an error condition in sha1_loose_object_info()
  sha1_file.c: cleanup "offset" usage
  sha1_file.c: cleanup hdr usage

1  2 
diff.c
index-pack.c

diff --combined diff.c
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -382,7 -382,6 +382,7 @@@ struct emit_callback 
        int nparents, color_diff;
        const char **label_path;
        struct diff_words_data *diff_words;
 +      int *found_changesp;
  };
  
  static void free_diff_words_data(struct emit_callback *ecbdata)
@@@ -502,8 -501,6 +502,8 @@@ static void fn_out_consume(void *priv, 
        const char *set = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);
        const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
  
 +      *(ecbdata->found_changesp) = 1;
 +
        if (ecbdata->label_path[0]) {
                const char *name_a_tab, *name_b_tab;
  
@@@ -1101,7 -1098,6 +1101,7 @@@ static void builtin_diff(const char *na
                if (complete_rewrite) {
                        emit_rewrite_diff(name_a, name_b, one, two,
                                        o->color_diff);
 +                      o->found_changes = 1;
                        goto free_ab_and_return;
                }
        }
                else
                        printf("Binary files %s and %s differ\n",
                               lbl[0], lbl[1]);
 +              o->found_changes = 1;
        }
        else {
                /* Crazy xdl interfaces.. */
                memset(&ecbdata, 0, sizeof(ecbdata));
                ecbdata.label_path = lbl;
                ecbdata.color_diff = o->color_diff;
 +              ecbdata.found_changesp = &o->found_changes;
                xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
                xecfg.ctxlen = o->context;
                xecfg.flags = XDL_EMIT_FUNCNAMES;
@@@ -1436,7 -1430,7 +1436,7 @@@ int diff_populate_filespec(struct diff_
                }
        }
        else {
-               char type[20];
+               enum object_type type;
                struct sha1_size_cache *e;
  
                if (size_only) {
                                s->size = e->size;
                                return 0;
                        }
-                       if (!sha1_object_info(s->sha1, type, &s->size))
+                       type = sha1_object_info(s->sha1, &s->size);
+                       if (type < 0)
                                locate_size_cache(s->sha1, 0, s->size);
                }
                else {
-                       s->data = read_sha1_file(s->sha1, type, &s->size);
+                       s->data = read_sha1_file(s->sha1, &type, &s->size);
                        s->should_free = 1;
                }
        }
@@@ -2461,8 -2456,7 +2462,8 @@@ static void diff_resolve_rename_copy(vo
                                p->status = DIFF_STATUS_RENAMED;
                }
                else if (hashcmp(p->one->sha1, p->two->sha1) ||
 -                       p->one->mode != p->two->mode)
 +                       p->one->mode != p->two->mode ||
 +                       is_null_sha1(p->one->sha1))
                        p->status = DIFF_STATUS_MODIFIED;
                else {
                        /* This is a "no-change" entry and should not
diff --combined index-pack.c
@@@ -277,19 -277,13 +277,19 @@@ static void *get_data_from_pack(struct 
  {
        unsigned long from = obj[0].offset + obj[0].hdr_size;
        unsigned long len = obj[1].offset - from;
 +      unsigned long rdy = 0;
        unsigned char *src, *data;
        z_stream stream;
        int st;
  
        src = xmalloc(len);
 -      if (pread(pack_fd, src, len, from) != len)
 -              die("cannot pread pack file: %s", strerror(errno));
 +      data = src;
 +      do {
 +              ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);
 +              if (n <= 0)
 +                      die("cannot pread pack file: %s", strerror(errno));
 +              rdy += n;
 +      } while (rdy < len);
        data = xmalloc(obj->size);
        memset(&stream, 0, sizeof(stream));
        stream.next_out = data;
@@@ -601,30 -595,23 +601,23 @@@ static void fix_unresolved_deltas(int n
                struct delta_entry *d = sorted_by_pos[i];
                void *data;
                unsigned long size;
-               char type[10];
-               enum object_type obj_type;
+               enum object_type type;
                int j, first, last;
  
                if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
                        continue;
-               data = read_sha1_file(d->base.sha1, type, &size);
+               data = read_sha1_file(d->base.sha1, &type, &size);
                if (!data)
                        continue;
-               if      (!strcmp(type, blob_type))   obj_type = OBJ_BLOB;
-               else if (!strcmp(type, tree_type))   obj_type = OBJ_TREE;
-               else if (!strcmp(type, commit_type)) obj_type = OBJ_COMMIT;
-               else if (!strcmp(type, tag_type))    obj_type = OBJ_TAG;
-               else die("base object %s is of type '%s'",
-                        sha1_to_hex(d->base.sha1), type);
  
                find_delta_children(&d->base, &first, &last);
                for (j = first; j <= last; j++) {
                        struct object_entry *child = objects + deltas[j].obj_no;
                        if (child->real_type == OBJ_REF_DELTA)
-                               resolve_delta(child, data, size, obj_type);
+                               resolve_delta(child, data, size, type);
                }
  
-               append_obj_to_pack(data, size, obj_type);
+               append_obj_to_pack(data, size, type);
                free(data);
                if (verbose)
                        percent = display_progress(nr_resolved_deltas,