From: Junio C Hamano Date: Tue, 28 Apr 2009 07:46:25 +0000 (-0700) Subject: Merge branch 'maint-1.6.1' into maint X-Git-Tag: v1.6.3-rc4~14^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/2254da06a5473ffde973337bad2c6a96eea61e20?ds=inline;hp=-c Merge branch 'maint-1.6.1' into maint * maint-1.6.1: grep: fix segfault when "git grep '('" is given Documentation: fix a grammatical error in api-builtin.txt builtin-merge: fix a typo in an error message --- 2254da06a5473ffde973337bad2c6a96eea61e20 diff --combined builtin-merge.c index 6d2160d0a3,2179e0686d..c339380cf3 --- a/builtin-merge.c +++ b/builtin-merge.c @@@ -36,8 -36,8 +36,8 @@@ struct strategy }; static const char * const builtin_merge_usage[] = { - "git-merge [options] ...", - "git-merge [options] HEAD ", + "git merge [options] ...", + "git merge [options] HEAD ", NULL }; @@@ -300,6 -300,35 +300,6 @@@ static void squash_message(void strbuf_release(&out); } -static int run_hook(const char *name) -{ - struct child_process hook; - const char *argv[3], *env[2]; - char index[PATH_MAX]; - - argv[0] = git_path("hooks/%s", name); - if (access(argv[0], X_OK) < 0) - return 0; - - snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", get_index_file()); - env[0] = index; - env[1] = NULL; - - if (squash) - argv[1] = "1"; - else - argv[1] = "0"; - argv[2] = NULL; - - memset(&hook, 0, sizeof(hook)); - hook.argv = argv; - hook.no_stdin = 1; - hook.stdout_to_stderr = 1; - hook.env = env; - - return run_command(&hook); -} - static void finish(const unsigned char *new_head, const char *msg) { struct strbuf reflog_message = STRBUF_INIT; @@@ -345,7 -374,7 +345,7 @@@ } /* Run a post-merge hook */ - run_hook("post-merge"); + run_hook(NULL, "post-merge", squash ? "1" : "0", NULL); strbuf_release(&reflog_message); } @@@ -356,14 -385,9 +356,14 @@@ static void merge_name(const char *remo struct object *remote_head; unsigned char branch_head[20], buf_sha[20]; struct strbuf buf = STRBUF_INIT; + struct strbuf bname = STRBUF_INIT; const char *ptr; int len, early; + len = strlen(remote); + if (interpret_nth_last_branch(remote, &bname) == len) + remote = bname.buf; + memset(branch_head, 0, sizeof(branch_head)); remote_head = peel_to_type(remote, 0, NULL, OBJ_COMMIT); if (!remote_head) @@@ -376,7 -400,7 +376,7 @@@ if (!hashcmp(remote_head->sha1, branch_head)) { strbuf_addf(msg, "%s\t\tbranch '%s' of .\n", sha1_to_hex(branch_head), remote); - return; + goto cleanup; } /* See if remote matches ^^^.. or ~ */ @@@ -416,8 -440,7 +416,8 @@@ sha1_to_hex(remote_head->sha1), truname.buf + 11, (early ? " (early part)" : "")); - return; + strbuf_release(&truname); + goto cleanup; } } @@@ -438,13 -461,10 +438,13 @@@ strbuf_remove(&line, ptr-line.buf+1, 13); strbuf_addbuf(msg, &line); strbuf_release(&line); - return; + goto cleanup; } strbuf_addf(msg, "%s\t\tcommit '%s'\n", sha1_to_hex(remote_head->sha1), remote); +cleanup: + strbuf_release(&buf); + strbuf_release(&bname); } static int git_merge_config(const char *k, const char *v, void *cb) @@@ -765,7 -785,7 +765,7 @@@ static int suggest_conflicts(void fp = fopen(git_path("MERGE_MSG"), "a"); if (!fp) - die("Could open %s for writing", git_path("MERGE_MSG")); + die("Could not open %s for writing", git_path("MERGE_MSG")); fprintf(fp, "\nConflicts:\n"); for (pos = 0; pos < active_nr; pos++) { struct cache_entry *ce = active_cache[pos]; diff --combined grep.c index 062b2b6f28,704facf996..b0d992a6e0 --- a/grep.c +++ b/grep.c @@@ -28,25 -28,9 +28,25 @@@ void append_grep_pattern(struct grep_op p->next = NULL; } +static int is_fixed(const char *s) +{ + while (*s && !is_regex_special(*s)) + s++; + return !*s; +} + static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) { - int err = regcomp(&p->regexp, p->pattern, opt->regflags); + int err; + + if (opt->fixed || is_fixed(p->pattern)) + p->fixed = 1; + if (opt->regflags & REG_ICASE) + p->fixed = 0; + if (p->fixed) + return; + + err = regcomp(&p->regexp, p->pattern, opt->regflags); if (err) { char errbuf[1024]; char where[1024]; @@@ -70,6 -54,8 +70,8 @@@ static struct grep_expr *compile_patter struct grep_expr *x; p = *list; + if (!p) + return NULL; switch (p->token) { case GREP_PATTERN: /* atom */ case GREP_PATTERN_HEAD: @@@ -82,8 -68,6 +84,6 @@@ case GREP_OPEN_PAREN: *list = p->next; x = compile_pattern_or(list); - if (!x) - return NULL; if (!*list || (*list)->token != GREP_CLOSE_PAREN) die("unmatched parenthesis"); *list = (*list)->next; @@@ -99,6 -83,8 +99,8 @@@ static struct grep_expr *compile_patter struct grep_expr *x; p = *list; + if (!p) + return NULL; switch (p->token) { case GREP_NOT: if (!p->next) @@@ -175,7 -161,8 +177,7 @@@ void compile_grep_patterns(struct grep_ case GREP_PATTERN: /* atom */ case GREP_PATTERN_HEAD: case GREP_PATTERN_BODY: - if (!opt->fixed) - compile_regexp(p, opt); + compile_regexp(p, opt); break; default: opt->extended = 1; @@@ -309,6 -296,7 +311,6 @@@ static struct static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol, char *eol, enum grep_context ctx) { int hit = 0; - int at_true_bol = 1; int saved_ch = 0; regmatch_t pmatch[10]; @@@ -329,7 -317,7 +331,7 @@@ } again: - if (!opt->fixed) { + if (!p->fixed) { regex_t *exp = &p->regexp; hit = !regexec(exp, bol, ARRAY_SIZE(pmatch), pmatch, 0); @@@ -351,7 -339,7 +353,7 @@@ * either end of the line, or at word boundary * (i.e. the next char must not be a word char). */ - if ( ((pmatch[0].rm_so == 0 && at_true_bol) || + if ( ((pmatch[0].rm_so == 0) || !word_char(bol[pmatch[0].rm_so-1])) && ((pmatch[0].rm_eo == (eol-bol)) || !word_char(bol[pmatch[0].rm_eo])) ) @@@ -363,14 -351,10 +365,14 @@@ /* There could be more than one match on the * line, and the first match might not be * strict word match. But later ones could be! + * Forward to the next possible start, i.e. the + * next position following a non-word char. */ bol = pmatch[0].rm_so + bol + 1; - at_true_bol = 0; - goto again; + while (word_char(bol[-1]) && bol < eol) + bol++; + if (bol < eol) + goto again; } } if (p->token == GREP_PATTERN_HEAD && saved_ch) @@@ -386,6 -370,8 +388,8 @@@ static int match_expr_eval(struct grep_ { int h = 0; + if (!x) + die("Not a valid grep expression"); switch (x->node) { case GREP_NODE_ATOM: h = match_one_pattern(o, x->u.atom, bol, eol, ctx); @@@ -413,7 -399,7 +417,7 @@@ h |= match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 1); break; default: - die("Unexpected node type (internal error) %d\n", x->node); + die("Unexpected node type (internal error) %d", x->node); } if (collect_hits) x->hit |= h;