From patchwork Fri Sep 21 15:57:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10610571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEA6D5A4 for ; Fri, 21 Sep 2018 15:58:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCBEB2CB08 for ; Fri, 21 Sep 2018 15:58:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0EEA2E076; Fri, 21 Sep 2018 15:58:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38EC62CB08 for ; Fri, 21 Sep 2018 15:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390644AbeIUVrm (ORCPT ); Fri, 21 Sep 2018 17:47:42 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:39208 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390633AbeIUVrk (ORCPT ); Fri, 21 Sep 2018 17:47:40 -0400 Received: by mail-lf1-f68.google.com with SMTP id v77-v6so11878456lfa.6 for ; Fri, 21 Sep 2018 08:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DJLTvTUqdFrbFY2rEP8oWG6kJYle2HBisEysl/u1GHQ=; b=s2R8DMSV0wmuMgLnUmmLKEpVNARdPXxUSpULRz/dfHnNEwVxMRmB2lK5+M+E2z+wBy 9uCcDqe1RewUHWkBCS5TeG1JB1VAz/hZBW2m8qSuO+WTaz9gRHIqxZndXvhaQxEOnZrO aamSK54Xn6//8rK8YtYlik6CCioYf4xU8VriGxz5piLrsIma947wGuCr4/n5OJatKd6B kUkx5oG3yH2iI1vKHp3ui0circBnn3KILNxYmeZhJ7AnHRfvBCVPGyNGLxfzbMIbXAwd gkyghk7eL6x0lZHsJn0kqaShPnGGJ9PbCZhZMkRmrZeLLpqPa/8gYPe9XHBjs+NQVRoS HCPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DJLTvTUqdFrbFY2rEP8oWG6kJYle2HBisEysl/u1GHQ=; b=ePKKJ2pONbLoRBqLIvEsAXkAnNgC2QehxboonH4HJK5bfkDuUX4f30vJz2YJycfh2s HlEBZryuCJmVTmeLzPcpxsp60KzQUybrFQWlwunJCR094OPopr2wh0Ed8JRsPX9tEmWx cSLSlNoEviPBv9WxxasdraR3EsA6i+2QtX4CltkyiIofMCKmUiCQshnRAMZ5vIiqTUgQ SEBpBqciGgkicJx3RB1cBEebvOmqNMzSdZGpN3kgUKkfFpRmI35uFz1RhplFEG0Tn6sY w6znJMJ5V503hiew2tXi8/s7BTdnGaz9+nvXF8+RkefAgktuwzHj0ja1mccaQMZRTwaB aqKA== X-Gm-Message-State: APzg51AIZFWN5IfCMkWZUqNA4ZsjLUFzEmEMyYFNiuaYAV3g+PMSi/CJ TvW96bhA8dGHvgp7fG8cVyk= X-Google-Smtp-Source: ANB0VdZ6KZg/hHkm4xeGgR7Hqw32W7lXJ4nWejwwQM2HZaflbYyePDJ+ciYwa1bxaD4nL12jjGfPSA== X-Received: by 2002:a19:ed06:: with SMTP id y6-v6mr2114844lfy.65.1537545488448; Fri, 21 Sep 2018 08:58:08 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id o19-v6sm2192978lfk.30.2018.09.21.08.58.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 08:58:07 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, sbeller@google.com Subject: [PATCH v5 18/23] line-range.c: remove implicit dependency on the_index Date: Fri, 21 Sep 2018 17:57:34 +0200 Message-Id: <20180921155739.14407-19-pclouds@gmail.com> X-Mailer: git-send-email 2.19.0.640.gcd3aa10a8a In-Reply-To: <20180921155739.14407-1-pclouds@gmail.com> References: <20180915161759.8272-1-pclouds@gmail.com> <20180921155739.14407-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/blame.c | 2 +- line-log.c | 4 ++-- line-range.c | 22 ++++++++++++++-------- line-range.h | 6 ++++-- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index c2da673ac8..97632828db 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1001,7 +1001,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) long bottom, top; if (parse_range_arg(range_list.items[range_i].string, nth_line_cb, &sb, lno, anchor, - &bottom, &top, sb.path)) + &bottom, &top, sb.path, &the_index)) usage(blame_usage); if ((!lno && (top || bottom)) || lno < bottom) die(Q_("file %s has only %lu line", diff --git a/line-log.c b/line-log.c index 35adf199a5..d1d429d738 100644 --- a/line-log.c +++ b/line-log.c @@ -574,7 +574,7 @@ parse_lines(struct repository *r, struct commit *commit, long begin = 0, end = 0; long anchor; - name_part = skip_range_arg(item->string); + name_part = skip_range_arg(item->string, r->index); if (!name_part || *name_part != ':' || !name_part[1]) die("-L argument not 'start,end:file' or ':funcname:file': %s", item->string); @@ -599,7 +599,7 @@ parse_lines(struct repository *r, struct commit *commit, if (parse_range_arg(range_part, nth_line, &cb_data, lines, anchor, &begin, &end, - full_name)) + full_name, r->index)) die("malformed -L argument '%s'", range_part); if ((!lines && (begin || end)) || lines < begin) die("file %s has only %lu lines", name_part, lines); diff --git a/line-range.c b/line-range.c index 7fa0d8bba5..9b50583dc0 100644 --- a/line-range.c +++ b/line-range.c @@ -163,9 +163,10 @@ static const char *find_funcname_matching_regexp(xdemitconf_t *xecfg, const char } } -static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_cb, - void *cb_data, long lines, long anchor, long *begin, long *end, - const char *path) +static const char *parse_range_funcname( + const char *arg, nth_line_fn_t nth_line_cb, + void *cb_data, long lines, long anchor, long *begin, long *end, + const char *path, struct index_state *istate) { char *pattern; const char *term; @@ -198,7 +199,7 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_ anchor--; /* input is in human terms */ start = nth_line_cb(cb_data, anchor); - drv = userdiff_find_by_path(&the_index, path); + drv = userdiff_find_by_path(istate, path); if (drv && drv->funcname.pattern) { const struct userdiff_funcname *pe = &drv->funcname; xecfg = xcalloc(1, sizeof(*xecfg)); @@ -244,7 +245,8 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb, void *cb_data, long lines, long anchor, - long *begin, long *end, const char *path) + long *begin, long *end, + const char *path, struct index_state *istate) { *begin = *end = 0; @@ -254,7 +256,9 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb, anchor = lines + 1; if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':')) { - arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, anchor, begin, end, path); + arg = parse_range_funcname(arg, nth_line_cb, cb_data, + lines, anchor, begin, end, + path, istate); if (!arg || *arg) return -1; return 0; @@ -275,10 +279,12 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb, return 0; } -const char *skip_range_arg(const char *arg) +const char *skip_range_arg(const char *arg, struct index_state *istate) { if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':')) - return parse_range_funcname(arg, NULL, NULL, 0, 0, NULL, NULL, NULL); + return parse_range_funcname(arg, NULL, NULL, + 0, 0, NULL, NULL, + NULL, istate); arg = parse_loc(arg, NULL, NULL, 0, -1, NULL); diff --git a/line-range.h b/line-range.h index d3c54e45aa..e69bf7c017 100644 --- a/line-range.h +++ b/line-range.h @@ -1,6 +1,8 @@ #ifndef LINE_RANGE_H #define LINE_RANGE_H +struct index_state; + /* * Parse one item in an -L begin,end option w.r.t. the notional file * object 'cb_data' consisting of 'lines' lines. @@ -23,7 +25,7 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb, void *cb_data, long lines, long anchor, long *begin, long *end, - const char *path); + const char *path, struct index_state *istate); /* * Scan past a range argument that could be parsed by @@ -34,6 +36,6 @@ int parse_range_arg(const char *arg, * NULL in case the argument is obviously malformed. */ -const char *skip_range_arg(const char *arg); +const char *skip_range_arg(const char *arg, struct index_state *istate); #endif /* LINE_RANGE_H */