From patchwork Mon Oct 24 18:55:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13018139 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 0B9E2C67871 for ; Mon, 24 Oct 2022 20:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235154AbiJXUub (ORCPT ); Mon, 24 Oct 2022 16:50:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235472AbiJXUtg (ORCPT ); Mon, 24 Oct 2022 16:49:36 -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 DB18F52DE5 for ; Mon, 24 Oct 2022 11:56:54 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id l127so8482795iof.12 for ; Mon, 24 Oct 2022 11:56: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=uPNL/OcdIuambt0Tm/HNOVTgI32GrLe4U2yhDI/QHxw=; b=uWLs/KMntVyxhQ0aQpuo99zbcozZgVP53P8bzatRsRam1QuJF5eebo8qHQ3UOu4pUI iHU1aaX40L/6ZWImJuINh0z62G+JuvMpW0zErtvg/KDlzY/g1P/oksbMVcg3B1JWwJbT tUT9QH4jX/FXvUJoyA1wzQ8ej8Zrzu8hBst/UEltGuV5u1ICGb9b4FIDRfVEwk+ynL5O HV5OJvg9h+Ztx1t51BgNes6e9PqKRrrc+hx6JflxzbwXJwsHeerT8YqnGEWXQBbhlrEf ah4s+lgN/LEDZg0RdOVfWCtbqOjcC/SCZ/xJImYVJ3kQiMivbSZ0wjkOelMgs0IVn+Np +2lQ== 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=7NEy9slQtfINx9QFb/xxGrlEES8ueLK5wABa6mcFiztdrEZ5VTlXVns87aVWu0PoRW BhYCVyUXyDsa3ieb/2CCAAVsRpoxb+szb7zHW8rQrSOfEsE5IsRzdlnUjc1RwK661rPL MXCP+6VCgAsWhAWmspsTOnIOLTBg9xEMnhiByXtz+y37ifFd9iR3Pj0FMTQvcCV0QaXN nBlea6h3n5Dcctyplog38lAltsEnWbI2dz6hgAx6lRMCBp6fYOMZzW4+0+Kgg17+SMG/ 43BHxrVoH92sKqNm13lFSQvNnhkusJKaz/+ZyLWWnJphHemPxDvHPY0fTM/bLlc7QDgk HUkw== X-Gm-Message-State: ACrzQf1aUfxHEOHXN5oxBvXxQqvlviZNnRO9nnEmZSoonqEZJnlvuUDC 3TWD92MuCwhAEolBMavAsaL6vYL+irPwPK/5 X-Google-Smtp-Source: AMsMyM4W/5lQU+0t2foqOTRBlYTyXaUAV69oRXkuyQm52ip1/p4G5WrIBngrJoq7JFkeMoVLfX4Y8w== X-Received: by 2002:a02:3548:0:b0:362:4000:9010 with SMTP id y8-20020a023548000000b0036240009010mr22927861jae.69.1666637731646; Mon, 24 Oct 2022 11:55:31 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id n20-20020a02a194000000b00349d33a92a2sm83658jah.140.2022.10.24.11.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 11:55:30 -0700 (PDT) Date: Mon, 24 Oct 2022 14:55:30 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jacob Stopak , Jeff King , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Subject: [PATCH 1/7] shortlog: accept `--date`-related options Message-ID: <38b60641c0f09a4cc6f8a9a69faafe8e3bd7635f.1666637725.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 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 Mon Oct 24 18:55:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13018181 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 94FC9C38A2D for ; Mon, 24 Oct 2022 21:50:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230052AbiJXVuv (ORCPT ); Mon, 24 Oct 2022 17:50:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiJXVuX (ORCPT ); Mon, 24 Oct 2022 17:50:23 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A98A2F090C for ; Mon, 24 Oct 2022 13:03:20 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id g13so5783502ile.0 for ; Mon, 24 Oct 2022 13:03:19 -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=QF7vN0W8oYtDC1N4rCk189pB9J/1Td07nSZcjJbGPAifby1YsiBr7ux3r7wDSkU3RS 1/BYwUzzVTEVolbuTci7d5Lmmr4QG7FaZSNLvFchylZ+jpX7VFihPOa7V5SSZYVjPENb rEFVAzVyY1LP8Zz0PTEhpWmonmgaWVpRroUAecaLfeNxPjdBNzRgIKCs3BzfPM9Y8ARs 6MBgte8QSF8sIgXz5m1UFI8yq3ifZUpJVLAaOIXZeN7iDq1rbWZxY2jvseF5utL4iUt0 7WtM1uUPGAhMZct56Kih0uAOcoRaUd7+a+AXTICqePxmq//jXkmlT24IucLaSgg2feT8 C26g== 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=HitDNUV2JpPsip6B4Wp3Fe/8bB4VZ7aU872I5rgrYdDCy7ezxZN7QdHMmXubXr84zv +J++OYaKHbZmvfWufzRR1UmWVa5UC8GQOHk3QbpN4MXiG6hlhM/zHV5IAE2QoMnayoYm ekla3cfixOTS3WuySe4vTOuYO+IjtKGe7cERYMjIAjIlSCvcm2mIGy8/oJketrgri+yt jNHgB7l0SsUQOEUPhO8vmMKSRnY0f0T6Z2HL0ti9YzwXKbYQzuyitArAU9JdB639ezep eOERjdfkL4B+yRQxcPXx36/OsPgV+HfkBdlJ7WUIUG4fs+dhSLGBAG8Pck1rys+y+iJu gKyg== X-Gm-Message-State: ACrzQf1zRKtBNqV6itGkXcGpN1eK4UaJrMZaUa14ju1yobO8Jadm3JLT QmbpSwfIjdmRIrZ/NdG1yeRp+zKO8k7ydqSd X-Google-Smtp-Source: AMsMyM7eiI2uYWyPXSEpicvMU4oWtrLz/vabKsSJWrnziIoYiL+0QECrxhtXr5p0xulVo73yatqO1g== X-Received: by 2002:a6b:671e:0:b0:6bb:f05a:fb11 with SMTP id b30-20020a6b671e000000b006bbf05afb11mr20427996ioc.74.1666637734636; Mon, 24 Oct 2022 11:55:34 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id o13-20020a056e0214cd00b003001a04f9b9sm247613ilk.12.2022.10.24.11.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 11:55:34 -0700 (PDT) Date: Mon, 24 Oct 2022 14:55:33 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jacob Stopak , Jeff King , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Subject: [PATCH 2/7] shortlog: make trailer insertion a noop when appropriate Message-ID: <2153c6c6649c54588c24db1ace647719ad0431f3.1666637725.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 Mon Oct 24 18:55:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13018138 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 295B2FA373F for ; Mon, 24 Oct 2022 20:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234229AbiJXUtx (ORCPT ); Mon, 24 Oct 2022 16:49:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235260AbiJXUtF (ORCPT ); Mon, 24 Oct 2022 16:49:05 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D5982B6902 for ; Mon, 24 Oct 2022 11:56:31 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id i9so5653564ilv.9 for ; Mon, 24 Oct 2022 11:56:30 -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=xKFeVhUpKti2uytYrueRVBXzdr3dyelghMGtC8gL4H+d2cIT/Je6l41HlEbesZgdz0 m+eOe9+CNa8I1QwlRCxPqHOyvm8bf9zEDngifbYOZCBwMbyk1RQO9EYv5tpY55iKrwQ9 uw2+3e//oW2y86HFGerhx+0zTqOXTcZgJet+3nWcHC2voCv0ECT6dCELHwu5C/LBsc57 IKfffSXf7ARpH5CFow4WSXLrn7zcyuW7unWeh+hPzCe3U1AclgRH6mRZ8YhRiaWP45c9 TBC0XNj3GtHPrf01a3dAzloCIiwj8D5boiv7SfKJvyW8aNK/jPDSZJhxqbGrh1IsR+sG NUrA== 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=WI9JDDfzHKzG6xy7zvLEHAZleVpy/Q2YnHh+0+H6Qyio3/+Ir55V2jUsFD7L3Lo2/2 mVTVyIwV1bwTrmxyfASUS0W4Y0fZkJ1stcpAskmcvP4GdzvGxIDFU9IRlNo/eK4rLmba whsMCgWKXxC6uo8TTJNbOUY41ot8v4FX3B3b8c/SgvT14tGbFAxX7aNyP4NOIcjb9E4E 64fkvFv8fanPEJPbUg0ykq1tih0peH1c4Zj38Vpvp0bP9QLZtLrGEsDaiHCavSpjMqnt 3F9WvgUrMWGdS1VihrkgulneJpddIyJaGf1cgCa0Oz7r/QIfZdhW7b1eKiUCzBT+7hpF y1FQ== X-Gm-Message-State: ACrzQf1qH4/EnWTzjGv18+Uu0j3cCGLGoMZCu7+2ptu44gVDfKoF/1Vi asz5iJ8jGNX7+k1W8rJ3D8uIzCnDijczHTrz X-Google-Smtp-Source: AMsMyM6TSwF9N0ZIXISv16Rm7L79kr6nlBoCgE6sa5wCBEb2PKobtTgF6gqN3RlkIuwXzTgnxGKpCA== X-Received: by 2002:a05:6e02:158a:b0:2d3:f198:9f39 with SMTP id m10-20020a056e02158a00b002d3f1989f39mr22997001ilu.206.1666637737450; Mon, 24 Oct 2022 11:55:37 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id a95-20020a029468000000b00363bd76184esm81900jai.162.2022.10.24.11.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 11:55:36 -0700 (PDT) Date: Mon, 24 Oct 2022 14:55:36 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jacob Stopak , Jeff King , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Subject: [PATCH 3/7] shortlog: extract `--group` fragment for translation Message-ID: <987a8484ac457cf16aa07e0411dcc4bbca83b06b.1666637725.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 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 Mon Oct 24 18:55:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13018137 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 62D12FA373F for ; Mon, 24 Oct 2022 20:49:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234365AbiJXUtw (ORCPT ); Mon, 24 Oct 2022 16:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235389AbiJXUtV (ORCPT ); Mon, 24 Oct 2022 16:49:21 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7676B2B76AE for ; Mon, 24 Oct 2022 11:56:34 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id n73so8459736iod.13 for ; Mon, 24 Oct 2022 11:56:34 -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=HG7Zjqk48NTmcEW1096NR7eZ1DiVQhQGPNTDxQKNLgk=; b=uL9AkU7Y3ZmSEEAUHie/4+Otr5GKUfigE7wHryC5YdOwToUM7dE/yLT9Kbok9oXLgX e23F3qXnK178Fy8rjybc0kUNNtAFWovgvR9V9rvwMXRicOlMG1N8GmHv+bScDnP7jexA TibBbMFAzr/UdUiclpdm2Uv/miP3EXRAKcOKHvzdBNkSlI0ainRqWYJze5aPjuKELCQf tVqm3asy4VNlHxlHUFN5X3934Etkh+HSLXq2CnXYO4e5LFpvk7VsqhVIT5ol3o1bBuJD 2rJMjsxTcUw9D+jN20HTu7eyBThzUs/SlyiP5pUK52JLygLLCLF/SGqKVO7UrPBFuHx6 4r6A== 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=HG7Zjqk48NTmcEW1096NR7eZ1DiVQhQGPNTDxQKNLgk=; b=RV96Dhn6QiPdRgm/IgY8EmcNKL6v2GjdtpUnHVX25oAiCTOPwrmEfV4EGqV2xIonsA ye/E0/YzcdO/hKc9ERrl45nH6pCsbuFUUOWzaOlsFGxWrOfyTWZvgyHTHwy8qtaNi5YV 1Gqrztz+JKH9q7B1xsPk/HSdfDtMH97+gwQDsEI4ek6TbJG6+KEQXMcIQGsnuKwLGtYv rNeFexaMtAOqeXHEeLDY2746cz1Ksxjccd6gMShU35+WKCMuN4Pro7BKpvtPI+VXNEaF kl1BgQ3io+cKdlosbn0/3A80OLxC5bJBUt6BUIayTNPkfe+9/z/4K1SH6bZSFve3/zgg 5Gxg== X-Gm-Message-State: ACrzQf1LJrAQH+rBW+8/yWAUnibJPS4iv1qDoR/Q/a617Tag9CP9fHSA 1OhBm7OFbylixbhSdJISBhzJflnN2ONZctgB X-Google-Smtp-Source: AMsMyM52BJzRpFqRohkKbmMZUbtGc24BcgyR02gQg3nb7NtqvtvlUM06Ju0Xt6DTi0dJvtxDJ2NLvQ== X-Received: by 2002:a05:6602:358f:b0:6bc:bc3b:10cd with SMTP id bi15-20020a056602358f00b006bcbc3b10cdmr20031195iob.63.1666637740277; Mon, 24 Oct 2022 11:55:40 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id i11-20020a92540b000000b002f6699c86eesm222387ilb.68.2022.10.24.11.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 11:55:39 -0700 (PDT) Date: Mon, 24 Oct 2022 14:55:39 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jacob Stopak , Jeff King , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Subject: [PATCH 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..f3b237c5ff 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 HAS_MULTI_BITS(log->groups) || 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 Mon Oct 24 18:55:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13018136 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 F352AFA3744 for ; Mon, 24 Oct 2022 20:49:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234165AbiJXUtt (ORCPT ); Mon, 24 Oct 2022 16:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235353AbiJXUtS (ORCPT ); Mon, 24 Oct 2022 16:49:18 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B454B2B7B78 for ; Mon, 24 Oct 2022 11:56:35 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id g13so5692123ile.0 for ; Mon, 24 Oct 2022 11:56:35 -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=TyHeWTxfGr8Hm/O3/pb8HgpGjoq2yivukCGYdAxs5ko=; b=Iik6CBPyPbKmAI/Ro4EqOJNcTan5iFxIHduXxgqS+YG7HJoxnvbhRiN2mPoYOSNJND jxay3MhvI/CeRbMMZZlgw98GbRhLeQq7YyLPVxZbO4r+5vLymjkuvalWlgsQamz5s5I7 hV72JUumn1ThP+773uDfty0n4LMGdSkJXbxOCKMtESKudRLR2WGp5b+84Ct1j8wjf+Np /kAibpfa3hd6z+bNFEplQ7RRXJm53O9oayIT1FBDXukSRoxXYYCZpVeV5+L95XDUm2p/ PcLrHkdZkIQQpm84NA4yX78xavLXVXEGiMDIpl8tGOV7vObVIkfCDuMf6v59kzn1RdQw 7etg== 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=TyHeWTxfGr8Hm/O3/pb8HgpGjoq2yivukCGYdAxs5ko=; b=is30GnqEWLx/OUTcQoBJGZGTA3bVMAiITMp4AJS90+sgAlR9XFOnWpjkQ0S+99MgX2 boA+JEmsFkxs+sjmZLigH48dbBzU/ilA8qNyVvQyFsWx6TEzb9TUdK94oAjSmQrZPgps epnsteh73Kw6vfCrIE1zSd0U2DBYPuV3AOEBrZjhon0i+GY0AzEy9Thkb7ebMOlYKs7i hOoefl+CYib3v03TRS1IaW7PJ357KiN8nFLt/YOj63/6K4HCwsVMLUlQzT9HiVaDtRRa hCArJwKdvKUTvi/XY5iDqJfCz+2JQbmz/gMXQMhL/qJnCHkUezaE14iQmz12K+dGMAzJ +cGQ== X-Gm-Message-State: ACrzQf0+ZzZoneHgZft991Jw/EyzDBry6ZgIfPt33FRNmjagmGbQt7D9 MR2mQSfToC4oi/wOOmtvNqNRlcSWNHHiVWtB X-Google-Smtp-Source: AMsMyM4AZdU9M/Rua9VHBkr+FsY2sfrJ9BtcFMNvr5fpxjbB40mCrbd0pbsE5T64OjQxnl4A1M0pQw== X-Received: by 2002:a05:6e02:20e9:b0:2ff:f2ee:4a4 with SMTP id q9-20020a056e0220e900b002fff2ee04a4mr3940889ilv.238.1666637742876; Mon, 24 Oct 2022 11:55:42 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id w18-20020a0566022c1200b0069e1bcbddaesm218066iov.16.2022.10.24.11.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 11:55:42 -0700 (PDT) Date: Mon, 24 Oct 2022 14:55:41 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jacob Stopak , Jeff King , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Subject: [PATCH 5/7] shortlog: extract `shortlog_finish_setup()` Message-ID: <3c565450654673134bd4c8584350d475b9f1b38d.1666637725.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 f3b237c5ff..808bae9baa 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 Mon Oct 24 18:55:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13018146 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 3C2D9FA3740 for ; Mon, 24 Oct 2022 20:59:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232161AbiJXU7g (ORCPT ); Mon, 24 Oct 2022 16:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235299AbiJXU7F (ORCPT ); Mon, 24 Oct 2022 16:59:05 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 044CEB48AB for ; Mon, 24 Oct 2022 12:05:10 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id y13so5211936pfp.7 for ; Mon, 24 Oct 2022 12:05:10 -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=/65QXB1aoRxcs4Xsc5r9OGnY0ge7BQ1M2LEBHMwsoVk=; b=SJcbj01m4TgaBuPEtnV0Zw1qExJ+2msR2EWArvxL3V7N0A90xcT+VmeBUjAxIpCkKA 0sfR3Hr0NaOCuqRcKp6R3VEkDCqDmaT0YNJiBTeVNGyxwmHyHijTAwL5/snmUSCOxqgv /PyI1GGc8/RUkXReGknclnmIPjyGVsmrCNHWJoQhkgNxTBMQSFeunwWP46XGSJQzWZgj 9VRSNfdqREqZH2w5dGVDk+fjl4EwHTxz8GnDFlfrqWJrK+LXGnPO8HQG/MLAoafAgf6D EZKhhP9vANLj5zdPVKWlb4cZn5CV/tgfK1dOQyEtm63HvhsAoylk42fcK7zTm/l202Qb arWg== 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=/65QXB1aoRxcs4Xsc5r9OGnY0ge7BQ1M2LEBHMwsoVk=; b=x38CR0yFR8BZBAqDTDbXOMSUlLOATyjIH0bDtTVk0SMoUWvypkK4LSt8ewlKKyZZDm ZDzBF/3wVkKnTeCJpZuBHvBCQeMT6glDF5hPQxHeEbGYi5B0B/Yu/TOLJWHzUVZyCzU2 d8AR4IAnlzsV3xAM/S/zwegImgL80hlGc2fwiMqhA3QWmFQrU6kLGC5q2beYFbq5o6OV aBSPIZkT0IlE+sX4eJZp2wxL9g8wp7kMBBsukg/qARH9gKsKdzuJ2lMa58qRRO2NXAgC hclIEM6hhF7q8BES8ozu16N5jtbOppVacvAyti5S7/RWR+k/52OX9Yds2Uj5YyqJx07u csUg== X-Gm-Message-State: ACrzQf2LAo7D3ZRqPJcWcgzcL08g32zvcNcdVPHQF0updRWBrqPbbKhR V3am7thKrc2dDKTPVst0a7A86OgVtylypoiZ X-Google-Smtp-Source: AMsMyM5WRkLqoZ1K/bOt2lHkpcEaYH9v0upV/STzN2P5ug3yTBok4rcnCrH5eA+7e2XnBfjOGB1x+A== X-Received: by 2002:a05:6e02:2147:b0:300:184b:702f with SMTP id d7-20020a056e02214700b00300184b702fmr2095412ilv.88.1666637745940; Mon, 24 Oct 2022 11:55:45 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id k3-20020a0566022a4300b0067c47eb46desm194864iov.47.2022.10.24.11.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 11:55:45 -0700 (PDT) Date: Mon, 24 Oct 2022 14:55:44 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jacob Stopak , Jeff King , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Subject: [PATCH 6/7] shortlog: implement `--group=author` in terms of `--group=` Message-ID: <6a373815bf5cd92da762c7cf5e40c0cecaa33be5.1666637725.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 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 808bae9baa..f6032c6328 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 Mon Oct 24 18:55:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13018135 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 5154FFA3743 for ; Mon, 24 Oct 2022 20:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233257AbiJXUts (ORCPT ); Mon, 24 Oct 2022 16:49:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235409AbiJXUt1 (ORCPT ); Mon, 24 Oct 2022 16:49:27 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D4382B9BA3 for ; Mon, 24 Oct 2022 11:56:48 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id g13so5692262ile.0 for ; Mon, 24 Oct 2022 11:56:47 -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=D//i2Mlz1KwVuZ4CUuIfv9yXE6tJCqoPCsZuhvzBAlo=; b=ag/AHCRTI1Zc557fsKu0Jrv/XH0nI5kn/rkOhtcFJMUrL6GFedP653iOTEwaz4qnnc P58HbGPZ8jDhPw3+qZIA7tn733yyu0ekSuz2XUpCX71ykDOhEB2+Y72DKubvwyd7FLqp AJyxWeqOcG+Io9G5LLL7fhbHlIDZHbVxOAiXm2oTS/ZPqWLPIzPMRrmwj4UKivOMHRiP hNxmx1KUXB9AjjtVkKb6r0tPKqLM/naLzEZGOrXTlWque5PF9gUCNQqv3lT4JdL8TJPA Y5tOFLeVJ1wuBcJ80rRIvxo0JOUdiOFo/v0Xoon/lhiGGA7Eucuk/Lr+79POn5yIM880 OnhQ== 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=D//i2Mlz1KwVuZ4CUuIfv9yXE6tJCqoPCsZuhvzBAlo=; b=wtqDFExG1zBe0/2o6Z37OLDmOLnBj92bai+AWY+tlVovu2fhSRpjq/Xax6RdTzCdtK 07W/J4kvSa1pqhOszXlc02txwHRla38TqD835jwahJZiPlM+/3h9kx05PiOWAPocStak 25LgrY4agQCvuZ5a+iiCk0ZH/tZCMOhj/7S6U6vXoZz3CQtkSqt4deNDvNKerKKxrEN4 Hpqljk2SH6OwWqP+RMqCZagM7PVlxe2LF2TuWzzIvQW8Y8faNJ18e9eJjcBbqjT+SpjW ErnSKlU1ymmOQjtyIfnVwkEQK1Rfd09HcvFUGoGbQTI1AQyPDRokIilpg54JnICYZxjI SWaA== X-Gm-Message-State: ACrzQf0fuMa+Qz1qfFPbp1C3VaIF0vqVmrmEbw9HAli/3lH0FQht/aP8 ZgkBVdjaLoZEomfBfUm1YVyNl3rU0hf7jtJo X-Google-Smtp-Source: AMsMyM4Z+d4mQSJdsbyWNwJhOuwZCn5/iith/heLhuyiBLfqOLKDXfls7SWzazloxwtCq4/FuI9PaQ== X-Received: by 2002:a05:6e02:1988:b0:2fc:907b:d1b4 with SMTP id g8-20020a056e02198800b002fc907bd1b4mr21406220ilf.155.1666637748838; Mon, 24 Oct 2022 11:55:48 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id p10-20020a056638216a00b003635a42d653sm85517jak.134.2022.10.24.11.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 11:55:48 -0700 (PDT) Date: Mon, 24 Oct 2022 14:55:47 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Jacob Stopak , Jeff King , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Subject: [PATCH 7/7] shortlog: implement `--group=committer` 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 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 f6032c6328..27a87167e1 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); }