From: Junio C Hamano Date: Wed, 21 Jun 2006 10:51:59 +0000 (-0700) Subject: Merge branch 'ff/c99' into next X-Git-Tag: v1.4.1-rc1~7 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9d24ed4f019e035eeb8125c2c595876ad1211a3a?ds=inline;hp=-c Merge branch 'ff/c99' into next * ff/c99: Remove all void-pointer arithmetic. --- 9d24ed4f019e035eeb8125c2c595876ad1211a3a diff --combined diff.c index bc32a4aa29,fb1411c52d..22b643cc25 --- a/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. @@@ -630,7 -575,6 +630,7 @@@ 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; } @@@ -658,9 -602,7 +658,9 @@@ 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; @@@ -670,9 -612,8 +670,9 @@@ 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 2e7d022819,9853619687..8d472f0202 --- a/http-push.c +++ b/http-push.c @@@ -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, @@@ -1722,7 -1713,8 +1722,7 @@@ 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, @@@ -1744,7 -1736,7 +1744,7 @@@ 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); @@@ -1765,9 -1757,8 +1765,9 @@@ 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) { @@@ -1777,16 -1768,15 +1777,16 @@@ 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 7a8c16c317,ba6525d1f4..bed2497b79 --- a/pack-objects.c +++ b/pack-objects.c @@@ -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 3d724acf23,44d42969e5..c1e81f976f --- a/pkt-line.c +++ b/pkt-line.c @@@ -16,13 -16,12 +16,13 @@@ * 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 5f70a5b810,bee8a09cbf..74d0dabe5d --- a/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;