From patchwork Tue Feb 12 22:27:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barret Rhoden X-Patchwork-Id: 10808865 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 A7248746 for ; Tue, 12 Feb 2019 22:27:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94F1B2C720 for ; Tue, 12 Feb 2019 22:27:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 874C82C725; Tue, 12 Feb 2019 22:27:34 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 E30C82C720 for ; Tue, 12 Feb 2019 22:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730768AbfBLW1c (ORCPT ); Tue, 12 Feb 2019 17:27:32 -0500 Received: from mail-qk1-f201.google.com ([209.85.222.201]:51067 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728584AbfBLW1b (ORCPT ); Tue, 12 Feb 2019 17:27:31 -0500 Received: by mail-qk1-f201.google.com with SMTP id x125so301845qka.17 for ; Tue, 12 Feb 2019 14:27:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=hEtMEUXdOKmOos88L8Z0fLTAykiOwtWjobx+9asYnSM=; b=fX3wgamf9OfUKifySYqMwpEK6tLNhoYb+2femcABH0QaS70QMblRp6YaEEdoFugQbl xW5ZPupdXcoavQnURs9QvV7YlLweEVDL+yAark8bzl/R+x0iwrjM9CtxpYggX/3VJlsJ r8QjHGI6tIMaOJ+bg8Lqu4E16GzMforgv5gPyRyM8eheos7sA7cSjPS/2mW1VxpbbgkY 8hhS3APJUmOClr/9O/dlATAdBnj0Z8WrvsVd0RMwBc8ujhpETQ/60lYjbPDhFrtId4X3 9s8xNb8sh5k3GhAj6E9X0HSjWza5HvYVHsahFHbAOBg/FkITCFNXIwHBMnfzLYkNZuZc 1MYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hEtMEUXdOKmOos88L8Z0fLTAykiOwtWjobx+9asYnSM=; b=WG+s6lpuI+aqnf+4nFAr2Yq+i74QUsoeYctxdBiwgikOtns+8z8qOzSPCW2JhGai/n jfXkKDx7tsnJlB/B9/MoxfGaWWVXL/YbPbYicUv9/PNsMJ+mZHDwfbUzmO+d+xwTxg97 A40a2gEKOiS9JXatFZg9juNlI86PCGTKZgd5Wgj0TpKeF2kMp+3st+SBhbzOpQGZNUFw /67c0VsTIqY1AdJIVeXRLPKtKthnHd1Q2hdszF0J8YN8wevjf/258/IKxz5VdLx2cxka QslweT/I+FN9EbbcddYQiiERNCi5BG9/CEiIO/JDRIZ1szbmhpMeQ23+wnNUYg2g8Abx adNQ== X-Gm-Message-State: AHQUAubGDLvDE7Xs0errgnLoiTExqRc71ilttNfbc99N0FZU655XyK0f GPHdEh7+SlvRVpwuJqZhPfPQUO8riFI2BnR2P1prjaiULr+jNUB4qR6KbMQalSUtTz/TAgntVbv h0s++Z/GlzDPODHHQWeAVkyiZuNyWmfPoqnOsSr3sXXpnc3VjFmnq X-Google-Smtp-Source: AHgI3IY3P3iryVBz1C01mGChtrJWkg/h/4Ym35SFpRNMpxNO/7FC1yC5NqRYIRF4r0wlERcU7eEMySpw X-Received: by 2002:a37:4989:: with SMTP id w131mr2216158qka.54.1550010450670; Tue, 12 Feb 2019 14:27:30 -0800 (PST) Date: Tue, 12 Feb 2019 17:27:18 -0500 In-Reply-To: <20190212222722.240676-1-brho@google.com> Message-Id: <20190212222722.240676-2-brho@google.com> Mime-Version: 1.0 References: <20190212222722.240676-1-brho@google.com> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog Subject: [PATCH v3 1/5] Move init_skiplist() outside of fsck From: Barret Rhoden To: git@vger.kernel.org Cc: " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , David Kastrup , Jeff King , Jeff Smith , Johannes Schindelin , Junio C Hamano , " =?utf-8?q?Ren=C3=A9_Scharfe?= " , Stefan Beller Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP init_skiplist() took a file consisting of SHA-1s and comments and added the objects to an oidset. This functionality is useful for other commands. Signed-off-by: Barret Rhoden --- fsck.c | 37 +-------------------------------- oidset.c | 35 +++++++++++++++++++++++++++++++ oidset.h | 8 +++++++ t/t5504-fetch-receive-strict.sh | 14 ++++++------- 4 files changed, 51 insertions(+), 43 deletions(-) diff --git a/fsck.c b/fsck.c index 2260adb71e7a..d45534ad90f5 100644 --- a/fsck.c +++ b/fsck.c @@ -181,41 +181,6 @@ static int fsck_msg_type(enum fsck_msg_id msg_id, return msg_type; } -static void init_skiplist(struct fsck_options *options, const char *path) -{ - FILE *fp; - struct strbuf sb = STRBUF_INIT; - struct object_id oid; - - fp = fopen(path, "r"); - if (!fp) - die("Could not open skip list: %s", path); - while (!strbuf_getline(&sb, fp)) { - const char *p; - const char *hash; - - /* - * Allow trailing comments, leading whitespace - * (including before commits), and empty or whitespace - * only lines. - */ - hash = strchr(sb.buf, '#'); - if (hash) - strbuf_setlen(&sb, hash - sb.buf); - strbuf_trim(&sb); - if (!sb.len) - continue; - - if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0') - die("Invalid SHA-1: %s", sb.buf); - oidset_insert(&options->skiplist, &oid); - } - if (ferror(fp)) - die_errno("Could not read '%s'", path); - fclose(fp); - strbuf_release(&sb); -} - static int parse_msg_type(const char *str) { if (!strcmp(str, "error")) @@ -284,7 +249,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) if (!strcmp(buf, "skiplist")) { if (equal == len) die("skiplist requires a path"); - init_skiplist(options, buf + equal + 1); + oidset_parse_file(&options->skiplist, buf + equal + 1); buf += len + 1; continue; } diff --git a/oidset.c b/oidset.c index fe4eb921df81..878a1b56af1c 100644 --- a/oidset.c +++ b/oidset.c @@ -35,3 +35,38 @@ void oidset_clear(struct oidset *set) kh_release_oid(&set->set); oidset_init(set, 0); } + +void oidset_parse_file(struct oidset *set, const char *path) +{ + FILE *fp; + struct strbuf sb = STRBUF_INIT; + struct object_id oid; + + fp = fopen(path, "r"); + if (!fp) + die("Could not open object name list: %s", path); + while (!strbuf_getline(&sb, fp)) { + const char *p; + const char *name; + + /* + * Allow trailing comments, leading whitespace + * (including before commits), and empty or whitespace + * only lines. + */ + name = strchr(sb.buf, '#'); + if (name) + strbuf_setlen(&sb, name - sb.buf); + strbuf_trim(&sb); + if (!sb.len) + continue; + + if (parse_oid_hex(sb.buf, &oid, &p) || *p != '\0') + die("Invalid object name: %s", sb.buf); + oidset_insert(set, &oid); + } + if (ferror(fp)) + die_errno("Could not read '%s'", path); + fclose(fp); + strbuf_release(&sb); +} diff --git a/oidset.h b/oidset.h index c9d0f6d3cc8b..c4807749df8d 100644 --- a/oidset.h +++ b/oidset.h @@ -73,6 +73,14 @@ int oidset_remove(struct oidset *set, const struct object_id *oid); */ void oidset_clear(struct oidset *set); +/** + * Add the contents of the file 'path' to an initialized oidset. Each line is + * an unabbreviated object name. Comments begin with '#', and trailing comments + * are allowed. Leading whitespace and empty or white-space only lines are + * ignored. + */ +void oidset_parse_file(struct oidset *set, const char *path); + struct oidset_iter { kh_oid_t *set; khiter_t iter; diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh index 7bc706873c5b..7184f1d07f90 100755 --- a/t/t5504-fetch-receive-strict.sh +++ b/t/t5504-fetch-receive-strict.sh @@ -164,9 +164,9 @@ test_expect_success 'fsck with unsorted skipList' ' test_expect_success 'fsck with invalid or bogus skipList input' ' git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck && test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err && - test_i18ngrep "Could not open skip list: does-not-exist" err && + test_i18ngrep "Could not open object name list: does-not-exist" err && test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err && - test_i18ngrep "Invalid SHA-1: \[core\]" err + test_i18ngrep "Invalid object name: \[core\]" err ' test_expect_success 'fsck with other accepted skipList input (comments & empty lines)' ' @@ -193,7 +193,7 @@ test_expect_success 'fsck no garbage output from comments & empty lines errors' test_expect_success 'fsck with invalid abbreviated skipList input' ' echo $commit | test_copy_bytes 20 >SKIP.abbreviated && test_must_fail git -c fsck.skipList=SKIP.abbreviated fsck 2>err-abbreviated && - test_i18ngrep "^fatal: Invalid SHA-1: " err-abbreviated + test_i18ngrep "^fatal: Invalid object name: " err-abbreviated ' test_expect_success 'fsck with exhaustive accepted skipList input (various types of comments etc.)' ' @@ -226,10 +226,10 @@ test_expect_success 'push with receive.fsck.skipList' ' test_must_fail git push --porcelain dst bogus && git --git-dir=dst/.git config receive.fsck.skipList does-not-exist && test_must_fail git push --porcelain dst bogus 2>err && - test_i18ngrep "Could not open skip list: does-not-exist" err && + test_i18ngrep "Could not open object name list: does-not-exist" err && git --git-dir=dst/.git config receive.fsck.skipList config && test_must_fail git push --porcelain dst bogus 2>err && - test_i18ngrep "Invalid SHA-1: \[core\]" err && + test_i18ngrep "Invalid object name: \[core\]" err && git --git-dir=dst/.git config receive.fsck.skipList SKIP && git push --porcelain dst bogus @@ -255,10 +255,10 @@ test_expect_success 'fetch with fetch.fsck.skipList' ' test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist && test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err && - test_i18ngrep "Could not open skip list: does-not-exist" err && + test_i18ngrep "Could not open object name list: does-not-exist" err && git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config && test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err && - test_i18ngrep "Invalid SHA-1: \[core\]" err && + test_i18ngrep "Invalid object name: \[core\]" err && git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP && git --git-dir=dst/.git fetch "file://$(pwd)" $refspec From patchwork Tue Feb 12 22:27:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barret Rhoden X-Patchwork-Id: 10808867 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 EC807922 for ; Tue, 12 Feb 2019 22:27:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA8672C720 for ; Tue, 12 Feb 2019 22:27:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEED82C725; Tue, 12 Feb 2019 22:27:36 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 716E82C720 for ; Tue, 12 Feb 2019 22:27:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730909AbfBLW1f (ORCPT ); Tue, 12 Feb 2019 17:27:35 -0500 Received: from mail-qt1-f201.google.com ([209.85.160.201]:34879 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728584AbfBLW1d (ORCPT ); Tue, 12 Feb 2019 17:27:33 -0500 Received: by mail-qt1-f201.google.com with SMTP id k1so368623qta.2 for ; Tue, 12 Feb 2019 14:27:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=0AVqEGp8Lf916B35P15x2TefwJH9bKGucnpkYkpGL9E=; b=DbY23twKNEM9aU+7r6ssUvq7nfiPdLbzCS1TiD15vvyOA7bBT9bHh9A4g8eCaL8hSd KgAKBqOFRQHremBS2B+Jwy9jgDcFAACjdfbk8lYwZKXoieXY+xhPck5KytpDxlvoR132 e4zrop/bpIV6ykLlV85cBl5uaj3qyPc86T2iE3ptXIWcQvxO2KoSGHbLpoKNAk98XRSh PAHBFe8Ft6cxOv9bwo4UZgjTV0eocKB8zF4IXi3i57TL5zSGhecK0s8RmmrPRblJhQ6t DLgO8ZnhwAVTNkv+N1I9Mh2/tBbXg14mkK/O0DdHvkVT8xBWqYwttGRZ87uXNvDGz6Sn aa8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0AVqEGp8Lf916B35P15x2TefwJH9bKGucnpkYkpGL9E=; b=YSeFC/1+QWbg8QKBrOMnmA/Wqi798Pf8U+uT5dE5iIkFmJmsADubRijKoXH526wIkz +ioZctbVfzOxJy6ASnK8JoUW7zoouoz7mYsp8UOmueaHP+AvbZNESx3CM+DUmTAoHUNI Od4Wj+WvAPxNqkzuJakGjc/2n7DDsqKzEBR15jSnu7shWSwZ4kYH2fJRKVUKo8GNPS9Q 0auznOVR6LvbipOF2Wq8EAtgmGhhQimIpTruafncbSfAaXm75NCSGESx7YsSGgV+2xRq EpywBulUS1JcogtmH31G3AyeylPbNGq+OaFIhFtN4MPLbvc7qVu9DifJvJSQ0FwiJ5yv Yktw== X-Gm-Message-State: AHQUAuYpIEPvVxclwOlzVJ8n45+17a05P+LP1Br+eRwhV5IZsa6twI4R 4qcFPop8cqB9BU1y7dDlR3lvYLYdzAe0UF7Jo4NawQvPEoqvGYBYRrKcr3mRFYnLNgut67KQb2y fqPQai5c2y6J9Z4dFvmxh38ks4VNO1bYHXjcmndYOOeNRM8nfjI67 X-Google-Smtp-Source: AHgI3IZ2RG00DygGwonuVMHMQMaOv1e4NsCjI/DIa0DsO6FBkAsHRAVDWxoARJYDD5TjktILGUiQPt6j X-Received: by 2002:a37:58b:: with SMTP id 133mr2576615qkf.31.1550010452139; Tue, 12 Feb 2019 14:27:32 -0800 (PST) Date: Tue, 12 Feb 2019 17:27:19 -0500 In-Reply-To: <20190212222722.240676-1-brho@google.com> Message-Id: <20190212222722.240676-3-brho@google.com> Mime-Version: 1.0 References: <20190212222722.240676-1-brho@google.com> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog Subject: [PATCH v3 2/5] blame: use a helper function in blame_chunk() From: Barret Rhoden To: git@vger.kernel.org Cc: " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , David Kastrup , Jeff King , Jeff Smith , Johannes Schindelin , Junio C Hamano , " =?utf-8?q?Ren=C3=A9_Scharfe?= " , Stefan Beller Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The same code for splitting a blame_entry at a particular line was used twice in blame_chunk(), and I'll use the helper again in an upcoming patch. Signed-off-by: Barret Rhoden --- blame.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/blame.c b/blame.c index da57233cbbd9..f30bb2430c5e 100644 --- a/blame.c +++ b/blame.c @@ -838,6 +838,25 @@ static struct blame_entry *reverse_blame(struct blame_entry *head, return tail; } +/* Splits a blame entry into two entries at 'len' lines. The original 'e' + * consists of len lines, i.e. [e->lno, e->lno + len), and the second part, + * which is returned, consists of the remainder: [e->lno + len, e->lno + + * e->num_lines). The caller needs to sort out the reference counting for the + * new entry's suspect. */ +static struct blame_entry *split_blame_at(struct blame_entry *e, int len, + struct blame_origin *new_suspect) +{ + struct blame_entry *n = xcalloc(1, sizeof(struct blame_entry)); + + n->suspect = new_suspect; + n->lno = e->lno + len; + n->s_lno = e->s_lno + len; + n->num_lines = e->num_lines - len; + e->num_lines = len; + e->score = 0; + return n; +} + /* * Process one hunk from the patch between the current suspect for * blame_entry e and its parent. This first blames any unfinished @@ -864,14 +883,9 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq, */ if (e->s_lno + e->num_lines > tlno) { /* Move second half to a new record */ - int len = tlno - e->s_lno; - struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry)); - n->suspect = e->suspect; - n->lno = e->lno + len; - n->s_lno = e->s_lno + len; - n->num_lines = e->num_lines - len; - e->num_lines = len; - e->score = 0; + struct blame_entry *n; + + n = split_blame_at(e, tlno - e->s_lno, e->suspect); /* Push new record to diffp */ n->next = diffp; diffp = n; @@ -918,14 +932,10 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq, * Move second half to a new record to be * processed by later chunks */ - int len = same - e->s_lno; - struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry)); - n->suspect = blame_origin_incref(e->suspect); - n->lno = e->lno + len; - n->s_lno = e->s_lno + len; - n->num_lines = e->num_lines - len; - e->num_lines = len; - e->score = 0; + struct blame_entry *n; + + n = split_blame_at(e, same - e->s_lno, + blame_origin_incref(e->suspect)); /* Push new record to samep */ n->next = samep; samep = n; From patchwork Tue Feb 12 22:27:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barret Rhoden X-Patchwork-Id: 10808869 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 BC373922 for ; Tue, 12 Feb 2019 22:27:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A96DA2C720 for ; Tue, 12 Feb 2019 22:27:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DCE52C725; Tue, 12 Feb 2019 22:27:39 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 68B7B2C720 for ; Tue, 12 Feb 2019 22:27:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730927AbfBLW1h (ORCPT ); Tue, 12 Feb 2019 17:27:37 -0500 Received: from mail-yw1-f73.google.com ([209.85.161.73]:55858 "EHLO mail-yw1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728584AbfBLW1g (ORCPT ); Tue, 12 Feb 2019 17:27:36 -0500 Received: by mail-yw1-f73.google.com with SMTP id j64so196194ywg.22 for ; Tue, 12 Feb 2019 14:27:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=uWxeVd/BvkSnF7SSKBcIvcwCn/88nLTEWCKFm+x8mVw=; b=Q0WR+1Yi1qsRftVpqrgojPHpg+PrH9wMMULj+xXFdlTB0qqR3RsBPVCtg092etHkNF 6PMwM0H/JIEWH25XhGb7GFYgheEhbpSzahRgYNDvSH3WrL347tmklb6wAQCvrEpmp/Ui /kcekE//b/7eL2uIxuUhnZszirPbgzPReF56p/F+XZIwAAtLqn4urd0CWXJm6Vw994Qv CvZwzr2eiJouk2GCfaGPubZcjZBaYbSnwxkAUIJBd0fcyGBfWsydztZ5qRtIHLpoT9uq KDIsz4IGjUjrRYwA/a65ac1REqmb8oS5HzHWM7bGhVxxgAmEh3cEUsorvn64SnHaZT19 cL8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uWxeVd/BvkSnF7SSKBcIvcwCn/88nLTEWCKFm+x8mVw=; b=Km3BSAlwNNUuBg4Jj6lZlcfBScfufSzp0bNtmXEhDfCiEN3xu1pJFz140W4qO3ctLA Z80MFZNLE+C92GezhrppwEiYteydesz02+JpcNrCXWgT0BCxPPyHtCIV569AQXg7sMnw 8Uofxj1BUAyC7FVbQCc+ABvHsaYH+9ylZccxE6E6K91j2waK+IU6MNknyZ3TF4wqcWpI FJe6YLx430OnrOcLIj6hTcd6qXwFdlcl4n3pc4I5+zQMbDs3jqn7EF6dtlOz10ExdXX9 G8EHhggLU/h88pwsCKffFSNiB3lf+x3doT63uk3eg5bnqy4rye+Ks5XsRgJ+yHXQY9vt A38A== X-Gm-Message-State: AHQUAuZb/TxEO5f2rgkB34soPOtqCnrJh59onwmTOswyHJx115cU64SA Yo91YOQWvSGZ5vpmw7DMwo94kurM9ef/aS+erO06jLQ2m+RxMiydm2DAKl1KdPvBB0URD3YqTfo SjXVb6R+sMeMc75NiXij2H+ZFwCmInj8Pnc+votmn7/5F8DFGAoan X-Google-Smtp-Source: AHgI3IZGdJa0LHEOWvqiLMtszJC7oWalY6xlcY2+Tz7hqi9HzSsOVrTAHINQjfK63LhP0AaR3D+eKeJl X-Received: by 2002:a81:6fd6:: with SMTP id k205mr1239703ywc.23.1550010454560; Tue, 12 Feb 2019 14:27:34 -0800 (PST) Date: Tue, 12 Feb 2019 17:27:20 -0500 In-Reply-To: <20190212222722.240676-1-brho@google.com> Message-Id: <20190212222722.240676-4-brho@google.com> Mime-Version: 1.0 References: <20190212222722.240676-1-brho@google.com> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog Subject: [PATCH v3 3/5] blame: add the ability to ignore commits and their changes From: Barret Rhoden To: git@vger.kernel.org Cc: " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , David Kastrup , Jeff King , Jeff Smith , Johannes Schindelin , Junio C Hamano , " =?utf-8?q?Ren=C3=A9_Scharfe?= " , Stefan Beller Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commits that make formatting changes or function renames are often not interesting when blaming a file. A user may deem such a commit as 'not interesting' and want to ignore and its changes it when assigning blame. For example, say a file has the following git history / rev-list: ---O---A---X---B---C---D---Y---E---F Commits X and Y both touch a particular line, and the other commits do not: X: "Take a third parameter" -MyFunc(1, 2); +MyFunc(1, 2, 3); Y: "Remove camelcase" -MyFunc(1, 2, 3); +my_func(1, 2, 3); git-blame will blame Y for the change. I'd like to be able to ignore Y: both the existence of the commit as well as any changes it made. This differs from -S rev-list, which specifies the list of commits to process for the blame. We would still process Y, but just don't let the blame 'stick.' This patch adds the ability for users to ignore a revision with --ignore-rev=rev, which may be repeated. They can specify a set of files of full object names of revs, e.g. SHA-1 hashes, one per line. A single file may be specified with the blame.ignoreRevFile config option or with --ignore-rev-file=file. Both the config option and the command line option may be repeated multiple times. An empty file name "" will clear the list of revs from previously processed files. Config options are processed before command line options. For a typical use case, projects will maintain the file containing revisions for commits that perform mass reformatting, and their users have the optional to ignore all of the commits in that file. Additionally, a user can use the --ignore-rev option for one-off investigation. To go back to the example above, X was a substantive change to the function, but not the change the user is interested in. The user inspected X, but wanted to find the previous change to that line - perhaps a commit that introduced that function call. To make this work, we can't simply remove all ignored commits from the rev-list. We need to diff the changes introduced by Y so that we can ignore them. We let the blames get passed to Y, just like when processing normally. When Y is the target, we make sure that Y does not *keep* any blames. Any changes that Y is responsible for get passed to its parent. Note we make one pass through all of the scapegoats (parents) to attempt to pass blame normally; we don't know if we *need* to ignore the commit until we've checked all of the parents. The blame_entry will get passed up the tree until we find a commit that has a diff chunk that affects those lines. If an ignored commit added more lines than it removed, we will never be able to attribute those lines to any commit. The blame_entry consists of the number of lines that the ignored commit touched, but the parent has fewer lines. Those extra lines extend beyond the parent's version of the diff hunk, so any blamed commit will be incorrect - it will be blamed on a commit that changed lines *after* the diff hunk. We mark those extra lines as "unblamable" and output a hash of all zeros. For example, the parent of an ignored commit has this, say at line 11: commit-a 11) void new_func_1(void *x, void *y); commit-b 12) void new_func_2(void *x, void *y); commit-c 13) some_line_c commit-d 14) some_line_d After a commit 'X', we have: commit-X 11) void new_func_1(void *x, commit-X 12) void *y); commit-X 13) void new_func_2(void *x, commit-X 14) void *y); commit-c 15) some_line_c commit-d 16) some_line_d Commit X nets two additionally lines: 13 and 14. Those are unblamable. If you ignore commit X and attempt to find blame, you will get this: commit-a 11) void new_func_1(void *x, commit-b 12) void *y); commit-c 13) void new_func_2(void *x, commit-d 14) void *y); commit-c 15) some_line_c commit-d 16) some_line_d Lines 13 and 14 received the blames from lines 15 and 16. From the parent's perspective, lines 15 and 16 are the ones that follow lines 11 and 12. By marking those lines unblamable, we get: commit-a 11) void new_func_1(void *x, commit-b 12) void *y); 00000000 13) void new_func_2(void *x, 00000000 14) void *y); commit-c 15) some_line_c commit-d 16) some_line_d We still can never be certain about which commits *should* be blamed for which lines. Note that line 12 was blamed on B, though B was the commit for new_func_2(), not new_func_1(). But we can avoid blaming commits that just happen to be in the area and would only be 'correct' due to dumb luck. The commits that are blamed merely changed lines in the parent's version of the file at that offset. Signed-off-by: Barret Rhoden --- Documentation/blame-options.txt | 16 ++++++++ Documentation/config/blame.txt | 7 ++++ Documentation/git-blame.txt | 1 + blame.c | 69 ++++++++++++++++++++++++++++----- blame.h | 3 ++ builtin/blame.c | 42 ++++++++++++++++++++ 6 files changed, 129 insertions(+), 9 deletions(-) diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt index dc41957afab2..a0a340ef1b73 100644 --- a/Documentation/blame-options.txt +++ b/Documentation/blame-options.txt @@ -110,5 +110,21 @@ commit. And the default value is 40. If there are more than one `-C` options given, the argument of the last `-C` will take effect. +--ignore-rev :: + Ignore changes made by the revision when assigning blame, as if the + change never happened. Lines that were changed or added by an ignored + commit will be blamed on the previous commit that changed that line or + nearby lines. This option may be specified multiple times to ignore + more than one revision. If the `blame.markIgnoredLines` config option + is set, then lines that were changed by an ignored commit will be + marked with a `*` in the blame output. + +--ignore-revs-file :: + Ignore revisions listed in `file`, one unabbreviated object name per line. + Whitespace and comments beginning with `#` are ignored. This option may be + repeated, and these files will be processed after any files specified with + the `blame.ignoreRevsFile` config option. An empty file name, `""`, will + clear the list of revs from previously processed files. + -h:: Show help message. diff --git a/Documentation/config/blame.txt b/Documentation/config/blame.txt index 67b5c1d1e02a..4da2788f306d 100644 --- a/Documentation/config/blame.txt +++ b/Documentation/config/blame.txt @@ -19,3 +19,10 @@ blame.showEmail:: blame.showRoot:: Do not treat root commits as boundaries in linkgit:git-blame[1]. This option defaults to false. + +blame.ignoreRevsFile:: + Ignore revisions listed in the file, one unabbreviated object name per + line, in linkgit:git-blame[1]. Whitespace and comments beginning with + `#` are ignored. This option may be repeated multiple times. Empty + file names will reset the list of ignored revisions. This option will + be handled before the command line option `--ignore-revs-file`. diff --git a/Documentation/git-blame.txt b/Documentation/git-blame.txt index 16323eb80e31..7e8154199635 100644 --- a/Documentation/git-blame.txt +++ b/Documentation/git-blame.txt @@ -10,6 +10,7 @@ SYNOPSIS [verse] 'git blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] [-L ] [-S ] [-M] [-C] [-C] [-C] [--since=] + [--ignore-rev ] [--ignore-revs-file ] [--progress] [--abbrev=] [ | --contents | --reverse ..] [--] diff --git a/blame.c b/blame.c index f30bb2430c5e..4427cde95dc5 100644 --- a/blame.c +++ b/blame.c @@ -479,7 +479,8 @@ void blame_coalesce(struct blame_scoreboard *sb) for (ent = sb->ent; ent && (next = ent->next); ent = next) { if (ent->suspect == next->suspect && - ent->s_lno + ent->num_lines == next->s_lno) { + ent->s_lno + ent->num_lines == next->s_lno && + ent->unblamable == next->unblamable) { ent->num_lines += next->num_lines; ent->next = next->next; blame_origin_decref(next->suspect); @@ -731,6 +732,10 @@ static void split_overlap(struct blame_entry *split, int chunk_end_lno; memset(split, 0, sizeof(struct blame_entry [3])); + split[0].unblamable = e->unblamable; + split[1].unblamable = e->unblamable; + split[2].unblamable = e->unblamable; + if (e->s_lno < tlno) { /* there is a pre-chunk part not blamed on parent */ split[0].suspect = blame_origin_incref(e->suspect); @@ -849,6 +854,7 @@ static struct blame_entry *split_blame_at(struct blame_entry *e, int len, struct blame_entry *n = xcalloc(1, sizeof(struct blame_entry)); n->suspect = new_suspect; + n->unblamable = e->unblamable; n->lno = e->lno + len; n->s_lno = e->s_lno + len; n->num_lines = e->num_lines - len; @@ -869,10 +875,10 @@ static struct blame_entry *split_blame_at(struct blame_entry *e, int len, */ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq, int tlno, int offset, int same, - struct blame_origin *parent) + struct blame_origin *parent, int ignore_diffs, int delta) { struct blame_entry *e = **srcq; - struct blame_entry *samep = NULL, *diffp = NULL; + struct blame_entry *samep = NULL, *diffp = NULL, *ignoredp = NULL; while (e && e->s_lno < tlno) { struct blame_entry *next = e->next; @@ -940,10 +946,36 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq, n->next = samep; samep = n; } - e->next = diffp; - diffp = e; + if (ignore_diffs) { + /* These go to the parent, like the ones before tlno. */ + blame_origin_decref(e->suspect); + e->suspect = blame_origin_incref(parent); + e->s_lno += offset; + /* The top part of any ignored diff will not exist in + * the parent, and we will never be able to accurately + * blame it. We'll keep it on the blame list for the + * target and mark it during the output. */ + if (delta > 0) { + struct blame_entry *n; + + n = split_blame_at(e, e->num_lines - delta, + blame_origin_incref(e->suspect)); + n->unblamable = 1; + n->next = diffp; + diffp = n; + } + e->next = ignoredp; + ignoredp = e; + } else { + e->next = diffp; + diffp = e; + } e = next; } + if (ignoredp) { + **dstq = reverse_blame(ignoredp, **dstq); + *dstq = &ignoredp->next; + } **srcq = reverse_blame(diffp, reverse_blame(samep, e)); /* Move across elements that are in the unblamable portion */ if (diffp) @@ -953,6 +985,7 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq, struct blame_chunk_cb_data { struct blame_origin *parent; long offset; + int ignore_diffs; struct blame_entry **dstq; struct blame_entry **srcq; }; @@ -965,7 +998,7 @@ static int blame_chunk_cb(long start_a, long count_a, if (start_a - start_b != d->offset) die("internal error in blame::blame_chunk_cb"); blame_chunk(&d->dstq, &d->srcq, start_b, start_a - start_b, - start_b + count_b, d->parent); + start_b + count_b, d->parent, d->ignore_diffs, count_b - count_a); d->offset = start_a + count_a - (start_b + count_b); return 0; } @@ -977,7 +1010,7 @@ static int blame_chunk_cb(long start_a, long count_a, */ static void pass_blame_to_parent(struct blame_scoreboard *sb, struct blame_origin *target, - struct blame_origin *parent) + struct blame_origin *parent, int ignore_diffs) { mmfile_t file_p, file_o; struct blame_chunk_cb_data d; @@ -988,6 +1021,7 @@ static void pass_blame_to_parent(struct blame_scoreboard *sb, d.parent = parent; d.offset = 0; + d.ignore_diffs = ignore_diffs; d.dstq = &newdest; d.srcq = &target->suspects; fill_origin_blob(&sb->revs->diffopt, parent, &file_p, &sb->num_read_blob); @@ -999,7 +1033,7 @@ static void pass_blame_to_parent(struct blame_scoreboard *sb, oid_to_hex(&parent->commit->object.oid), oid_to_hex(&target->commit->object.oid)); /* The rest are the same as the parent */ - blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent); + blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent, 0, 0); *d.dstq = NULL; queue_blames(sb, parent, newdest); @@ -1504,11 +1538,28 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin, blame_origin_incref(porigin); origin->previous = porigin; } - pass_blame_to_parent(sb, origin, porigin); + pass_blame_to_parent(sb, origin, porigin, 0); if (!origin->suspects) goto finish; } + /* + * Pass remaining suspects for ignored commits to their parents. + */ + if (oidset_contains(&sb->ignore_list, &commit->object.oid)) { + for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse); + i < num_sg && sg; + sg = sg->next, i++) { + struct blame_origin *porigin = sg_origin[i]; + + if (!porigin) + continue; + pass_blame_to_parent(sb, origin, porigin, 1); + if (!origin->suspects) + goto finish; + } + } + /* * Optionally find moves in parents' files. */ diff --git a/blame.h b/blame.h index be3a895043e0..91664913d7c4 100644 --- a/blame.h +++ b/blame.h @@ -92,6 +92,7 @@ struct blame_entry { * scanning the lines over and over. */ unsigned score; + int unblamable; }; /* @@ -117,6 +118,8 @@ struct blame_scoreboard { /* linked list of blames */ struct blame_entry *ent; + struct oidset ignore_list; + /* look-up a line in the final buffer */ int num_lines; int *lineno; diff --git a/builtin/blame.c b/builtin/blame.c index 581de0d83226..5f38e9dccddd 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -52,6 +52,7 @@ static int no_whole_file_rename; static int show_progress; static char repeated_meta_color[COLOR_MAXLEN]; static int coloring_mode; +static struct string_list ignore_revs_file_list = STRING_LIST_INIT_NODUP; static struct date_mode blame_date_mode = { DATE_ISO8601 }; static size_t blame_date_width; @@ -346,6 +347,8 @@ static void emit_porcelain(struct blame_scoreboard *sb, struct blame_entry *ent, char hex[GIT_MAX_HEXSZ + 1]; oid_to_hex_r(hex, &suspect->commit->object.oid); + if (ent->unblamable) + memset(hex, '0', strlen(hex)); printf("%s %d %d %d\n", hex, ent->s_lno + 1, @@ -479,6 +482,8 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int } } + if (ent->unblamable) + memset(hex, '0', length); printf("%.*s", length, hex); if (opt & OUTPUT_ANNOTATE_COMPAT) { const char *name; @@ -695,6 +700,16 @@ static int git_blame_config(const char *var, const char *value, void *cb) parse_date_format(value, &blame_date_mode); return 0; } + if (!strcmp(var, "blame.ignorerevsfile")) { + const char *str; + int ret; + + ret = git_config_pathname(&str, var, value); + if (ret) + return ret; + string_list_insert(&ignore_revs_file_list, str); + return 0; + } if (!strcmp(var, "color.blame.repeatedlines")) { if (color_parse_mem(value, strlen(value), repeated_meta_color)) warning(_("invalid color '%s' in color.blame.repeatedLines"), @@ -774,6 +789,27 @@ static int is_a_rev(const char *name) return OBJ_NONE < oid_object_info(the_repository, &oid, NULL); } +static void build_ignorelist(struct blame_scoreboard *sb, + struct string_list *ignore_revs_file_list, + struct string_list *ignore_rev_list) +{ + struct string_list_item *i; + struct object_id oid; + + oidset_init(&sb->ignore_list, 0); + for_each_string_list_item(i, ignore_revs_file_list) { + if (!strcmp(i->string, "")) + oidset_clear(&sb->ignore_list); + else + oidset_parse_file(&sb->ignore_list, i->string); + } + for_each_string_list_item(i, ignore_rev_list) { + if (get_oid_committish(i->string, &oid)) + die(_("Cannot find revision %s to ignore"), i->string); + oidset_insert(&sb->ignore_list, &oid); + } +} + int cmd_blame(int argc, const char **argv, const char *prefix) { struct rev_info revs; @@ -785,6 +821,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) struct progress_info pi = { NULL, 0 }; struct string_list range_list = STRING_LIST_INIT_NODUP; + struct string_list ignore_rev_list = STRING_LIST_INIT_NODUP; int output_option = 0, opt = 0; int show_stats = 0; const char *revs_file = NULL; @@ -806,6 +843,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix) OPT_BIT('s', NULL, &output_option, N_("Suppress author name and timestamp (Default: off)"), OUTPUT_NO_AUTHOR), OPT_BIT('e', "show-email", &output_option, N_("Show author email instead of name (Default: off)"), OUTPUT_SHOW_EMAIL), OPT_BIT('w', NULL, &xdl_opts, N_("Ignore whitespace differences"), XDF_IGNORE_WHITESPACE), + OPT_STRING_LIST(0, "ignore-rev", &ignore_rev_list, N_("rev"), N_("Ignore when blaming")), + OPT_STRING_LIST(0, "ignore-revs-file", &ignore_revs_file_list, N_("file"), N_("Ignore revisions from ")), OPT_BIT(0, "color-lines", &output_option, N_("color redundant metadata from previous line differently"), OUTPUT_COLOR_LINE), OPT_BIT(0, "color-by-age", &output_option, N_("color lines by age"), OUTPUT_SHOW_AGE_WITH_COLOR), @@ -999,6 +1038,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix) sb.contents_from = contents_from; sb.reverse = reverse; sb.repo = the_repository; + build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list); + string_list_clear(&ignore_revs_file_list, 0); + string_list_clear(&ignore_rev_list, 0); setup_scoreboard(&sb, path, &o); lno = sb.num_lines; From patchwork Tue Feb 12 22:27:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barret Rhoden X-Patchwork-Id: 10808871 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 14308746 for ; Tue, 12 Feb 2019 22:27:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 026DE2C720 for ; Tue, 12 Feb 2019 22:27:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EABEE2C725; Tue, 12 Feb 2019 22:27:40 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 743A22C720 for ; Tue, 12 Feb 2019 22:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731007AbfBLW1j (ORCPT ); Tue, 12 Feb 2019 17:27:39 -0500 Received: from mail-qk1-f201.google.com ([209.85.222.201]:49202 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730932AbfBLW1i (ORCPT ); Tue, 12 Feb 2019 17:27:38 -0500 Received: by mail-qk1-f201.google.com with SMTP id s65so308870qke.16 for ; Tue, 12 Feb 2019 14:27:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=uoU5D34kNTz+Uv+JFrtGEh1wh0zzK6BluWK96zzDW2o=; b=GtIAxBmJrpP1qkVAmfFoahn32JDu32Ogl2OHrakPgoT+EyAk+6axiMxOMjwc6zsqTw ILwgB76zhiuJm+IpOLVqU08/ruP0n6IIDZnpP+89VSnVCjVlDyBePggcjvvz+y7Af9rT 1FiLgZDZ6RdDqxIh+84KPz38DtkNp8Qj4dkNyECk/WjK1Oj4f47pr1L9U06ZUYyyLeBZ HOGg/2wauD1rzym+FBPNMP6KN82fv9cNe936CNP3hBdkW5CbSKVa1CiIn44P1DRR7oe3 ST2TglD0u38bWFP5vWvvAtwDnr/gIrgF9XGZcqCyDxGO777kkoU7Zy0ZaPmiUGlIoNNR GaGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uoU5D34kNTz+Uv+JFrtGEh1wh0zzK6BluWK96zzDW2o=; b=QD4toKltaFoAh6w1QoWbUpPpf01Sep3usT31gFBKV+1DI6fiZ4P1Hcy1QnsdDSn5nq pylCysR0PsoEzwGUE0Yn153ZhBNrmoa/B66h9FX4DAKidffQk8LbUbVb32QjQeutvL9N zapj2tdVgOmnzCsyOFWvnRP7zoDBM81UNzuNWmW8df2cybftQfnn/1Yqu4LabTM4jtTz 3AmP7Leb5jPGUGFtctfzS4am6J6Pps3B9H/FPUsAnYZHnbcPeeBL9dsEzcgFdsDfRTQT tO3c+XI+GZrNUzKfVcdYLpM7Lk5JE4yY+AdjA18Z9XfQ59OWNbYFXGKK5oaGgRrlM4Wx S0hQ== X-Gm-Message-State: AHQUAub+dkud2qaykzh1SUPhgMi1TFumn8KfACi7owsXnuPx9czRxonG cNWOwk43oihGZPaac0ZMrv7UmW2tZwuoN7cIT/Ed5Xje3aApVIbfehpGpdOsuF8TuozqWZmh5U6 CVzIBQy2Fr8Wvpn0lv8a4uyspilpd1K5h0sHhH7hnMP/neuITNYyH X-Google-Smtp-Source: AHgI3IYYuS3axIzyFYYbdl82Xfz93p3k6FF725nTsImDQHtg/xWzwKbCqPrE/vMIbaXVAh8ztyQz43Up X-Received: by 2002:a0c:add8:: with SMTP id x24mr3390221qvc.16.1550010456672; Tue, 12 Feb 2019 14:27:36 -0800 (PST) Date: Tue, 12 Feb 2019 17:27:21 -0500 In-Reply-To: <20190212222722.240676-1-brho@google.com> Message-Id: <20190212222722.240676-5-brho@google.com> Mime-Version: 1.0 References: <20190212222722.240676-1-brho@google.com> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog Subject: [PATCH v3 4/5] blame: add a config option to mark ignored lines From: Barret Rhoden To: git@vger.kernel.org Cc: " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , David Kastrup , Jeff King , Jeff Smith , Johannes Schindelin , Junio C Hamano , " =?utf-8?q?Ren=C3=A9_Scharfe?= " , Stefan Beller Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When ignoring commits, the commit that is blamed might not be responsible for the change. Users might want to know when a particular line has a potentially inaccurate blame. This patch adds a config option to identify these lines by specifying blame.markIgnoredFiles. When this option is set, each blame line is marked with an '*'. For example: 278b6158d6fdb (Barret Rhoden 2016-04-11 13:57:54 -0400 26) appears as: *278b6158d6fd (Barret Rhoden 2016-04-11 13:57:54 -0400 26) where the '*' is placed before the commit, and the hash has one fewer characters. Signed-off-by: Barret Rhoden --- Documentation/config/blame.txt | 4 ++++ blame.c | 4 ++++ blame.h | 1 + builtin/blame.c | 9 +++++++++ 4 files changed, 18 insertions(+) diff --git a/Documentation/config/blame.txt b/Documentation/config/blame.txt index 4da2788f306d..9f7f0fcf42c9 100644 --- a/Documentation/config/blame.txt +++ b/Documentation/config/blame.txt @@ -26,3 +26,7 @@ blame.ignoreRevsFile:: `#` are ignored. This option may be repeated multiple times. Empty file names will reset the list of ignored revisions. This option will be handled before the command line option `--ignore-revs-file`. + +blame.markIgnoredLines:: + Mark lines that were changed by an ignored revision with a '*' in the + output of linkgit:git-blame[1]. diff --git a/blame.c b/blame.c index 4427cde95dc5..34debdba1a7f 100644 --- a/blame.c +++ b/blame.c @@ -480,6 +480,7 @@ void blame_coalesce(struct blame_scoreboard *sb) for (ent = sb->ent; ent && (next = ent->next); ent = next) { if (ent->suspect == next->suspect && ent->s_lno + ent->num_lines == next->s_lno && + ent->ignored == next->ignored && ent->unblamable == next->unblamable) { ent->num_lines += next->num_lines; ent->next = next->next; @@ -732,6 +733,7 @@ static void split_overlap(struct blame_entry *split, int chunk_end_lno; memset(split, 0, sizeof(struct blame_entry [3])); + split[0].ignored = split[1].ignored = split[2].ignored = e->ignored; split[0].unblamable = e->unblamable; split[1].unblamable = e->unblamable; split[2].unblamable = e->unblamable; @@ -854,6 +856,7 @@ static struct blame_entry *split_blame_at(struct blame_entry *e, int len, struct blame_entry *n = xcalloc(1, sizeof(struct blame_entry)); n->suspect = new_suspect; + n->ignored = e->ignored; n->unblamable = e->unblamable; n->lno = e->lno + len; n->s_lno = e->s_lno + len; @@ -951,6 +954,7 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq, blame_origin_decref(e->suspect); e->suspect = blame_origin_incref(parent); e->s_lno += offset; + e->ignored = 1; /* The top part of any ignored diff will not exist in * the parent, and we will never be able to accurately * blame it. We'll keep it on the blame list for the diff --git a/blame.h b/blame.h index 91664913d7c4..53df8b4c5b3f 100644 --- a/blame.h +++ b/blame.h @@ -92,6 +92,7 @@ struct blame_entry { * scanning the lines over and over. */ unsigned score; + int ignored; int unblamable; }; diff --git a/builtin/blame.c b/builtin/blame.c index 5f38e9dccddd..46d96905de75 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -53,6 +53,7 @@ static int show_progress; static char repeated_meta_color[COLOR_MAXLEN]; static int coloring_mode; static struct string_list ignore_revs_file_list = STRING_LIST_INIT_NODUP; +static int mark_ignored_lines; static struct date_mode blame_date_mode = { DATE_ISO8601 }; static size_t blame_date_width; @@ -482,6 +483,10 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int } } + if (mark_ignored_lines && ent->ignored) { + length--; + putchar('*'); + } if (ent->unblamable) memset(hex, '0', length); printf("%.*s", length, hex); @@ -710,6 +715,10 @@ static int git_blame_config(const char *var, const char *value, void *cb) string_list_insert(&ignore_revs_file_list, str); return 0; } + if (!strcmp(var, "blame.markignoredlines")) { + mark_ignored_lines = git_config_bool(var, value); + return 0; + } if (!strcmp(var, "color.blame.repeatedlines")) { if (color_parse_mem(value, strlen(value), repeated_meta_color)) warning(_("invalid color '%s' in color.blame.repeatedLines"), From patchwork Tue Feb 12 22:27:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barret Rhoden X-Patchwork-Id: 10808873 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 7C2DE922 for ; Tue, 12 Feb 2019 22:27:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AEE42C720 for ; Tue, 12 Feb 2019 22:27:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F46A2C725; Tue, 12 Feb 2019 22:27:43 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 3DCF32C720 for ; Tue, 12 Feb 2019 22:27:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731115AbfBLW1k (ORCPT ); Tue, 12 Feb 2019 17:27:40 -0500 Received: from mail-qt1-f201.google.com ([209.85.160.201]:34102 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728584AbfBLW1j (ORCPT ); Tue, 12 Feb 2019 17:27:39 -0500 Received: by mail-qt1-f201.google.com with SMTP id u32so381789qte.1 for ; Tue, 12 Feb 2019 14:27:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=G2gCcVluih27GVXEe98PpgMaMYKqsCspf3XB+7FYrPo=; b=hgz18WrVdshcZnSWctOAKnFWbBdIO5IHgZs4cZ0YkgjGPMGPzbMQ4VGHvaGKI1znDN YQPjSWiE0nlt725ZOllG+3RMjzd3D5xmxvDtug2qj/XQeDrY3F2weijn5rtWADJUa80Q gDInBv781wfLjhLbUyeCvgOUyMEPydMO6WQVQ6giTKoaFmqicvtxIOOpVlBEU2BLZp1x /AcjJbgMwXm/ZmteizGvYOSGQl2qvmQ96+dk1HgOyXR7zw36EndocYNNaQpDFa6N2e4L tlcmD+6zGQoVdP55DT3RGtJPzo7uiEIbK+DUfIooGAVi+K9Rd5Quc4PkXKU7BhAMjj+7 udKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=G2gCcVluih27GVXEe98PpgMaMYKqsCspf3XB+7FYrPo=; b=etFim8u798Zbq5XiL8/sJWqD6DXRMp/HBDxrqHeFCvH0vnBkw+g8aMuTviw+nOlLNE RvYzWwYpWkpChe0py7cGoAQdy3SGw+pJLP4IcrQBZZQNz/JryuOMdD9ndx4pzFgdszs0 MtAq220jGlVwVBd04srD8CX5WZrKaWAu1MxwjPBUBNi8lvMoh4d+9vR22FafK+JN39xT s3WlFtSx4fDBsEAa37mULzpiNyvfUTXcRRCdB6LvSTNdlnpyL/otKqgK4ykblbOgRqi8 Eq16mRLe0fsSL4hepvPwCTzTq8nRjQFuvjRFZEsf6+7DD44dWd0Sn+RlXlT61VA3hk7N 51Tg== X-Gm-Message-State: AHQUAuYsNAwl9KqetpNW3qTXt4Xxbfhhv/EtWSyVbu5TeD+cQPOXXwSw +hTSKmsbpjGBOBjLuRO5uck+TmX0MWnmj4yWB4WBCWZlO64LDNt0lfzpIp5l/IUQ1c2BoqCa5dg rmCaDk2M+OhPr1QS8VAXNd8hIAeCSedxxQayQQcheURqp5IZ7ZjCo X-Google-Smtp-Source: AHgI3Iaiz2tUo0lsO7+s0rxXzHiUtxGvn96ibfuMbCb5tmbLsPBnc/gXGUgU5XZ+DCTDSGbDwSmoeTsZ X-Received: by 2002:a0c:d486:: with SMTP id u6mr3394088qvh.56.1550010457786; Tue, 12 Feb 2019 14:27:37 -0800 (PST) Date: Tue, 12 Feb 2019 17:27:22 -0500 In-Reply-To: <20190212222722.240676-1-brho@google.com> Message-Id: <20190212222722.240676-6-brho@google.com> Mime-Version: 1.0 References: <20190212222722.240676-1-brho@google.com> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog Subject: [PATCH v3 5/5] blame: add tests for ignoring revisions From: Barret Rhoden To: git@vger.kernel.org Cc: " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , David Kastrup , Jeff King , Jeff Smith , Johannes Schindelin , Junio C Hamano , " =?utf-8?q?Ren=C3=A9_Scharfe?= " , Stefan Beller 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: Barret Rhoden --- t/t8013-blame-ignore-revs.sh | 199 +++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100755 t/t8013-blame-ignore-revs.sh diff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh new file mode 100755 index 000000000000..3a4ad7cf937a --- /dev/null +++ b/t/t8013-blame-ignore-revs.sh @@ -0,0 +1,199 @@ +#!/bin/sh + +test_description='ignore revisions when blaming' +. ./test-lib.sh + +# Creates: +# A--B--X +# A added line 1 and B added line 2. X makes changes to those lines. Sanity +# check that X is blamed for both lines. +test_expect_success setup ' + test_commit A file line1 && + + echo line2 >> file && + git add file && + test_tick && + git commit -m B && + git tag B && + + test_write_lines line-one line-two > file && + git add file && + test_tick && + git commit -m X && + git tag X && + + git blame --line-porcelain file > blame_raw && + + grep "^[0-9a-f]\+ 1 1" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse X > expect && + test_cmp expect actual && + + grep "^[0-9a-f]\+ 2 2" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse X > expect && + test_cmp expect actual + ' + +# Ignore X, make sure A is blamed for line 1 and B for line 2. +test_expect_success ignore_rev_changing_lines ' + git blame --line-porcelain --ignore-rev X file > blame_raw && + + grep "^[0-9a-f]\+ 1 1" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse A > expect && + test_cmp expect actual && + + grep "^[0-9a-f]\+ 2 2" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse B > expect && + test_cmp expect actual + ' + +# For ignored revs that have added more lines than they removed, the extra lines +# must be blamed on an all-zeros rev. +# A--B--X--Y +# Where Y changes lines 1 and 2, and adds lines 3 and 4. +test_expect_success ignore_rev_adding_lines ' + test_write_lines line-one-change line-two-changed new_line3 new_line4 > file && + git add file && + test_tick && + git commit -m Y && + git tag Y && + + git rev-parse Y > expect && + sed -i -e "s/[0-9a-f]/0/g" expect && + git blame --line-porcelain file --ignore-rev Y > blame_raw && + + grep "^[0-9a-f]\+ 3 3" blame_raw | sed -e "s/ .*//" > actual && + test_cmp expect actual && + + grep "^[0-9a-f]\+ 4 4" blame_raw | sed -e "s/ .*//" > actual && + test_cmp expect actual + ' + +# Ignore X and Y, both in separate files. Lines 1 == A, 2 == B. +test_expect_success ignore_revs_from_files ' + git rev-parse X > ignore_x && + git rev-parse Y > ignore_y && + git blame --line-porcelain file --ignore-revs-file ignore_x --ignore-revs-file ignore_y > blame_raw && + + grep "^[0-9a-f]\+ 1 1" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse A > expect && + test_cmp expect actual && + + grep "^[0-9a-f]\+ 2 2" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse B > expect && + test_cmp expect actual + ' + +# Ignore X from the config option, Y from a file. +test_expect_success ignore_revs_from_configs_and_files ' + git config --add blame.ignoreRevsFile ignore_x && + git blame --line-porcelain file --ignore-revs-file ignore_y > blame_raw && + + grep "^[0-9a-f]\+ 1 1" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse A > expect && + test_cmp expect actual && + + grep "^[0-9a-f]\+ 2 2" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse B > expect && + test_cmp expect actual + ' + +# Override blame.ignoreRevsFile (ignore_x) with an empty string. X should be +# blamed now for lines 1 and 2, since we are no longer ignoring X. +test_expect_success override_ignore_revs_file ' + git blame --line-porcelain file --ignore-revs-file "" --ignore-revs-file ignore_y > blame_raw && + git rev-parse X > expect && + + grep "^[0-9a-f]\+ 1 1" blame_raw | sed -e "s/ .*//" > actual && + test_cmp expect actual && + + grep "^[0-9a-f]\+ 2 2" blame_raw | sed -e "s/ .*//" > actual && + test_cmp expect actual + ' +test_expect_success bad_files_and_revs ' + test_must_fail git blame file --ignore-rev NOREV 2> err && + test_i18ngrep "Cannot find revision NOREV to ignore" err && + + test_must_fail git blame file --ignore-revs-file NOFILE 2> err && + test_i18ngrep "Could not open object name list: NOFILE" err && + + echo NOREV > ignore_norev && + test_must_fail git blame file --ignore-revs-file ignore_norev 2> err && + test_i18ngrep "Invalid object name: NOREV" err + ' + +# Commit Z will touch the first two lines. Y touched all four. +# A--B--X--Y--Z +# The blame output when ignoring Z should be: +# ^Y ... 1) +# ^Y ... 2) +# Y ... 3) +# Y ... 4) +# We're checking only the first character +test_expect_success mark_ignored_lines ' + git config --add blame.markIgnoredLines true && + + test_write_lines line-one-Z line-two-Z new_line3 new_line4 > file && + git add file && + test_tick && + git commit -m Z && + git tag Z && + + git blame --ignore-rev Z file > blame_raw && + echo "*" > expect && + + sed -n "1p" blame_raw | cut -c1 > actual && + test_cmp expect actual && + + sed -n "2p" blame_raw | cut -c1 > actual && + test_cmp expect actual && + + sed -n "3p" blame_raw | cut -c1 > actual && + ! test_cmp expect actual && + + sed -n "4p" blame_raw | cut -c1 > actual && + ! test_cmp expect actual + ' + +# Resetting the repo and creating: +# +# A--B--M +# \ / +# C-+ +# +# 'A' creates a file. B changes line 1, and C changes line 9. M merges. +test_expect_success ignore_merge ' + rm -rf .git/ && + git init && + + test_write_lines L1 L2 L3 L4 L5 L6 L7 L8 L9 > file && + git add file && + test_tick && + git commit -m A && + git tag A && + + test_write_lines BB L2 L3 L4 L5 L6 L7 L8 L9 > file && + git add file && + test_tick && + git commit -m B && + git tag B && + + git reset --hard A && + test_write_lines L1 L2 L3 L4 L5 L6 L7 L8 CC > file && + git add file && + test_tick && + git commit -m C && + git tag C && + + test_merge M B && + git blame --line-porcelain file --ignore-rev M > blame_raw && + + grep "^[0-9a-f]\+ 1 1" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse B > expect && + test_cmp expect actual && + + grep "^[0-9a-f]\+ 9 9" blame_raw | sed -e "s/ .*//" > actual && + git rev-parse C > expect && + test_cmp expect actual + ' + +test_done