From patchwork Fri Oct 21 22:25:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13015520 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFF1BC38A2D for ; Fri, 21 Oct 2022 22:25:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbiJUWZu (ORCPT ); Fri, 21 Oct 2022 18:25:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbiJUWZo (ORCPT ); Fri, 21 Oct 2022 18:25:44 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DE7E1BB554 for ; Fri, 21 Oct 2022 15:25:42 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id l127so3472386iof.12 for ; Fri, 21 Oct 2022 15:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=uPNL/OcdIuambt0Tm/HNOVTgI32GrLe4U2yhDI/QHxw=; b=Xw8wksyKtJ0LO8wMAm675WYPSsd++UhcV3ogDBuky1REpvI3PL+1xQGr7O5gh/qrtI jZlwcDvXs0tILVBGSuTqVqCWMssoMC8keGxX5DrTP5kPTQdVpgEjfXyKRkIiGyRMPcGN Wg2dv2OBixx+QEOlwl/K0J+lCnwntBLjiDbe+xyfwTWqse7pUJ+rISiZvh25r1un9o0T UDv7AHlILpxxn/dYkML497gn+H0+IVDf++qhq/c7bUqmeYyg91HLmso8+j/NSJ4MGuCr QXkf6W5dzsZCGWlGxul1xCsRC+IlKPHGDp+llQY9TCLhhhK3Ev2cTYd50NiXaCOuQhyl a9bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uPNL/OcdIuambt0Tm/HNOVTgI32GrLe4U2yhDI/QHxw=; b=nCPMbSAx3Z1I3t4jevKiagvodCLS3yrxBuBl+qIKnB4G9EQ7+ovHXpN5OZL/Y6qCk+ jU2jmyPl+f+7dsyxzuusyC0XVgzg7Bhuy2pQmrP6Ti91jNoAerIYBUtsK4sO0fOq84pr uX0cmhc2rZbzbCymsBx4yOn0+5ifM/Rr8oYuUPnmlQZXG0aGAdFqk43udqY5hYjVsjFV /Uy9lH5eVYaFFT94SsJYO2hyN/xrhGSwyOg0VhRNXwXlBXxQLK4zl1RUPos9S/3NTOAC aKsMTiw3gjs8UO8jncvaSi4woNTR9Ff9pVmgMSY1J7263JN8kSpZvBEWXVWcKsHqlNuV HPBw== X-Gm-Message-State: ACrzQf0Ti2Dj3Ari7S+le31lu1bpP3CAyOp2rueErbXwI3mqGna7Az/n v7vy+KPYiyprILoaEq7FAhnSUCUYyehXwN+U X-Google-Smtp-Source: AMsMyM6nP1F5tq58UXmEJjrJGlEUL3GiUxUbIZC2pQd5RizxZXfK59+nr8FVOtjmCFGVJb5mWNhYoQ== X-Received: by 2002:a05:6602:2c42:b0:6bc:e15d:4c65 with SMTP id x2-20020a0566022c4200b006bce15d4c65mr15615115iov.31.1666391141838; Fri, 21 Oct 2022 15:25:41 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id i17-20020a0566022c9100b006bccaa66ee4sm4882284iow.40.2022.10.21.15.25.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 15:25:41 -0700 (PDT) Date: Fri, 21 Oct 2022 18:25:40 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v3 1/7] shortlog: accept `--date`-related options Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff King Prepare for a future patch which will introduce arbitrary pretty formats via the `--group` argument. To allow additional customizability (for example, to support something like `git shortlog -s --group='%aD' --date='format:%Y-%m' ...` (which groups commits by the datestring 'YYYY-mm' according to author date), we must store off the `--date` parsed from calling `parse_revision_opt()`. Note that this also affects custom output `--format` strings in `git shortlog`. Though this is a behavior change, this is arguably fixing a long-standing bug (ie., that `--format` strings are not affected by `--date` specifiers as they should be). Signed-off-by: Jeff King Signed-off-by: Taylor Blau --- Documentation/git-shortlog.txt | 5 +++++ builtin/shortlog.c | 3 ++- shortlog.h | 2 ++ t/t4201-shortlog.sh | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt index f64e77047b..9ed9d6a9e7 100644 --- a/Documentation/git-shortlog.txt +++ b/Documentation/git-shortlog.txt @@ -47,6 +47,11 @@ OPTIONS Each pretty-printed commit will be rewrapped before it is shown. +--date=:: + Show dates formatted according to the given date string. (See + the `--date` option in the "Commit Formatting" section of + linkgit:git-log[1]). + --group=:: Group commits based on ``. If no `--group` option is specified, the default is `author`. `` is one of: diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 7a1e1fe7c0..53c379a51d 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -211,7 +211,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) ctx.fmt = CMIT_FMT_USERFORMAT; ctx.abbrev = log->abbrev; ctx.print_email_subject = 1; - ctx.date_mode.type = DATE_NORMAL; + ctx.date_mode = log->date_mode; ctx.output_encoding = get_log_output_encoding(); if (!log->summary) { @@ -407,6 +407,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT; log.abbrev = rev.abbrev; log.file = rev.diffopt.file; + log.date_mode = rev.date_mode; if (!log.groups) log.groups = SHORTLOG_GROUP_AUTHOR; diff --git a/shortlog.h b/shortlog.h index 3f7e9aabca..dc388dd459 100644 --- a/shortlog.h +++ b/shortlog.h @@ -2,6 +2,7 @@ #define SHORTLOG_H #include "string-list.h" +#include "date.h" struct commit; @@ -15,6 +16,7 @@ struct shortlog { int in2; int user_format; int abbrev; + struct date_mode date_mode; enum { SHORTLOG_GROUP_AUTHOR = (1 << 0), diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 3095b1b2ff..7547da539d 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -83,6 +83,13 @@ test_expect_success 'pretty format' ' test_cmp expect log.predictable ' +test_expect_success 'pretty format (with --date)' ' + sed "s/SUBJECT/2005-04-07 OBJECT_NAME/" expect.template >expect && + git shortlog --format="%ad %H" --date=short HEAD >log && + fuzz log >log.predictable && + test_cmp expect log.predictable +' + test_expect_success '--abbrev' ' sed s/SUBJECT/OBJID/ expect.template >expect && git shortlog --format="%h" --abbrev=35 HEAD >log && From patchwork Fri Oct 21 22:25:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13015521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7755FC433FE for ; Fri, 21 Oct 2022 22:25:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbiJUWZy (ORCPT ); Fri, 21 Oct 2022 18:25:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbiJUWZq (ORCPT ); Fri, 21 Oct 2022 18:25:46 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CD7A1918A0 for ; Fri, 21 Oct 2022 15:25:45 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id o65so3510792iof.4 for ; Fri, 21 Oct 2022 15:25:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=dpsOH8MNNjaXe8PFoD/jp7TaZ7ac3hJ14pF51hYOfwY=; b=Xf4fLqcICpCCaMruU0saND2MLU5sDuyKEHKDGGMhTv/sPuIhKNnOw7DY019vqlMCqG 404XW5XPiAgRPoY/+QS/QZvsPUdN/Mzo/3SgSBJ/Di/0/ys5QXAknyqJI/Na5Bt3mK6b 4so3vGQRWNdkTua5+mE0O5nPPAxnsda0M4SxFmPcwZKGjMqdsfS543czpsLeOPH/kbay LOzHquPOmha/2PNHzCx30x+18INpHkX8rIu480VHiANEWbEnUM+8addIrgwKPyqd+7KD qmdlho9c718d0+TqMKayoQxuvhS2jcruai1kyDkxk5Sw2kgW2wITp3U6RqvQmzb8f2Yx sS1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=dpsOH8MNNjaXe8PFoD/jp7TaZ7ac3hJ14pF51hYOfwY=; b=0mU+qCIyGpIltpG2x2oGaQYf8UR+5mJhlZGQqLxbj0Q6FgzAx173ACY9PsugHzPTHP 1z9YkFragi8+gu2Or+izSAxrUCnVc8uDACDwU+eBo7uPJCg20UCiIrg9Z+40AgauW2tM VfSpAKAaSdCtC7MRJaPOmz59UmVFq/svUNphUTugc2D3vOxY2QVoqynEDdcBWl8FbssL cKI0FjVknjdo3dr8XeKVOmKPSqfmRg5AcOEsUaqBdyOkTMkDQaN0o8UckN07CHmA77le AYi8CAQQCTDkuck3AsZOPEUCyU+Z9E0H7d5ZRkWzMRq2bvZx5dMPEygIVjOKc3KbvSL+ xudw== X-Gm-Message-State: ACrzQf002nzIOxsJzLIw3hGqlX0ibeD99Zyh0LxnJy4E0LuTIXLxUaO+ WVb6kijPKsepJG2C9lU14fCo5X/1BJt/r0q9 X-Google-Smtp-Source: AMsMyM4H4hLYMLvNoQCisJznPzhdmJr6OCkIkl7OT2tMfS2Wnthkp09b/Yr8HZnaFdhSz4dpEf9knA== X-Received: by 2002:a02:6385:0:b0:36e:ba59:5ded with SMTP id j127-20020a026385000000b0036eba595dedmr354116jac.247.1666391144641; Fri, 21 Oct 2022 15:25:44 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id q9-20020a05663810c900b0034272baf43esm4612776jad.168.2022.10.21.15.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 15:25:44 -0700 (PDT) Date: Fri, 21 Oct 2022 18:25:43 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v3 2/7] shortlog: make trailer insertion a noop when appropriate Message-ID: <25cdc28215973b2bcefb1c14d5415e7a6f163352.1666391136.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When there are no trailers to insert, it is natural that insert_records_from_trailers() should return without having done any work. But instead we guard this call unnecessarily by first checking whether `log->groups` has the `SHORTLOG_GROUP_TRAILER` bit set. Prepare to match a similar pattern in the future where a function which inserts records of a certain type does no work when no specifiers matching that type are given. Signed-off-by: Taylor Blau --- builtin/shortlog.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 53c379a51d..18f0800c82 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -170,6 +170,9 @@ static void insert_records_from_trailers(struct shortlog *log, const char *commit_buffer, *body; struct strbuf ident = STRBUF_INIT; + if (!log->trailers.nr) + return; + /* * Using format_commit_message("%B") would be simpler here, but * this saves us copying the message. @@ -240,9 +243,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) strset_add(&dups, ident.buf)) insert_one_record(log, ident.buf, oneline_str); } - if (log->groups & SHORTLOG_GROUP_TRAILER) { - insert_records_from_trailers(log, &dups, commit, &ctx, oneline_str); - } + insert_records_from_trailers(log, &dups, commit, &ctx, oneline_str); strset_clear(&dups); strbuf_release(&ident); From patchwork Fri Oct 21 22:25:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13015525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DEACC38A2D for ; Fri, 21 Oct 2022 22:26:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229944AbiJUW01 (ORCPT ); Fri, 21 Oct 2022 18:26:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbiJUW0H (ORCPT ); Fri, 21 Oct 2022 18:26:07 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F4B8233987 for ; Fri, 21 Oct 2022 15:26:00 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id y80so3506862iof.3 for ; Fri, 21 Oct 2022 15:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=iqe77xsVoSYKACIEl4ZI0FSatz/GG7p2xIG+FFeF39E=; b=pRWwpTF8xm01Cyehlay9AIIi2iJzq3N63McwCzOXgpot73XpCBJu1/5wLeWHnEVrrf he9YfWkUzrNeEr0Ovm99zpgIfUEp28KvoSUIryR6fTDJZe4K3MwHVLsnA2cp69zqAQCB FEOZhJA7I783xupp97Zq0irIm8eTQETeHm6zBTmgvXi+1QbZaAM1duV9NDW4DS49lLR3 4oy1rrT3QFU/LKx324R9PlQmAalu/T2Sp9ArbeJt9PTsSWAjdjv6N+dZ4FtALosJca8K +UpPgL9rSKy3jgwQGvMXAJCTI9U0HmK5lPkgR4pA/Ypry0D2i2gA9A78DqpgLiL5meYb GNNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iqe77xsVoSYKACIEl4ZI0FSatz/GG7p2xIG+FFeF39E=; b=ZQJe8R9Xb6agW3b1F1MylLPHGbfxANgDdDMp/iRt5DD2EGT8CHx8+LplkyLOQCBJg4 6+XtyXjuaim5Lk9tVhHzKbsT8n1PmZVIT9R2zXbm3pk6epz9csHrIELoTCM+l7yiLbpx j+yKS7HUMDx1+9pwLC/MrNd1QjmK6RIUYlHJc8enR8FP6g8PQilfJfaoXJxChNvVaYbW mT8Df8gP2JrxmWpc+tE7ql4URuZWyuu9a8bKMw8WR6TQee0gE2KkqEmus63lJLjFcemE w+dFUGjBz45BaqPJ6xajs9YDEfAXOF6zbv83QAIrmCcklrFSrxUPU4h6Tg858pEohS3e UyPw== X-Gm-Message-State: ACrzQf1qH9CWmxG6khjvfr3umoMCs2rgMYBW2OKiikuYARPQEtWNjlW2 AYaoFGCSMaNrjUL7PFpF15IUuAG6T4VK2IeJ X-Google-Smtp-Source: AMsMyM6SPG3kQnM5abmjP8ceUS6tBNqVzgILphbiBBgA+KcVIhUXz9J7dI+Xuyy1gFXEpxOEJY7yDQ== X-Received: by 2002:a02:cf05:0:b0:363:a207:c3ff with SMTP id q5-20020a02cf05000000b00363a207c3ffmr16387999jar.178.1666391147653; Fri, 21 Oct 2022 15:25:47 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id i16-20020a92c950000000b002e949936411sm4449125ilq.26.2022.10.21.15.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 15:25:47 -0700 (PDT) Date: Fri, 21 Oct 2022 18:25:46 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v3 3/7] shortlog: extract `--group` fragment for translation Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The subsequent commit will add another unhandled case in `read_from_stdin()` which will want to use the same message as with `--group=trailer`. Extract the "--group=trailer" part from this message so the same translation key can be used for both cases. Signed-off-by: Taylor Blau --- builtin/shortlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 18f0800c82..d0645769d7 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -132,7 +132,7 @@ static void read_from_stdin(struct shortlog *log) match = committer_match; break; case SHORTLOG_GROUP_TRAILER: - die(_("using --group=trailer with stdin is not supported")); + die(_("using %s with stdin is not supported"), "--group=trailer"); default: BUG("unhandled shortlog group"); } From patchwork Fri Oct 21 22:25:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13015522 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 927FDC38A2D for ; Fri, 21 Oct 2022 22:26:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbiJUW0C (ORCPT ); Fri, 21 Oct 2022 18:26:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbiJUWZv (ORCPT ); Fri, 21 Oct 2022 18:25:51 -0400 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA1F2204ACC for ; Fri, 21 Oct 2022 15:25:50 -0700 (PDT) Received: by mail-io1-xd2e.google.com with SMTP id i65so3552023ioa.0 for ; Fri, 21 Oct 2022 15:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mSopvb+1Nn824ZFphSMRXWhfBJc8qAxPlN76pRZxzbU=; b=tb8myT3JLt3N4LXkyb65Wjp35MliP30qPHdw7Gah/Kbkm8xmfWqYJ22q+Cin16zO4W FJIiwlltb/suvN7Uphj11dj76lFttQ5w1skPEdDk807qRTZuz6Ze2kxMPws02WJp16kl 2NeW4AwcpDjrvvqsxSayLCTzDjSOd4X145lPl/Vo2iAHE1ZHig6feX2k73bq4deWZgFH wUWHfOl/lpkrZau1tFndIazJgZUf2tIUhPftxDErMLkUSRlorsIRxQHOprMrBBhte4s7 2PB1acbgwlvDf5jvLj757NywF+WzFo80mbJh/in13MmqILcwkm30yf6LCGVBzIBoa56s 2VPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mSopvb+1Nn824ZFphSMRXWhfBJc8qAxPlN76pRZxzbU=; b=Jqp0NMa28kdaovrYBDW8eIRxcVONGeIVtEQg/ga2/koRI7UEhmV8wkAwooBOkLfkSd XXyYVDzAp/CAIq4bdjgZEzDpUs5NmtnJ6FvsubbTQa3vWK1jfIJ8U6Mq3FbiHU6m2gRO 50ZAkgjJauZCNFLhT/EQ7XQ4eMi7lB7MCpPrAzwXy4HMqQ7VD0PHQJumsxRMU7iemUtf Mlsnk0IXObpPKjgRF7Jwg1465ArY8wOFbocSot4rPyJpgZURmfDvOd6P6HVf/bKmSDxM 5eZSFqN8+RObBCb6wCpOtlTdrKbgOtP5k2J7yd9No/4odX23cO67gbul2o/ckvT1F/ub 1Itg== X-Gm-Message-State: ACrzQf2Qx/d3EMoxZfjPvUSijtDj8Xd6eVlUP7lY5jaAl/TXq/7bAqyQ cx09qmUh8+QPm7Vw+v8z08wqcHROVLLLQYRh X-Google-Smtp-Source: AMsMyM76gN5NofJNxy6Iqre9HS4w1/X0s+ssQJogpC3JpjVSjDSqUQ2rcZzn5kNauycv2FGvWa/O/g== X-Received: by 2002:a05:6602:2c02:b0:690:b560:7fae with SMTP id w2-20020a0566022c0200b00690b5607faemr14487614iov.169.1666391150331; Fri, 21 Oct 2022 15:25:50 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id q7-20020a056638040700b00363d1aa7515sm4762703jap.16.2022.10.21.15.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 15:25:50 -0700 (PDT) Date: Fri, 21 Oct 2022 18:25:49 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v3 4/7] shortlog: support arbitrary commit format `--group`s Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In addition to generating a shortlog based on committer, author, or the identity in one or more specified trailers, it can be useful to generate a shortlog based on an arbitrary commit format. This can be used, for example, to generate a distribution of commit activity over time, like so: $ git shortlog --group='%cd' --date='format:%Y-%m' -s v2.37.0.. 117 2022-06 274 2022-07 324 2022-08 263 2022-09 7 2022-10 Arbitrary commit formats can be used. In fact, `git shortlog`'s default behavior (to count by commit authors) can be emulated as follows: $ git shortlog --group='%aN <%aE>' ... and future patches will make the default behavior (as well as `--committer`, and `--group=trailer:`) special cases of the more flexible `--group` option. Note also that the SHORTLOG_GROUP_FORMAT enum value is used only to designate that `--group:` is in use when in stdin mode to declare that the combination is invalid. Signed-off-by: Taylor Blau --- Documentation/git-shortlog.txt | 5 ++++- builtin/shortlog.c | 41 +++++++++++++++++++++++++++++++++- shortlog.h | 2 ++ t/t4201-shortlog.sh | 32 ++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt index 9ed9d6a9e7..7d0277d033 100644 --- a/Documentation/git-shortlog.txt +++ b/Documentation/git-shortlog.txt @@ -50,7 +50,7 @@ OPTIONS --date=:: Show dates formatted according to the given date string. (See the `--date` option in the "Commit Formatting" section of - linkgit:git-log[1]). + linkgit:git-log[1]). Useful with `--group=format:`. --group=:: Group commits based on ``. If no `--group` option is @@ -64,6 +64,9 @@ OPTIONS example, if your project uses `Reviewed-by` trailers, you might want to see who has been reviewing with `git shortlog -ns --group=trailer:reviewed-by`. + - `format:`, any string accepted by the `--format` option of + 'git log'. (See the "PRETTY FORMATS" section of + linkgit:git-log[1].) + Note that commits that do not include the trailer will not be counted. Likewise, commits with multiple trailers (e.g., multiple signoffs) may diff --git a/builtin/shortlog.c b/builtin/shortlog.c index d0645769d7..a52288acab 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -133,6 +133,8 @@ static void read_from_stdin(struct shortlog *log) break; case SHORTLOG_GROUP_TRAILER: die(_("using %s with stdin is not supported"), "--group=trailer"); + case SHORTLOG_GROUP_FORMAT: + die(_("using %s with stdin is not supported"), "--group=format"); default: BUG("unhandled shortlog group"); } @@ -203,6 +205,32 @@ static void insert_records_from_trailers(struct shortlog *log, unuse_commit_buffer(commit, commit_buffer); } +static int shortlog_needs_dedup(const struct shortlog *log) +{ + return log->format.nr > 1 || log->trailers.nr; +} + +static void insert_records_from_format(struct shortlog *log, + struct strset *dups, + struct commit *commit, + struct pretty_print_context *ctx, + const char *oneline) +{ + struct strbuf buf = STRBUF_INIT; + struct string_list_item *item; + + for_each_string_list_item(item, &log->format) { + strbuf_reset(&buf); + + format_commit_message(commit, item->string, &buf, ctx); + + if (!shortlog_needs_dedup(log) || strset_add(dups, buf.buf)) + insert_one_record(log, buf.buf, oneline); + } + + strbuf_release(&buf); +} + void shortlog_add_commit(struct shortlog *log, struct commit *commit) { struct strbuf ident = STRBUF_INIT; @@ -244,6 +272,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) insert_one_record(log, ident.buf, oneline_str); } insert_records_from_trailers(log, &dups, commit, &ctx, oneline_str); + insert_records_from_format(log, &dups, commit, &ctx, oneline_str); strset_clear(&dups); strbuf_release(&ident); @@ -315,6 +344,7 @@ static int parse_group_option(const struct option *opt, const char *arg, int uns if (unset) { log->groups = 0; string_list_clear(&log->trailers, 0); + string_list_clear(&log->format, 0); } else if (!strcasecmp(arg, "author")) log->groups |= SHORTLOG_GROUP_AUTHOR; else if (!strcasecmp(arg, "committer")) @@ -322,8 +352,15 @@ static int parse_group_option(const struct option *opt, const char *arg, int uns else if (skip_prefix(arg, "trailer:", &field)) { log->groups |= SHORTLOG_GROUP_TRAILER; string_list_append(&log->trailers, field); - } else + } else if (skip_prefix(arg, "format:", &field)) { + log->groups |= SHORTLOG_GROUP_FORMAT; + string_list_append(&log->format, field); + } else if (strchr(arg, '%')) { + log->groups |= SHORTLOG_GROUP_FORMAT; + string_list_append(&log->format, arg); + } else { return error(_("unknown group type: %s"), arg); + } return 0; } @@ -341,6 +378,7 @@ void shortlog_init(struct shortlog *log) log->in2 = DEFAULT_INDENT2; log->trailers.strdup_strings = 1; log->trailers.cmp = strcasecmp; + log->format.strdup_strings = 1; } int cmd_shortlog(int argc, const char **argv, const char *prefix) @@ -481,4 +519,5 @@ void shortlog_output(struct shortlog *log) log->list.strdup_strings = 1; string_list_clear(&log->list, 1); clear_mailmap(&log->mailmap); + string_list_clear(&log->format, 0); } diff --git a/shortlog.h b/shortlog.h index dc388dd459..4850a8c30f 100644 --- a/shortlog.h +++ b/shortlog.h @@ -22,8 +22,10 @@ struct shortlog { SHORTLOG_GROUP_AUTHOR = (1 << 0), SHORTLOG_GROUP_COMMITTER = (1 << 1), SHORTLOG_GROUP_TRAILER = (1 << 2), + SHORTLOG_GROUP_FORMAT = (1 << 3), } groups; struct string_list trailers; + struct string_list format; int email; struct string_list mailmap; diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 7547da539d..8e4effebdb 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -244,6 +244,26 @@ test_expect_success 'shortlog --group=trailer:signed-off-by' ' test_cmp expect actual ' +test_expect_success 'shortlog --group=format' ' + git shortlog -s --date="format:%Y" --group="format:%cN (%cd)" \ + HEAD >actual && + cat >expect <<-\EOF && + 4 C O Mitter (2005) + 1 Sin Nombre (2005) + EOF + test_cmp expect actual +' + +test_expect_success 'shortlog --group= DWIM' ' + git shortlog -s --date="format:%Y" --group="%cN (%cd)" HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'shortlog bogus --group' ' + test_must_fail git shortlog --group=bogus HEAD 2>err && + grep "unknown group type" err +' + test_expect_success 'trailer idents are split' ' cat >expect <<-\EOF && 2 C O Mitter @@ -326,6 +346,18 @@ test_expect_success 'shortlog can match multiple groups' ' test_cmp expect actual ' +test_expect_success 'shortlog can match multiple format groups' ' + GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" \ + git commit --allow-empty -m "identical names" && + test_tick && + cat >expect <<-\EOF && + 2 A U Thor + 1 C O Mitter + EOF + git shortlog -ns --group="%cn" --group="%an" -2 HEAD >actual && + test_cmp expect actual +' + test_expect_success 'set up option selection tests' ' git commit --allow-empty -F - <<-\EOF subject From patchwork Fri Oct 21 22:25:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13015523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2850C433FE for ; Fri, 21 Oct 2022 22:26:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229897AbiJUW0H (ORCPT ); Fri, 21 Oct 2022 18:26:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbiJUW0C (ORCPT ); Fri, 21 Oct 2022 18:26:02 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7442F24AE25 for ; Fri, 21 Oct 2022 15:25:54 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id 137so3476409iou.9 for ; Fri, 21 Oct 2022 15:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=im6pf5qn5BQrDBjTVWszBsBsCVfSJjB/xDbDqCvcY78=; b=2vrSwCCp13nKHLWV7VG33zvag5jUC7whjF/jZQT6Q9jAWqRkPowVg5G5VYTAGXEQkU +oGQ57Pnlo+NybCpJVu8SE7YZMfFJrLvO6n3AZbOcdgnFkvTvgyfcY6XB4D+WgRFaaaE d/aDwmJRdet4sdd0NpgNT9/WWFTakRw6q9fzi0mouTp91ArKIMqNd9zCbos15xF2GprK P+xFhgz/cX5e3Yh5m6zgGavduxtcOJh+bVogbQoyNa5p+RfKlkZAB6+VQmfW+uhNoCh4 Y9iPWmpGFXBJzI+F+U94Ouew/+sY8eHjIkvmQx9fE8I40tyNyVOB8794+4HFxVmyNXkY 6Rmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=im6pf5qn5BQrDBjTVWszBsBsCVfSJjB/xDbDqCvcY78=; b=jqCXQT737GwvDrmt6vdfhrMIPTAY1k5hUEevWwcgWYq9SjgfwQlC+9CljKDq/PE7t6 2rIUdRee2UjVoMtjVMUr32gFHlwGoIi6PHyyTKY0MqbwPJRF8iaKDjbyHLiAqRBAX6CC VAalw0tfVj5DcuizJTJ6o+nMwa5uUeFCmrD2JHX4UFAr7z0AGtjNX9LiqdOcbcXfWXCr pfbIz9qQ7vqIel8R1SgdOmq6K700gV0fFvQKHqteFP5NbKIb3VJRzWeK8p21h7+0U3rD Yq1FFsqxp6q+lWpHOTqA1KDF6jtm5RiLArYY9UPuR0KUGHWGHkCokYO+8x57h3//mV3j 1YMg== X-Gm-Message-State: ACrzQf1BlaaHR1HdhlaIh0TBLvQ8OM3zCHtA8pLmr/OJwZE9u1LBmG4C mZk5+DLmu4mswqX0JpaiAeY13lDOSIZ90qyr X-Google-Smtp-Source: AMsMyM76fupcJTQEUHP5IJBd10ijRjJJeGD+0qNiHG/sorh9M9RZNFo5YHqwXc6Va9Xi1US/Rp0T4Q== X-Received: by 2002:a05:6638:12c2:b0:364:158f:7263 with SMTP id v2-20020a05663812c200b00364158f7263mr16384238jas.269.1666391153084; Fri, 21 Oct 2022 15:25:53 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id f4-20020a056602088400b006bb57cfcb88sm4999316ioz.44.2022.10.21.15.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 15:25:52 -0700 (PDT) Date: Fri, 21 Oct 2022 18:25:51 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v3 5/7] shortlog: extract `shortlog_finish_setup()` Message-ID: <8dd69edcf8cd15c631138cb6bdc130c5da808870.1666391136.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Extract a function which finishes setting up the shortlog struct for use. The caller in `make_cover_letter()` does not care about trailer sorting, so it isn't strictly necessary to add a call there in this patch. But the next patch will add additional functionality to the new `shortlog_finish_setup()` function, which the caller in `make_cover_letter()` will care about. Signed-off-by: Taylor Blau --- builtin/log.c | 1 + builtin/shortlog.c | 7 ++++++- shortlog.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/builtin/log.c b/builtin/log.c index ee19dc5d45..b4d5420217 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1334,6 +1334,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file, log.in2 = 4; log.file = rev->diffopt.file; log.groups = SHORTLOG_GROUP_AUTHOR; + shortlog_finish_setup(&log); for (i = 0; i < nr; i++) shortlog_add_commit(&log, list[i]); diff --git a/builtin/shortlog.c b/builtin/shortlog.c index a52288acab..ebf2bf3d3b 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -381,6 +381,11 @@ void shortlog_init(struct shortlog *log) log->format.strdup_strings = 1; } +void shortlog_finish_setup(struct shortlog *log) +{ + string_list_sort(&log->trailers); +} + int cmd_shortlog(int argc, const char **argv, const char *prefix) { struct shortlog log = { STRING_LIST_INIT_NODUP }; @@ -450,7 +455,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) if (!log.groups) log.groups = SHORTLOG_GROUP_AUTHOR; - string_list_sort(&log.trailers); + shortlog_finish_setup(&log); /* assume HEAD if from a tty */ if (!nongit && !rev.pending.nr && isatty(0)) diff --git a/shortlog.h b/shortlog.h index 4850a8c30f..28d04f951a 100644 --- a/shortlog.h +++ b/shortlog.h @@ -33,6 +33,7 @@ struct shortlog { }; void shortlog_init(struct shortlog *log); +void shortlog_finish_setup(struct shortlog *log); void shortlog_add_commit(struct shortlog *log, struct commit *commit); From patchwork Fri Oct 21 22:25:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13015524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56379C38A2D for ; Fri, 21 Oct 2022 22:26:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbiJUW0M (ORCPT ); Fri, 21 Oct 2022 18:26:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbiJUW0F (ORCPT ); Fri, 21 Oct 2022 18:26:05 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5539B1BB554 for ; Fri, 21 Oct 2022 15:25:58 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id y17so2390621ilq.8 for ; Fri, 21 Oct 2022 15:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=h/GiXiCUojIvEAZIVZPMDyEUyrAGsES8iWuEromJJ9g=; b=GGjx3VtfTUaM4psQ3puvP7VXPk1iXH8keEcwdJqAi1qRqyx2GysYPk/xOutAjxEv6Y fyHV6jvxW1bHb7rl75O9Z2eq1xiyeQ9HO1cyVucCPfY7Bo6IHhefLsv8Hk8w34PGXrd6 xvrSAn41DRnlvMxwvj/Dq6jFwoTmsu35ZmCxnUdq3U+FCXheMWlTNLfd3fPLRuAMth9/ pZE4ZwoOb+WL62qxzinWP42wd3Hteqf24SXWRpSM2PmW0OS6rCJ+AYcQax8yD4xlpE23 QalYelUnLD8QFHTwKOVZyi4pBitQaGV0S3uz49pVEIfs4i8nbd654tMIwo34jFGwkmiJ C5lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=h/GiXiCUojIvEAZIVZPMDyEUyrAGsES8iWuEromJJ9g=; b=Z34by/RxZuwT0/XqXvlcg23qPLxWu1Px8LouCixpT7SO5sDZc7RFZ+eH1CD/H5Yd3M 87aQyNjCrlW8398RTyKWDIM85Vp0Iw8WAnlmPQ2ILwjuhhbNzK7Lplz18NkxAbEEl7nB p51QDejqN7Kmn2GK/3ChKJYc2HHyr7MWnTJQ3WtHFulfrOW0dTUty8jLF8VwuHZuvxYg 1kY7phYRqadE2sqV+EAGXZL03D560IDWphscMS+p3ejDVJZH2X1fd5JP6/8kmneSK2uM bnNOv/dPZaHsen5q6yv0hlxkrTOZNudDnz1BwQctR9LapqSU+YrLVqWu1SS5VEuHfiQe Nocw== X-Gm-Message-State: ACrzQf16CsWRl+1Q9Hjm8BMnPlkPCyZRbobJnuRwXBHwV5ayUqbKE/T/ SxL9bsKlH72udhrGtg+BaULSDWerqhionXN4 X-Google-Smtp-Source: AMsMyM4iA5rwyED8qjzee1OpJB167lBRZMPjvnUPxqpzQiDEUThnQcpeusVq9V4eC89+2jpZGF8jhg== X-Received: by 2002:a05:6e02:1946:b0:2fa:b248:47e9 with SMTP id x6-20020a056e02194600b002fab24847e9mr14610779ilu.153.1666391155907; Fri, 21 Oct 2022 15:25:55 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id c1-20020a92cf01000000b002fc681a6ad8sm4447583ilo.78.2022.10.21.15.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 15:25:55 -0700 (PDT) Date: Fri, 21 Oct 2022 18:25:54 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v3 6/7] shortlog: implement `--group=author` in terms of `--group=` Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of handling SHORTLOG_GROUP_AUTHOR separately, reimplement it as a special case of the new `--group=` mode, where the author mode is a shorthand for `--group='%aN <%aE>'. Note that we still need to keep the SHORTLOG_GROUP_AUTHOR enum since it has a different meaning in `read_from_stdin()`, where it is still used for a different purpose. Signed-off-by: Taylor Blau --- builtin/shortlog.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index ebf2bf3d3b..4b95820bca 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -253,15 +253,6 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) } oneline_str = oneline.len ? oneline.buf : ""; - if (log->groups & SHORTLOG_GROUP_AUTHOR) { - strbuf_reset(&ident); - format_commit_message(commit, - log->email ? "%aN <%aE>" : "%aN", - &ident, &ctx); - if (!HAS_MULTI_BITS(log->groups) || - strset_add(&dups, ident.buf)) - insert_one_record(log, ident.buf, oneline_str); - } if (log->groups & SHORTLOG_GROUP_COMMITTER) { strbuf_reset(&ident); format_commit_message(commit, @@ -383,6 +374,10 @@ void shortlog_init(struct shortlog *log) void shortlog_finish_setup(struct shortlog *log) { + if (log->groups & SHORTLOG_GROUP_AUTHOR) + string_list_append(&log->format, + log->email ? "%aN <%aE>" : "%aN"); + string_list_sort(&log->trailers); } From patchwork Fri Oct 21 22:25:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13015526 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CA3EC38A2D for ; Fri, 21 Oct 2022 22:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbiJUW0b (ORCPT ); Fri, 21 Oct 2022 18:26:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229649AbiJUW0I (ORCPT ); Fri, 21 Oct 2022 18:26:08 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D5DE232E55 for ; Fri, 21 Oct 2022 15:26:01 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id n73so3463791iod.13 for ; Fri, 21 Oct 2022 15:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XacoFaubAe+xFBWIvyw51mFWJwxSc1YnWe8ybySpMUc=; b=hiWEdEUNL/X5yVNq/pLNskkJjjeHOFsuhcmo2zOME0e9rq4+ZcaxAFucOMJNpPffci dQDmGFyQQ9GQhVXN9LHy5XCLshxnoxSrtYPw+XPcfZCUJLm/9pu3huUiD2r0jPBqbvze WXVm4MNLt3Kwf5Kb3xbJHf27Sr+Nw1+v+0DAY9p6/VCiQN4mCnobxN5nOM8QEOdhGyIn KWL100cHqEZfd//Hb4LEV5ogN2QikzR2rKMUrRiah95rZWQ25QUkaCOpHEb3Np+y7h3K ID7cgvcdjGAo65KDRbspQ36me/PPNQzDx/UVv8cEvTPzCi0Ok39RHXg07ZTdNquFaaBv aTcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XacoFaubAe+xFBWIvyw51mFWJwxSc1YnWe8ybySpMUc=; b=RTRKtL+sjdzeX7pIcIK1k6ASMu0XDLpcwM3wF3ZjrvT4ezDmaPVqF/E/tapT33epFl PPEbbFxxaDKrCWeVMmo6xiQdtouAPvpNCkI2nUf7ugnbpzSc95Be6cJohix/K1yR7+6S K17lCxbymqlq9Ijp6a8Ko4txzUHX3egwFwe1EFgMVhOSoBNFxQQqkpRC2aFhjcDjOTYV 7Xlth20NewLY+CvMPAwj7i0towGQENcwsbLitXVEFD5LYXiVp8eyW4JF9LeBEEJBtDXP o/VT2K+TYuqKfJEv1TL/AMopR0l2fhjF4/JYfH/zPyQf2Yl9St4pfECyHO9xK18+d4MC fXPg== X-Gm-Message-State: ACrzQf0hN8TM8rP22VW9FwpHzG17inABR8Z3vVvEKZJy2T0U4l2Vh23K JxHbzXYu/0UPOtUrLVAKDNE6s6i9qGAlywXe X-Google-Smtp-Source: AMsMyM5OjDyNaKHZbmTL08dyQwRz21v6C7wophQxoSmnD7mJ5oVPPEndR4tVoIJ3y1sMQx2SYikh0A== X-Received: by 2002:a6b:3ec3:0:b0:6bb:d3ac:61d4 with SMTP id l186-20020a6b3ec3000000b006bbd3ac61d4mr14713209ioa.160.1666391158732; Fri, 21 Oct 2022 15:25:58 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id a18-20020a027352000000b0036348f096acsm4696457jae.6.2022.10.21.15.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 15:25:58 -0700 (PDT) Date: Fri, 21 Oct 2022 18:25:57 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v3 7/7] shortlog: implement `--group=committer` in terms of `--group=` Message-ID: <6ce06a054eb0cf10f59ecd1526671a40c8908edb.1666391136.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the same spirit as the previous commit, reimplement `--group=committer` as a special case of `--group=`, too. Signed-off-by: Taylor Blau --- builtin/shortlog.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 4b95820bca..27b057940d 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -233,7 +233,6 @@ static void insert_records_from_format(struct shortlog *log, void shortlog_add_commit(struct shortlog *log, struct commit *commit) { - struct strbuf ident = STRBUF_INIT; struct strbuf oneline = STRBUF_INIT; struct strset dups = STRSET_INIT; struct pretty_print_context ctx = {0}; @@ -253,20 +252,10 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) } oneline_str = oneline.len ? oneline.buf : ""; - if (log->groups & SHORTLOG_GROUP_COMMITTER) { - strbuf_reset(&ident); - format_commit_message(commit, - log->email ? "%cN <%cE>" : "%cN", - &ident, &ctx); - if (!HAS_MULTI_BITS(log->groups) || - strset_add(&dups, ident.buf)) - insert_one_record(log, ident.buf, oneline_str); - } insert_records_from_trailers(log, &dups, commit, &ctx, oneline_str); insert_records_from_format(log, &dups, commit, &ctx, oneline_str); strset_clear(&dups); - strbuf_release(&ident); strbuf_release(&oneline); } @@ -377,6 +366,9 @@ void shortlog_finish_setup(struct shortlog *log) if (log->groups & SHORTLOG_GROUP_AUTHOR) string_list_append(&log->format, log->email ? "%aN <%aE>" : "%aN"); + if (log->groups & SHORTLOG_GROUP_COMMITTER) + string_list_append(&log->format, + log->email ? "%cN <%cE>" : "%cN"); string_list_sort(&log->trailers); }