From: Junio C Hamano Date: Wed, 5 Apr 2006 21:25:57 +0000 (-0700) Subject: Merge branch 'nh/http' into next X-Git-Tag: v1.3.0-rc4~38 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=806d097e6b1c2c996a2a01cf8eaf3d7326e70c3c;hp=459a21bd35675e140e19569e8b5c62c7fc4eee5b;p=git.git Merge branch 'nh/http' into next * nh/http: Fix compile with expat, but an old curl version --- diff --git a/.gitignore b/.gitignore index 75891c39..b5959d63 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ git-checkout git-checkout-index git-cherry git-cherry-pick +git-clean git-clone git-clone-pack git-commit diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 2a0275ee..ec6811c7 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -69,6 +69,10 @@ changeset, not just the files that contain the change in . +--pickaxe-regex:: + Make the not a plain string but an extended POSIX + regex to match. + -O:: Output the patch in the order specified in the , which has one shell glob pattern per line. diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt new file mode 100644 index 00000000..36890c54 --- /dev/null +++ b/Documentation/git-clean.txt @@ -0,0 +1,50 @@ +git-clean(1) +============ + +NAME +---- +git-clean - Remove untracked files from the working tree + +SYNOPSIS +-------- +[verse] +'git-clean' [-d] [-n] [-q] [-x | -X] + +DESCRIPTION +----------- +Removes files unknown to git. This allows to clean the working tree +from files that are not under version control. If the '-x' option is +specified, ignored files are also removed, allowing to remove all +build products. + +OPTIONS +------- +-d:: + Remove untracked directories in addition to untracked files. + +-n:: + Don't actually remove anything, just show what would be done. + +-q:: + Be quiet, only report errors, but not the files that are + successfully removed. + +-x:: + Don't use the ignore rules. This allows removing all untracked + files, including build products. This can be used (possibly in + conjunction with gitlink:git-reset[1]) to create a pristine + working directory to test a clean build. + +-X:: + Remove only files ignored by git. This may be useful to rebuild + everything from scratch, but keep manually created files. + + +Author +------ +Written by Pavel Roskin + + +GIT +--- +Part of the gitlink:git[7] suite diff --git a/Makefile b/Makefile index 16415199..6b10eaa4 100644 --- a/Makefile +++ b/Makefile @@ -114,7 +114,7 @@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__ SCRIPT_SH = \ git-add.sh git-bisect.sh git-branch.sh git-checkout.sh \ - git-cherry.sh git-clone.sh git-commit.sh \ + git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \ git-count-objects.sh git-diff.sh git-fetch.sh \ git-format-patch.sh git-log.sh git-ls-remote.sh \ git-merge-one-file.sh git-parse-remote.sh \ @@ -208,7 +208,7 @@ LIB_OBJS = \ quote.o read-cache.o refs.o run-command.o \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ tag.o tree.o usage.o config.o environment.o ctype.o copy.o \ - fetch-clone.o revision.o pager.o tree-walk.o \ + fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \ $(DIFF_OBJS) GITLIBS = $(LIB_FILE) $(XDIFF_LIB) diff --git a/combine-diff.c b/combine-diff.c index 7693884f..4657eb4c 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -4,6 +4,7 @@ #include "diff.h" #include "diffcore.h" #include "quote.h" +#include "xdiff-interface.h" static int uninteresting(struct diff_filepair *p) { @@ -110,78 +111,9 @@ static char *grab_blob(const unsigned char *sha1, unsigned long *size) return blob; } -#define TMPPATHLEN 50 -#define MAXLINELEN 10240 - -static void write_to_temp_file(char *tmpfile, void *blob, unsigned long size) -{ - int fd = git_mkstemp(tmpfile, TMPPATHLEN, ".diff_XXXXXX"); - if (fd < 0) - die("unable to create temp-file"); - if (write(fd, blob, size) != size) - die("unable to write temp-file"); - close(fd); -} - -static void write_temp_blob(char *tmpfile, const unsigned char *sha1) -{ - unsigned long size; - void *blob; - blob = grab_blob(sha1, &size); - write_to_temp_file(tmpfile, blob, size); - free(blob); -} - -static int parse_num(char **cp_p, unsigned int *num_p) -{ - char *cp = *cp_p; - unsigned int num = 0; - int read_some; - - while ('0' <= *cp && *cp <= '9') - num = num * 10 + *cp++ - '0'; - if (!(read_some = cp - *cp_p)) - return -1; - *cp_p = cp; - *num_p = num; - return 0; -} - -static int parse_hunk_header(char *line, int len, - unsigned int *ob, unsigned int *on, - unsigned int *nb, unsigned int *nn) -{ - char *cp; - cp = line + 4; - if (parse_num(&cp, ob)) { - bad_line: - return error("malformed diff output: %s", line); - } - if (*cp == ',') { - cp++; - if (parse_num(&cp, on)) - goto bad_line; - } - else - *on = 1; - if (*cp++ != ' ' || *cp++ != '+') - goto bad_line; - if (parse_num(&cp, nb)) - goto bad_line; - if (*cp == ',') { - cp++; - if (parse_num(&cp, nn)) - goto bad_line; - } - else - *nn = 1; - return -!!memcmp(cp, " @@", 3); -} - -static void append_lost(struct sline *sline, int n, const char *line) +static void append_lost(struct sline *sline, int n, const char *line, int len) { struct lline *lline; - int len = strlen(line); unsigned long this_mask = (1UL<lost_tail = &lline->next; } -static void combine_diff(const unsigned char *parent, const char *ourtmp, +struct combine_diff_state { + struct xdiff_emit_state xm; + + unsigned int lno, ob, on, nb, nn; + unsigned long nmask; + int num_parent; + int n; + struct sline *sline; + struct sline *lost_bucket; +}; + +static void consume_line(void *state_, char *line, unsigned long len) +{ + struct combine_diff_state *state = state_; + if (5 < len && !memcmp("@@ -", line, 4)) { + if (parse_hunk_header(line, len, + &state->ob, &state->on, + &state->nb, &state->nn)) + return; + state->lno = state->nb; + if (!state->nb) + /* @@ -1,2 +0,0 @@ to remove the + * first two lines... + */ + state->nb = 1; + if (state->nn == 0) + /* @@ -X,Y +N,0 @@ removed Y lines + * that would have come *after* line N + * in the result. Our lost buckets hang + * to the line after the removed lines, + */ + state->lost_bucket = &state->sline[state->nb]; + else + state->lost_bucket = &state->sline[state->nb-1]; + if (!state->sline[state->nb-1].p_lno) + state->sline[state->nb-1].p_lno = + xcalloc(state->num_parent, + sizeof(unsigned long)); + state->sline[state->nb-1].p_lno[state->n] = state->ob; + return; + } + if (!state->lost_bucket) + return; /* not in any hunk yet */ + switch (line[0]) { + case '-': + append_lost(state->lost_bucket, state->n, line+1, len-1); + break; + case '+': + state->sline[state->lno-1].flag |= state->nmask; + state->lno++; + break; + } +} + +static void combine_diff(const unsigned char *parent, mmfile_t *result_file, struct sline *sline, int cnt, int n, int num_parent) { - FILE *in; - char parent_tmp[TMPPATHLEN]; - char cmd[TMPPATHLEN * 2 + 1024]; - char line[MAXLINELEN]; - unsigned int lno, ob, on, nb, nn, p_lno; + unsigned int p_lno, lno; unsigned long nmask = (1UL << n); - struct sline *lost_bucket = NULL; + xpparam_t xpp; + xdemitconf_t xecfg; + mmfile_t parent_file; + xdemitcb_t ecb; + struct combine_diff_state state; + unsigned long sz; if (!cnt) return; /* result deleted */ - write_temp_blob(parent_tmp, parent); - sprintf(cmd, "diff --unified=0 -La/x -Lb/x '%s' '%s'", - parent_tmp, ourtmp); - in = popen(cmd, "r"); - if (!in) - die("cannot spawn %s", cmd); - - lno = 1; - while (fgets(line, sizeof(line), in) != NULL) { - int len = strlen(line); - if (5 < len && !memcmp("@@ -", line, 4)) { - if (parse_hunk_header(line, len, - &ob, &on, &nb, &nn)) - break; - lno = nb; - if (!nb) - /* @@ -1,2 +0,0 @@ to remove the - * first two lines... - */ - nb = 1; - if (nn == 0) - /* @@ -X,Y +N,0 @@ removed Y lines - * that would have come *after* line N - * in the result. Our lost buckets hang - * to the line after the removed lines, - */ - lost_bucket = &sline[nb]; - else - lost_bucket = &sline[nb-1]; - if (!sline[nb-1].p_lno) - sline[nb-1].p_lno = - xcalloc(num_parent, - sizeof(unsigned long)); - sline[nb-1].p_lno[n] = ob; - continue; - } - if (!lost_bucket) - continue; /* not in any hunk yet */ - switch (line[0]) { - case '-': - append_lost(lost_bucket, n, line+1); - break; - case '+': - sline[lno-1].flag |= nmask; - lno++; - break; - } - } - fclose(in); - unlink(parent_tmp); + parent_file.ptr = grab_blob(parent, &sz); + parent_file.size = sz; + xpp.flags = XDF_NEED_MINIMAL; + xecfg.ctxlen = 0; + xecfg.flags = 0; + ecb.outf = xdiff_outf; + ecb.priv = &state; + memset(&state, 0, sizeof(state)); + state.xm.consume = consume_line; + state.nmask = nmask; + state.sline = sline; + state.lno = 1; + state.num_parent = num_parent; + state.n = n; + + xdl_diff(&parent_file, result_file, &xpp, &xecfg, &ecb); + free(parent_file.ptr); /* Assign line numbers for this parent. * @@ -625,61 +579,56 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, int dense, const char *header, struct diff_options *opt) { - unsigned long size, cnt, lno; + unsigned long result_size, cnt, lno; char *result, *cp, *ep; struct sline *sline; /* survived lines */ int mode_differs = 0; int i, show_hunks, shown_header = 0; - char ourtmp_buf[TMPPATHLEN]; - char *ourtmp = ourtmp_buf; int working_tree_file = !memcmp(elem->sha1, null_sha1, 20); int abbrev = opt->full_index ? 40 : DEFAULT_ABBREV; + mmfile_t result_file; /* Read the result of merge first */ - if (!working_tree_file) { - result = grab_blob(elem->sha1, &size); - write_to_temp_file(ourtmp, result, size); - } + if (!working_tree_file) + result = grab_blob(elem->sha1, &result_size); else { /* Used by diff-tree to read from the working tree */ struct stat st; int fd; - ourtmp = elem->path; - if (0 <= (fd = open(ourtmp, O_RDONLY)) && + if (0 <= (fd = open(elem->path, O_RDONLY)) && !fstat(fd, &st)) { int len = st.st_size; int cnt = 0; elem->mode = canon_mode(st.st_mode); - size = len; + result_size = len; result = xmalloc(len + 1); while (cnt < len) { int done = xread(fd, result+cnt, len-cnt); if (done == 0) break; if (done < 0) - die("read error '%s'", ourtmp); + die("read error '%s'", elem->path); cnt += done; } result[len] = 0; } else { /* deleted file */ - size = 0; + result_size = 0; elem->mode = 0; result = xmalloc(1); result[0] = 0; - ourtmp = "/dev/null"; } if (0 <= fd) close(fd); } - for (cnt = 0, cp = result; cp - result < size; cp++) { + for (cnt = 0, cp = result; cp - result < result_size; cp++) { if (*cp == '\n') cnt++; } - if (size && result[size-1] != '\n') + if (result_size && result[result_size-1] != '\n') cnt++; /* incomplete line */ sline = xcalloc(cnt+1, sizeof(*sline)); @@ -689,7 +638,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, sline[lno].lost_tail = &sline[lno].lost_head; sline[lno].flag = 0; } - for (lno = 0, cp = result; cp - result < size; cp++) { + for (lno = 0, cp = result; cp - result < result_size; cp++) { if (*cp == '\n') { sline[lno].len = cp - sline[lno].bol; lno++; @@ -697,8 +646,11 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, sline[lno].bol = cp + 1; } } - if (size && result[size-1] != '\n') - sline[cnt-1].len = size - (sline[cnt-1].bol - result); + if (result_size && result[result_size-1] != '\n') + sline[cnt-1].len = result_size - (sline[cnt-1].bol - result); + + result_file.ptr = result; + result_file.size = result_size; sline[0].p_lno = xcalloc((cnt+1) * num_parent, sizeof(unsigned long)); for (lno = 0; lno < cnt; lno++) @@ -714,7 +666,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, } } if (i <= j) - combine_diff(elem->parent[i].sha1, ourtmp, sline, + combine_diff(elem->parent[i].sha1, &result_file, sline, cnt, i, num_parent); if (elem->parent[i].mode != elem->mode) mode_differs = 1; @@ -767,8 +719,6 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, } dump_sline(sline, cnt, num_parent); } - if (ourtmp == ourtmp_buf) - unlink(ourtmp); free(result); for (i = 0; i < cnt; i++) { diff --git a/date.c b/date.c index 1c1917b4..376d25d2 100644 --- a/date.c +++ b/date.c @@ -255,10 +255,10 @@ static int match_multi_number(unsigned long num, char c, const char *date, char break; } /* mm/dd/yy ? */ - if (is_date(num3, num2, num, tm)) + if (is_date(num3, num, num2, tm)) break; /* dd/mm/yy ? */ - if (is_date(num3, num, num2, tm)) + if (is_date(num3, num2, num, tm)) break; return 0; } diff --git a/diff.c b/diff.c index e496905b..ce98a908 100644 --- a/diff.c +++ b/diff.c @@ -883,6 +883,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) options->filter = arg + 14; else if (!strcmp(arg, "--pickaxe-all")) options->pickaxe_opts = DIFF_PICKAXE_ALL; + else if (!strcmp(arg, "--pickaxe-regex")) + options->pickaxe_opts = DIFF_PICKAXE_REGEX; else if (!strncmp(arg, "-B", 2)) { if ((options->break_opt = diff_scoreopt_parse(arg)) == -1) @@ -1280,28 +1282,34 @@ void diff_flush(struct diff_options *options) for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; - if ((diff_output_format == DIFF_FORMAT_NO_OUTPUT) || - (p->status == DIFF_STATUS_UNKNOWN)) - continue; - if (p->status == 0) - die("internal error in diff-resolve-rename-copy"); - switch (diff_output_format) { - case DIFF_FORMAT_PATCH: - diff_flush_patch(p, options); - break; - case DIFF_FORMAT_RAW: - case DIFF_FORMAT_NAME_STATUS: - diff_flush_raw(p, line_termination, - inter_name_termination, - options); + + switch (p->status) { + case DIFF_STATUS_UNKNOWN: break; - case DIFF_FORMAT_NAME: - diff_flush_name(p, - inter_name_termination, - line_termination); + case 0: + die("internal error in diff-resolve-rename-copy"); break; + default: + switch (diff_output_format) { + case DIFF_FORMAT_PATCH: + diff_flush_patch(p, options); + break; + case DIFF_FORMAT_RAW: + case DIFF_FORMAT_NAME_STATUS: + diff_flush_raw(p, line_termination, + inter_name_termination, + options); + break; + case DIFF_FORMAT_NAME: + diff_flush_name(p, + inter_name_termination, + line_termination); + break; + case DIFF_FORMAT_NO_OUTPUT: + break; + } } - diff_free_filepair(q->queue[i]); + diff_free_filepair(p); } free(q->queue); q->queue = NULL; diff --git a/diff.h b/diff.h index a268d16f..0cebec11 100644 --- a/diff.h +++ b/diff.h @@ -102,6 +102,7 @@ extern int diff_setup_done(struct diff_options *); #define DIFF_DETECT_COPY 2 #define DIFF_PICKAXE_ALL 1 +#define DIFF_PICKAXE_REGEX 2 extern void diffcore_std(struct diff_options *); diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index 50e46ab8..cfcce315 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -5,8 +5,11 @@ #include "diff.h" #include "diffcore.h" +#include + static unsigned int contains(struct diff_filespec *one, - const char *needle, unsigned long len) + const char *needle, unsigned long len, + regex_t *regexp) { unsigned int cnt; unsigned long offset, sz; @@ -18,15 +21,28 @@ static unsigned int contains(struct diff_filespec *one, data = one->data; cnt = 0; - /* Yes, I've heard of strstr(), but the thing is *data may - * not be NUL terminated. Sue me. - */ - for (offset = 0; offset + len <= sz; offset++) { - /* we count non-overlapping occurrences of needle */ - if (!memcmp(needle, data + offset, len)) { - offset += len - 1; + if (regexp) { + regmatch_t regmatch; + int flags = 0; + + while (*data && !regexec(regexp, data, 1, ®match, flags)) { + flags |= REG_NOTBOL; + data += regmatch.rm_so; + if (*data) data++; cnt++; } + + } else { /* Classic exact string match */ + /* Yes, I've heard of strstr(), but the thing is *data may + * not be NUL terminated. Sue me. + */ + for (offset = 0; offset + len <= sz; offset++) { + /* we count non-overlapping occurrences of needle */ + if (!memcmp(needle, data + offset, len)) { + offset += len - 1; + cnt++; + } + } } return cnt; } @@ -36,10 +52,24 @@ void diffcore_pickaxe(const char *needle, int opts) struct diff_queue_struct *q = &diff_queued_diff; unsigned long len = strlen(needle); int i, has_changes; + regex_t regex, *regexp = NULL; struct diff_queue_struct outq; outq.queue = NULL; outq.nr = outq.alloc = 0; + if (opts & DIFF_PICKAXE_REGEX) { + int err; + err = regcomp(®ex, needle, REG_EXTENDED | REG_NEWLINE); + if (err) { + /* The POSIX.2 people are surely sick */ + char errbuf[1024]; + regerror(err, ®ex, errbuf, 1024); + regfree(®ex); + die("invalid pickaxe regex: %s", errbuf); + } + regexp = ®ex; + } + if (opts & DIFF_PICKAXE_ALL) { /* Showing the whole changeset if needle exists */ for (i = has_changes = 0; !has_changes && i < q->nr; i++) { @@ -48,16 +78,16 @@ void diffcore_pickaxe(const char *needle, int opts) if (!DIFF_FILE_VALID(p->two)) continue; /* ignore unmerged */ /* created */ - if (contains(p->two, needle, len)) + if (contains(p->two, needle, len, regexp)) has_changes++; } else if (!DIFF_FILE_VALID(p->two)) { - if (contains(p->one, needle, len)) + if (contains(p->one, needle, len, regexp)) has_changes++; } else if (!diff_unmodified_pair(p) && - contains(p->one, needle, len) != - contains(p->two, needle, len)) + contains(p->one, needle, len, regexp) != + contains(p->two, needle, len, regexp)) has_changes++; } if (has_changes) @@ -80,16 +110,16 @@ void diffcore_pickaxe(const char *needle, int opts) if (!DIFF_FILE_VALID(p->two)) ; /* ignore unmerged */ /* created */ - else if (contains(p->two, needle, len)) + else if (contains(p->two, needle, len, regexp)) has_changes = 1; } else if (!DIFF_FILE_VALID(p->two)) { - if (contains(p->one, needle, len)) + if (contains(p->one, needle, len, regexp)) has_changes = 1; } else if (!diff_unmodified_pair(p) && - contains(p->one, needle, len) != - contains(p->two, needle, len)) + contains(p->one, needle, len, regexp) != + contains(p->two, needle, len, regexp)) has_changes = 1; if (has_changes) @@ -98,6 +128,10 @@ void diffcore_pickaxe(const char *needle, int opts) diff_free_filepair(p); } + if (opts & DIFF_PICKAXE_REGEX) { + regfree(®ex); + } + free(q->queue); *q = outq; return; diff --git a/git-clean.sh b/git-clean.sh new file mode 100755 index 00000000..b200868e --- /dev/null +++ b/git-clean.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# +# Copyright (c) 2005-2006 Pavel Roskin +# + +USAGE="[-d] [-n] [-q] [-x | -X]" +LONG_USAGE='Clean untracked files from the working directory + -d remove directories as well + -n don'\''t remove anything, just show what would be done + -q be quiet, only report errors + -x remove ignored files as well + -X remove only ignored files as well' +SUBDIRECTORY_OK=Yes +. git-sh-setup + +ignored= +ignoredonly= +cleandir= +quiet= +rmf="rm -f" +rmrf="rm -rf" +rm_refuse="echo Not removing" +echo1="echo" + +while case "$#" in 0) break ;; esac +do + case "$1" in + -d) + cleandir=1 + ;; + -n) + quiet=1 + rmf="echo Would remove" + rmrf="echo Would remove" + rm_refuse="echo Would not remove" + echo1=":" + ;; + -q) + quiet=1 + ;; + -x) + ignored=1 + ;; + -X) + ignoredonly=1 + ;; + *) + usage + esac + shift +done + +case "$ignored,$ignoredonly" in + 1,1) usage;; +esac + +if [ -z "$ignored" ]; then + excl="--exclude-per-directory=.gitignore" + if [ -f "$GIT_DIR/info/exclude" ]; then + excl_info="--exclude-from=$GIT_DIR/info/exclude" + fi + if [ "$ignoredonly" ]; then + excl="$excl --ignored" + fi +fi + +git-ls-files --others --directory $excl ${excl_info:+"$excl_info"} | +while read -r file; do + if [ -d "$file" -a ! -L "$file" ]; then + if [ -z "$cleandir" ]; then + $rm_refuse "$file" + continue + fi + $echo1 "Removing $file" + $rmrf "$file" + else + $echo1 "Removing $file" + $rmf "$file" + fi +done diff --git a/git-clone.sh b/git-clone.sh index 823c74b9..c013e481 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -52,7 +52,8 @@ Perhaps git-update-server-info needs to be run there?" git-http-fetch -v -a -w "$tname" "$name" "$1/" || exit 1 done <"$clone_tmp/refs" rm -fr "$clone_tmp" - http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" + http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" || + rm -f "$GIT_DIR/REMOTE_HEAD" } # Read git-fetch-pack -k output and store the remote branches. @@ -324,7 +325,7 @@ test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp" if test -f "$GIT_DIR/CLONE_HEAD" then - # Figure out where the remote HEAD points at. + # Read git-fetch-pack -k output and store the remote branches. perl -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin" fi @@ -332,22 +333,25 @@ cd "$D" || exit if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD" then - head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"` # Figure out which remote branch HEAD points at. case "$use_separate_remote" in '') remote_top=refs/heads ;; *) remote_top="refs/remotes/$origin" ;; esac - # What to use to track the remote primary branch - if test -n "$use_separate_remote" - then - origin_tracking="remotes/$origin/master" - else - origin_tracking="heads/$origin" - fi + head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"` + case "$head_sha1" in + 'ref: refs/'*) + # Uh-oh, the remote told us (http transport done against + # new style repository with a symref HEAD). + # Ideally we should skip the guesswork but for now + # opt for minimum change. + head_sha1=`expr "$head_sha1" : 'ref: refs/heads/\(.*\)'` + head_sha1=`cat "$GIT_DIR/$remote_top/$head_sha1"` + ;; + esac - # The name under $remote_top the remote HEAD seems to point at + # The name under $remote_top the remote HEAD seems to point at. head_points_at=$( ( echo "master" @@ -368,23 +372,28 @@ then ) ) - # Write out remotes/$origin file. + # Write out remotes/$origin file, and update our "$head_points_at". case "$head_points_at" in ?*) mkdir -p "$GIT_DIR/remotes" && - echo >"$GIT_DIR/remotes/$origin" \ - "URL: $repo -Pull: refs/heads/$head_points_at:refs/$origin_tracking" && + git-symbolic-ref HEAD "refs/heads/$head_points_at" && case "$use_separate_remote" in - t) git-update-ref HEAD "$head_sha1" ;; - *) git-update-ref "refs/heads/$origin" $(git-rev-parse HEAD) ;; + t) origin_track="$remote_top/$head_points_at" + git-update-ref HEAD "$head_sha1" ;; + *) origin_track="$remote_top/$origin" + git-update-ref "refs/heads/$origin" "$head_sha1" ;; esac && + echo >"$GIT_DIR/remotes/$origin" \ + "URL: $repo +Pull: refs/heads/$head_points_at:$origin_track" && (cd "$GIT_DIR/$remote_top" && find . -type f -print) | while read dotslref do name=`expr "$dotslref" : './\(.*\)'` && - test "$head_points_at" = "$name" || - test "$origin" = "$name" || + test "$use_separate_remote" = '' && { + test "$head_points_at" = "$name" || + test "$origin" = "$name" + } || echo "Pull: refs/heads/${name}:$remote_top/${name}" done >>"$GIT_DIR/remotes/$origin" && case "$use_separate_remote" in diff --git a/xdiff-interface.c b/xdiff-interface.c new file mode 100644 index 00000000..f7d6f988 --- /dev/null +++ b/xdiff-interface.c @@ -0,0 +1,104 @@ +#include "cache.h" +#include "xdiff-interface.h" + +static int parse_num(char **cp_p, unsigned int *num_p) +{ + char *cp = *cp_p; + unsigned int num = 0; + int read_some; + + while ('0' <= *cp && *cp <= '9') + num = num * 10 + *cp++ - '0'; + if (!(read_some = cp - *cp_p)) + return -1; + *cp_p = cp; + *num_p = num; + return 0; +} + +int parse_hunk_header(char *line, int len, + unsigned int *ob, unsigned int *on, + unsigned int *nb, unsigned int *nn) +{ + char *cp; + cp = line + 4; + if (parse_num(&cp, ob)) { + bad_line: + return error("malformed diff output: %s", line); + } + if (*cp == ',') { + cp++; + if (parse_num(&cp, on)) + goto bad_line; + } + else + *on = 1; + if (*cp++ != ' ' || *cp++ != '+') + goto bad_line; + if (parse_num(&cp, nb)) + goto bad_line; + if (*cp == ',') { + cp++; + if (parse_num(&cp, nn)) + goto bad_line; + } + else + *nn = 1; + return -!!memcmp(cp, " @@", 3); +} + +static void consume_one(void *priv_, char *s, unsigned long size) +{ + struct xdiff_emit_state *priv = priv_; + char *ep; + while (size) { + unsigned long this_size; + ep = memchr(s, '\n', size); + this_size = (ep == NULL) ? size : (ep - s + 1); + priv->consume(priv, s, this_size); + size -= this_size; + s += this_size; + } +} + +int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf) +{ + struct xdiff_emit_state *priv = priv_; + int i; + + for (i = 0; i < nbuf; i++) { + if (mb[i].ptr[mb[i].size-1] != '\n') { + /* Incomplete line */ + priv->remainder = realloc(priv->remainder, + priv->remainder_size + + mb[i].size); + memcpy(priv->remainder + priv->remainder_size, + mb[i].ptr, mb[i].size); + priv->remainder_size += mb[i].size; + continue; + } + + /* we have a complete line */ + if (!priv->remainder) { + consume_one(priv, mb[i].ptr, mb[i].size); + continue; + } + priv->remainder = realloc(priv->remainder, + priv->remainder_size + + mb[i].size); + memcpy(priv->remainder + priv->remainder_size, + mb[i].ptr, mb[i].size); + consume_one(priv, priv->remainder, + priv->remainder_size + mb[i].size); + free(priv->remainder); + priv->remainder = NULL; + priv->remainder_size = 0; + } + if (priv->remainder) { + consume_one(priv, priv->remainder, priv->remainder_size); + free(priv->remainder); + priv->remainder = NULL; + priv->remainder_size = 0; + } + return 0; +} diff --git a/xdiff-interface.h b/xdiff-interface.h new file mode 100644 index 00000000..ec682a29 --- /dev/null +++ b/xdiff-interface.h @@ -0,0 +1,21 @@ +#ifndef XDIFF_INTERFACE_H +#define XDIFF_INTERFACE_H + +#include "xdiff/xdiff.h" + +struct xdiff_emit_state; + +typedef void (*xdiff_emit_consume_fn)(void *, char *, unsigned long); + +struct xdiff_emit_state { + xdiff_emit_consume_fn consume; + char *remainder; + unsigned long remainder_size; +}; + +int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf); +int parse_hunk_header(char *line, int len, + unsigned int *ob, unsigned int *on, + unsigned int *nb, unsigned int *nn); + +#endif