Merge branch 'ff/c99' into next
authorJunio C Hamano <junkio@cox.net>
Wed, 21 Jun 2006 10:51:59 +0000 (03:51 -0700)
committerJunio C Hamano <junkio@cox.net>
Wed, 21 Jun 2006 10:51:59 +0000 (03:51 -0700)
* ff/c99:
Remove all void-pointer arithmetic.

1  2 
diff.c
http-push.c
pack-objects.c
pkt-line.c
tag.c
diff --combined diff.c
index bc32a4aa29171af6ca268a54cde881934079de83,fb1411c52d1cce9c51ad33272624e4d027debc2e..22b643cc2520664416ceac9998d401a6585f07bf
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -25,20 -25,6 +25,20 @@@ int git_diff_config(const char *var, co
        return git_default_config(var, value);
  }
  
 +enum color_diff {
 +      DIFF_PLAIN = 0,
 +      DIFF_METAINFO = 1,
 +      DIFF_FILE_OLD = 2,
 +      DIFF_FILE_NEW = 3,
 +};
 +
 +static const char *diff_colors[] = {
 +      "\033[0;0m",
 +      "\033[1;35m",
 +      "\033[1;31m",
 +      "\033[1;34m",
 +};
 +
  static char *quote_one(const char *str)
  {
        int needlen;
@@@ -191,54 -177,23 +191,54 @@@ static int fill_mmfile(mmfile_t *mf, st
  }
  
  struct emit_callback {
 +      struct xdiff_emit_state xm;
 +      int nparents, color_diff;
        const char **label_path;
  };
  
 -static int fn_out(void *priv, mmbuffer_t *mb, int nbuf)
 +static inline void color_diff(int diff_use_color, enum color_diff ix)
 +{
 +      if (diff_use_color)
 +              fputs(diff_colors[ix], stdout);
 +}
 +
 +static void fn_out_consume(void *priv, char *line, unsigned long len)
  {
        int i;
        struct emit_callback *ecbdata = priv;
  
        if (ecbdata->label_path[0]) {
 +              color_diff(ecbdata->color_diff, DIFF_METAINFO);
                printf("--- %s\n", ecbdata->label_path[0]);
 +              color_diff(ecbdata->color_diff, DIFF_METAINFO);
                printf("+++ %s\n", ecbdata->label_path[1]);
                ecbdata->label_path[0] = ecbdata->label_path[1] = NULL;
        }
 -      for (i = 0; i < nbuf; i++)
 -              if (!fwrite(mb[i].ptr, mb[i].size, 1, stdout))
 -                      return -1;
 -      return 0;
 +
 +      /* This is not really necessary for now because
 +       * this codepath only deals with two-way diffs.
 +       */
 +      for (i = 0; i < len && line[i] == '@'; i++)
 +              ;
 +      if (2 <= i && i < len && line[i] == ' ') {
 +              ecbdata->nparents = i - 1;
 +              color_diff(ecbdata->color_diff, DIFF_METAINFO);
 +      }
 +      else if (len < ecbdata->nparents)
 +              color_diff(ecbdata->color_diff, DIFF_PLAIN);
 +      else {
 +              int nparents = ecbdata->nparents;
 +              int color = DIFF_PLAIN;
 +              for (i = 0; i < nparents && len; i++) {
 +                      if (line[i] == '-')
 +                              color = DIFF_FILE_OLD;
 +                      else if (line[i] == '+')
 +                              color = DIFF_FILE_NEW;
 +              }
 +              color_diff(ecbdata->color_diff, color);
 +      }
 +      fwrite(line, len, 1, stdout);
 +      color_diff(ecbdata->color_diff, DIFF_PLAIN);
  }
  
  static char *pprint_rename(const char *a, const char *b)
@@@ -560,7 -515,7 +560,7 @@@ static void emit_binary_diff(mmfile_t *
                else
                        line[0] = bytes - 26 + 'a' - 1;
                encode_85(line + 1, cp, bytes);
-               cp += bytes;
+               cp = (char *) cp + bytes;
                puts(line);
        }
        printf("\n");
@@@ -594,35 -549,25 +594,35 @@@ static void builtin_diff(const char *na
        b_two = quote_two("b/", name_b);
        lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
        lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
 +      color_diff(o->color_diff, DIFF_METAINFO);
        printf("diff --git %s %s\n", a_one, b_two);
        if (lbl[0][0] == '/') {
                /* /dev/null */
 +              color_diff(o->color_diff, DIFF_METAINFO);
                printf("new file mode %06o\n", two->mode);
 -              if (xfrm_msg && xfrm_msg[0])
 +              if (xfrm_msg && xfrm_msg[0]) {
 +                      color_diff(o->color_diff, DIFF_METAINFO);
                        puts(xfrm_msg);
 +              }
        }
        else if (lbl[1][0] == '/') {
                printf("deleted file mode %06o\n", one->mode);
 -              if (xfrm_msg && xfrm_msg[0])
 +              if (xfrm_msg && xfrm_msg[0]) {
 +                      color_diff(o->color_diff, DIFF_METAINFO);
                        puts(xfrm_msg);
 +              }
        }
        else {
                if (one->mode != two->mode) {
 +                      color_diff(o->color_diff, DIFF_METAINFO);
                        printf("old mode %06o\n", one->mode);
 +                      color_diff(o->color_diff, DIFF_METAINFO);
                        printf("new mode %06o\n", two->mode);
                }
 -              if (xfrm_msg && xfrm_msg[0])
 +              if (xfrm_msg && xfrm_msg[0]) {
 +                      color_diff(o->color_diff, DIFF_METAINFO);
                        puts(xfrm_msg);
 +              }
                /*
                 * we do not run diff between different kind
                 * of objects.
                if ((one->mode ^ two->mode) & S_IFMT)
                        goto free_ab_and_return;
                if (complete_rewrite) {
 +                      color_diff(o->color_diff, DIFF_PLAIN);
                        emit_rewrite_diff(name_a, name_b, one, two);
                        goto free_ab_and_return;
                }
                xdemitcb_t ecb;
                struct emit_callback ecbdata;
  
 +              memset(&ecbdata, 0, sizeof(ecbdata));
                ecbdata.label_path = lbl;
 +              ecbdata.color_diff = o->color_diff;
                xpp.flags = XDF_NEED_MINIMAL;
                xecfg.ctxlen = o->context;
                xecfg.flags = XDL_EMIT_FUNCNAMES;
                        xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
                else if (!strncmp(diffopts, "-u", 2))
                        xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
 -              ecb.outf = fn_out;
 +              ecb.outf = xdiff_outf;
                ecb.priv = &ecbdata;
 +              ecbdata.xm.consume = fn_out_consume;
                xdl_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
        }
  
@@@ -1515,8 -1456,6 +1515,8 @@@ int diff_opt_parse(struct diff_options 
                else if (40 < options->abbrev)
                        options->abbrev = 40;
        }
 +      else if (!strcmp(arg, "--color"))
 +              options->color_diff = 1;
        else
                return 0;
        return 1;
diff --combined http-push.c
index 2e7d02281919841c4f3af38ca49939039573c2b0,9853619687a25501d1dee052f39ebeedcbd8dc69..8d472f0202827db726ede451be3fd63940c38c96
@@@ -196,7 -196,7 +196,7 @@@ static size_t fwrite_sha1_file(void *pt
        struct transfer_request *request = (struct transfer_request *)data;
        do {
                ssize_t retval = write(request->local_fileno,
-                                      ptr + posn, size - posn);
+                                      (char *) ptr + posn, size - posn);
                if (retval < 0)
                        return posn;
                posn += retval;
@@@ -1172,7 -1172,7 +1172,7 @@@ static void one_remote_object(const cha
  
        obj->flags |= REMOTE;
        if (!object_list_contains(objects, obj))
 -              add_object(obj, &objects, NULL, "");
 +              object_list_insert(obj, &objects);
  }
  
  static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed)
@@@ -1700,15 -1700,6 +1700,15 @@@ static int locking_available(void
        return lock_flags;
  }
  
 +struct object_list **add_one_object(struct object *obj, struct object_list **p)
 +{
 +      struct object_list *entry = xmalloc(sizeof(struct object_list));
 +      entry->item = obj;
 +      entry->next = *p;
 +      *p = entry;
 +      return &entry->next;
 +}
 +
  static struct object_list **process_blob(struct blob *blob,
                                         struct object_list **p,
                                         struct name_path *path,
                return p;
  
        obj->flags |= SEEN;
 -      name = strdup(name);
 -      return add_object(obj, p, path, name);
 +      return add_one_object(obj, p);
  }
  
  static struct object_list **process_tree(struct tree *tree,
  
        obj->flags |= SEEN;
        name = strdup(name);
 -      p = add_object(obj, p, NULL, name);
 +      p = add_one_object(obj, p);
        me.up = path;
        me.elem = name;
        me.elem_len = strlen(name);
  
  static int get_delta(struct rev_info *revs, struct remote_lock *lock)
  {
 +      int i;
        struct commit *commit;
 -      struct object_list **p = &objects, *pending;
 +      struct object_list **p = &objects;
        int count = 0;
  
        while ((commit = get_revision(revs)) != NULL) {
                        count += add_send_request(&commit->object, lock);
        }
  
 -      for (pending = revs->pending_objects; pending; pending = pending->next) {
 -              struct object *obj = pending->item;
 -              const char *name = pending->name;
 +      for (i = 0; i < revs->pending.nr; i++) {
 +              struct object_array_entry *entry = revs->pending.objects + i;
 +              struct object *obj = entry->item;
 +              const char *name = entry->name;
  
                if (obj->flags & (UNINTERESTING | SEEN))
                        continue;
                if (obj->type == TYPE_TAG) {
                        obj->flags |= SEEN;
 -                      p = add_object(obj, p, NULL, name);
 +                      p = add_one_object(obj, p);
                        continue;
                }
                if (obj->type == TYPE_TREE) {
diff --combined pack-objects.c
index 7a8c16c317dc42217ab01da8b130b815ad81846d,ba6525d1f4786dad167994bf7a635c13b2b08ef6..bed2497b7974bed96a6ac9478807059cb8de17cb
@@@ -156,7 -156,7 +156,7 @@@ static void prepare_pack_revindex(struc
  
        rix->revindex = xmalloc(sizeof(unsigned long) * (num_ent + 1));
        for (i = 0; i < num_ent; i++) {
-               unsigned int hl = *((unsigned int *)(index + 24 * i));
+               unsigned int hl = *((unsigned int *)((char *) index + 24*i));
                rix->revindex[i] = ntohl(hl);
        }
        /* This knows the pack format -- the 20-byte trailer
@@@ -300,7 -300,7 +300,7 @@@ static unsigned long write_object(struc
                use_packed_git(p);
  
                datalen = find_packed_object_size(p, entry->in_pack_offset);
-               buf = p->pack_base + entry->in_pack_offset;
+               buf = (char *) p->pack_base + entry->in_pack_offset;
                sha1write(f, buf, datalen);
                unuse_packed_git(p);
                hdrlen = 0; /* not really */
@@@ -1221,10 -1221,6 +1221,10 @@@ int main(int argc, char **argv
                                local = 1;
                                continue;
                        }
 +                      if (!strcmp("--progress", arg)) {
 +                              progress = 1;
 +                              continue;
 +                      }
                        if (!strcmp("--incremental", arg)) {
                                incremental = 1;
                                continue;
diff --combined pkt-line.c
index 3d724acf23fab5e8a8e3dd5b1dce957ea1d4a9d3,44d42969e558cf85aca41cf29604dcfda4ebaf7e..c1e81f976f26726db2432f72f7356087a6e3a7d8
   * The writing side could use stdio, but since the reading
   * side can't, we stay with pure read/write interfaces.
   */
 -static void safe_write(int fd, const void *buf, unsigned n)
 +ssize_t safe_write(int fd, const void *buf, ssize_t n)
  {
 +      ssize_t nn = n;
        while (n) {
                int ret = xwrite(fd, buf, n);
                if (ret > 0) {
-                       buf += ret;
+                       buf = (char *) buf + ret;
                        n -= ret;
                        continue;
                }
@@@ -30,7 -29,6 +30,7 @@@
                        die("write error (disk full?)");
                die("write error (%s)", strerror(errno));
        }
 +      return nn;
  }
  
  /*
@@@ -68,7 -66,7 +68,7 @@@ static void safe_read(int fd, void *buf
        int n = 0;
  
        while (n < size) {
-               int ret = xread(fd, buffer + n, size - n);
+               int ret = xread(fd, (char *) buffer + n, size - n);
                if (ret < 0)
                        die("read error (%s)", strerror(errno));
                if (!ret)
diff --combined tag.c
index 5f70a5b8104078b139d2ec87b7aebc6791b4d253,bee8a09cbf5fec119e9b2555beb4cb8b38d8057e..74d0dabe5d8c1f06a3f67475368c34e3b4046456
--- 1/tag.c
--- 2/tag.c
+++ b/tag.c
@@@ -19,7 -19,7 +19,7 @@@ struct tag *lookup_tag(const unsigned c
  {
          struct object *obj = lookup_object(sha1);
          if (!obj) {
 -                struct tag *ret = xcalloc(1, sizeof(struct tag));
 +                struct tag *ret = alloc_tag_node();
                  created_object(sha1, &ret->object);
                  ret->object.type = TYPE_TAG;
                  return ret;
@@@ -47,10 -47,10 +47,10 @@@ int parse_tag_buffer(struct tag *item, 
  
        if (size < 64)
                return -1;
-       if (memcmp("object ", data, 7) || get_sha1_hex(data + 7, object))
+       if (memcmp("object ", data, 7) || get_sha1_hex((char *) data + 7, object))
                return -1;
  
-       type_line = data + 48;
+       type_line = (char *) data + 48;
        if (memcmp("\ntype ", type_line-1, 6))
                return -1;