From patchwork Fri Oct 21 03:11:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13014230 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 76064C43217 for ; Fri, 21 Oct 2022 03:11:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229823AbiJUDLv (ORCPT ); Thu, 20 Oct 2022 23:11:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiJUDLd (ORCPT ); Thu, 20 Oct 2022 23:11:33 -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 544C215D0BF for ; Thu, 20 Oct 2022 20:11:31 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id l6so986624ilq.3 for ; Thu, 20 Oct 2022 20:11:31 -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=NS5jnNvTpcFKtSvrcIw2q8cUIC7uZK6L+0C7KlbIWK0=; b=vJtpkwzpjYZDZVSyhqMhCJWmrGRJcyhHQzlq2dSIzZnJgy0/T79SEdwVauDuLP39vx ZXxjJPb6GwHTgcMwbc7mEXPwKicBK0SbqcYll6/YFr/go8bbRseTU+GIHZSruz1wRKI4 Cvdo/l+Csa9FU3jb9xKuVdZqDpZPxMdIeNft1XQg4uwDcMy+VHbypx4GwOYAViTyovh9 sKgoh7Fdm/d/7GSAvPQQPXkJY+KqjYEDjxjdIIipCVMIYvkrwOlcRkT8WvnpSwvzjfbc U2TTDHJrQtY5Jqjq307qq4W/1Grh9vHC/GFKpV6OJPp3MEx9gcuCk4f5nNjr2EcciAMq gGPA== 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=NS5jnNvTpcFKtSvrcIw2q8cUIC7uZK6L+0C7KlbIWK0=; b=vtsQOiIyPafwNA3hiA2bfnbOq6ADmWqRMkw6dbGJuzLcxiAKAnEGq9SRORTRcTyboY fOKN5YqpjSdcLNlZVIS+3nuGK9g3EVKYsftlKMObsMVif6WJAf4pb7w3T/BuB5v4VGCC Kq1NG0q5YNbAEE9fMXN8H+HOIwMYZMg0tUfS3YbHD2545Q9L07N33911MZRGJjyo1/gx /sXIC90djs92q6CeSemXU0EFmdKuixvx3iud2hpkfw8Zb7jscd+SA2KAb0xKtegSk/+Z RGUYt5OyvoGYz/nZVXjsJil8zB9b4pjlgfm8guUCI0HCgYud5WFEMrL6cOTLeLch7kTD 6b/Q== X-Gm-Message-State: ACrzQf0GKu9RqONPawgj7BB6/dQ+YG63X+0ntGxm4/8iuoAGwW3sj+g0 P5xXl0Bil4zqNgOw/E55U0a6W1l7Fmy2x7Xf X-Google-Smtp-Source: AMsMyM7YSCjiBqwhAEMRonP53Obi7IjMoExplS+B53m4iVQzdKH5uzgPPOpoGsbdCqHQ8KpCbMk2Sw== X-Received: by 2002:a05:6e02:1a82:b0:2ff:3a41:4440 with SMTP id k2-20020a056e021a8200b002ff3a414440mr5116572ilv.231.1666321890530; Thu, 20 Oct 2022 20:11:30 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id x10-20020a0566380caa00b00349d33a92a2sm3852740jad.140.2022.10.20.20.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 20:11:30 -0700 (PDT) Date: Thu, 20 Oct 2022 23:11:29 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v2 1/6] shortlog: accept `--date`-related options Message-ID: <58baccbaa8612adae55f776ce10806809861270c.1666320509.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..311c041c06 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=:: + With a `--group=format:`, show dates formatted + according to the given date string. (See the `--date` options + 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 03:11:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13014231 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 D820AC4332F for ; Fri, 21 Oct 2022 03:11:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229678AbiJUDLx (ORCPT ); Thu, 20 Oct 2022 23:11:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbiJUDLf (ORCPT ); Thu, 20 Oct 2022 23:11:35 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A8E416DC0D for ; Thu, 20 Oct 2022 20:11:34 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id o65so1277949iof.4 for ; Thu, 20 Oct 2022 20:11: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=dpsOH8MNNjaXe8PFoD/jp7TaZ7ac3hJ14pF51hYOfwY=; b=zhK0hgOOrgOmtvKNc3USU+RAZd0fLQfwNvc6B2q8w1ej8z8x1uF6zzHu1rz+OsZzCH bmegYrt2rY19IHK74WQ+E7n5WhgyVsErzrPurtuAEYGA4pfwu4ROtxouYi72FgXp3j4m lHrsgHC/ge6C30J9kca4tTtAqq319vlM0HFGgn2kpCTP3Jp2GWWFjp94OBZYgM0hS/2U aa7hFzTe0ZdR4E8Fe3TFNpVGGCrd6S5AOHSOJCpGxMlI6WBuurhGrwR9Tm0YmQGHOaRU +OVxehAG0/6bMSN4hFWxrGMX+/kUxQC1Scf0YTe4yFuwfS0YUPw82t5W7ebQRfdHOWdW J4ww== 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=Wt4idooAG25F7gp0aBZLA1DL3Ptpj6bJ+YM3Omm1V4TyGz6C+jutrrV7XvI4f76njo Yy8xo6F49P02/Goy9KoF1IixjF8tXaEQhBJWP2o4Iovh6E8fVtD+ORbv4sQ9jOzasLXB zDq7Gxl62yFjDWKc7nTsF7YErjLr6clAsCb67wMZJi0K9UFll7yIMjHq6fOkXepizi0Z gVCXM6ElOItBfkN8/1dQtR70U3uhUABMkauGuQkW4MRzXsbAmbFsld73dF534hrkD62j 3boQYZvKaeUWlWLn29ne7vGFGK7ZGZLKT5tdNNQcDtbQrTPWGAvPEq7IsBza1mW8vFJv dSuA== X-Gm-Message-State: ACrzQf0RjFUR2GEDX7gEiGQulHKHWPY22DEbj12l3lpYJ9zkLj4NB50A T73MVmnIulL+R6JGqNJTu9jpzjz4pq18ZrJQ X-Google-Smtp-Source: AMsMyM4y71vRxK+wOHoD+d/drgfGxaASgpGAZpfp863F1JHfDd3xt5dQE9kLw3zLKAzLsb7fwa/2gQ== X-Received: by 2002:a05:6638:2049:b0:364:ef8:868e with SMTP id t9-20020a056638204900b003640ef8868emr12810908jaj.75.1666321893549; Thu, 20 Oct 2022 20:11:33 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id w29-20020a056638379d00b00368d1654e9bsm690493jal.165.2022.10.20.20.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 20:11:33 -0700 (PDT) Date: Thu, 20 Oct 2022 23:11:32 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v2 2/6] shortlog: make trailer insertion a noop when appropriate Message-ID: <7decccad7ccb39eed67bab87ed665beccf5d392f.1666320509.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 03:11:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13014232 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 432AFC43217 for ; Fri, 21 Oct 2022 03:11:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229880AbiJUDL5 (ORCPT ); Thu, 20 Oct 2022 23:11:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbiJUDLi (ORCPT ); Thu, 20 Oct 2022 23:11:38 -0400 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 533B413C1EE for ; Thu, 20 Oct 2022 20:11:37 -0700 (PDT) Received: by mail-il1-x12d.google.com with SMTP id l3so958299ilg.13 for ; Thu, 20 Oct 2022 20:11:37 -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=jp3sgf9MiQGt0kXZw/JW/SkmxUjJM4irz4eOVlgtyThMdh5kQnZzesH6LosL5yt+mt QiqPYTNMqUAf7SoMrv2MzCCBOUkRWdRB80XWfildWmdVS7K2jNZr3sE3RgjoH8KkZck0 X5ykHYPfHkTBXhcEGVvTizkwYUNaA5VCu3lNnvxP3M39zFUuxD3GXiGcIpdKiJ9bZ85S KzWi9/dKYNkNu/1/bbuz0mKLCoLy6Dw+kXegv3bXTBvn0f4XEfj7h3vSOH3tHQizI9JR 7nFbWYGR2y9pkZnEZbgPwQLKmtpzn5qPHyAbSa3jWSd2SbMCSLUmMIwFmc7I9iEmmKOk /+cA== 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=4ODCQL4yL98L0r/0XOVMp6SrHsM/CVxHC+TKejcYPJJBUynYsPiVpC5JvGAsYEp6OY 9ipG671DKRAJTlgKRTjpvxWGYWf0rJ4vGrf38GEUAuo2NI/BQB09DoXd13UAjcgqoOy1 kawK8oPP/OVzCM7gjUoM0qydT82lAZ8DJgommWCtqiaN2pKcbJjqszfhSLIClUxMnDQU 35LlHR2BBIsbbWUUyeb9xcKR3ajadJeDW7EwhyuRkiLlzjrkkX+KKgvwX1re2gpRFkaO Nv9TS6T3HFG/cy8EYrNIUBaF00nfcFw0ePyqv/8Ef3HMjgai3vlefq092Xq9ByjXjRRN Ucow== X-Gm-Message-State: ACrzQf2C4nyzep6Dg7PLgmBfuHDZcR+7HpCXOWsCyISQI305xzTB7ryd dFg6uN7IwgeuUJS4lhlaWdwpQYoFnryRUZv5 X-Google-Smtp-Source: AMsMyM7+TZNGZfTjcjtMTsKE/BhTqTei023AOu7l/pzwvWQnKXLRrGCJ4FuYIp58xZcvYsZs4VElMg== X-Received: by 2002:a05:6e02:219c:b0:2f9:aef7:e018 with SMTP id j28-20020a056e02219c00b002f9aef7e018mr11614820ila.315.1666321896559; Thu, 20 Oct 2022 20:11:36 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id j21-20020a056638053500b003633eb91999sm3736476jar.155.2022.10.20.20.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 20:11:36 -0700 (PDT) Date: Thu, 20 Oct 2022 23:11:35 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v2 3/6] shortlog: extract `--group` fragment for translation Message-ID: <3665488fc95ee3b097f2e0e1e64d23d523c073fa.1666320509.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 Fri Oct 21 03:11:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13014233 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 A701EC433FE for ; Fri, 21 Oct 2022 03:11:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229765AbiJUDL6 (ORCPT ); Thu, 20 Oct 2022 23:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229734AbiJUDLm (ORCPT ); Thu, 20 Oct 2022 23:11:42 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46E51BECDD for ; Thu, 20 Oct 2022 20:11:40 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id l127so1237944iof.12 for ; Thu, 20 Oct 2022 20:11:40 -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=4f+L5daK31D8okaMwSpnCIUCs/le7fnuZBmfmTtUqc0=; b=gHHMYHNYSsOPDjnSrM+jaj6XTQ7SmzHwop5tAask4ixm/+K04w1pAAKIUo59s2WNh1 syHwVMh2KE9bQ3chezBZUSQiiVh1wFtvPORq/C+sV+K/e0JMMuvdS+nS+3lmUHcN6/I1 1J17Iz0jfzcAAZAlSTkU/GEtwbZYTU6GWZVIY6qi/IhBtl+dnv8hdYDgq7jzOYdS4l7i D9zP+zb8My3qnhu0p4TS9ri7vaxH05lG2DmnRxtq7E/GyaQQFOQ9am8Q3+3wPIQarF2u war+ne/T08am5zgc2G6KKC0MsoSlzT3HQuHa7kZnIHJG2ogQrlXfUIIWlY/xcb3UeepJ EUMA== 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=4f+L5daK31D8okaMwSpnCIUCs/le7fnuZBmfmTtUqc0=; b=eqjo2B31peQfZo+Y39iLdqYVfSiVpGxZGEOHsVqD411Qxnc8kCCRaSz6rXlBLb+T8h 3bsO3tNJ1z5DAsGp8u3O5vZrkFzJCDie543ImGC2fNp4urE46f6o7dPp59CwdWqPeUeq Ajnibwhhh5QmZO1/K2lz0Lc7BR0VymDUg6jsf9pEaBgv+KwkevXkjkvPWCZwDvfpobnA Z8YnmuJV+Ugz/pzPjMgClAcIlEyRDXJZg8jw8jhLJxTBuWVtGdwouZXiu4rbB6uLbXOg 7aVkdMtLPaK9IQpFpIpi6yRZXTxD4wFKPVmQlrvUewuCizOIUIR/7oRQHemejW/GZk0Y ia1Q== X-Gm-Message-State: ACrzQf3Tat7rh2//br7sWLMcizU9PgzsXFBYkyvwBkfjjzMC8xCp0lWR 0nWaoiQHFXp92+WHTcv2t9VFitwUxRWxOB9Z X-Google-Smtp-Source: AMsMyM4xameyUKeMlBOq6WX/cXFTD9WmbyIrqlYcrg0zB3piVDHK7+3e5lFJimA2TVUosA/c0KRzIg== X-Received: by 2002:a05:6638:4185:b0:363:cdcd:ce1 with SMTP id az5-20020a056638418500b00363cdcd0ce1mr13042253jab.101.1666321899502; Thu, 20 Oct 2022 20:11:39 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id j3-20020a026303000000b00363e4730a41sm3859295jac.175.2022.10.20.20.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 20:11:39 -0700 (PDT) Date: Thu, 20 Oct 2022 23:11:38 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v2 4/6] shortlog: support arbitrary commit format `--group`s Message-ID: <4a36c0ca4e840d53e2fd257e2d97498ced6fb28c.1666320509.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 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 | 3 +++ builtin/shortlog.c | 37 +++++++++++++++++++++++++++- shortlog.h | 2 ++ t/t4201-shortlog.sh | 44 ++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 1 deletion(-) diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt index 311c041c06..8cf5a2e3c7 100644 --- a/Documentation/git-shortlog.txt +++ b/Documentation/git-shortlog.txt @@ -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..0358397a7b 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,28 @@ static void insert_records_from_trailers(struct shortlog *log, unuse_commit_buffer(commit, commit_buffer); } +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 (!(log->format.nr > 1 || log->trailers.nr) || + 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 +268,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 +340,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 +348,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 +374,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 +515,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..13ac0bac64 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -244,6 +244,36 @@ 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 multiple --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 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 +356,20 @@ test_expect_success 'shortlog can match multiple groups' ' test_cmp expect actual ' +test_expect_success 'shortlog can match multiple format groups' ' + cat >expect <<-\EOF && + 2 User B + 1 A U Thor + 1 User A + EOF + git shortlog -ns \ + --group="%(trailers:valueonly,key=some-trailer)" \ + --group="%(trailers:valueonly,key=another-trailer)" \ + -2 HEAD >actual.raw && + grep -v "^$" actual.raw >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 03:11: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: 13014234 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 2EB94C433FE for ; Fri, 21 Oct 2022 03:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229906AbiJUDMA (ORCPT ); Thu, 20 Oct 2022 23:12:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbiJUDLq (ORCPT ); Thu, 20 Oct 2022 23:11:46 -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 46E5AD8F55 for ; Thu, 20 Oct 2022 20:11:43 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id 187so1247430iov.10 for ; Thu, 20 Oct 2022 20:11:43 -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=zd9zUDRv2jDdpAqGYBb5Eyl0Xx2VQTYfwws6RV7WY28=; b=bDMAqOwVfsjj1fcBhx9I6zyq639JeSEvVtrFUAKb3KZ81V3itFmyNquDO2W7/PCINS AaPsphdbhGx0VI6HC3k6tRZIFQsvxcJba6gruu2UscHP+NMEExKejBsms6Ss9HtRK/+t 2obxFwwPxNI7dxUBnoww42OAJ833SjhyU4MH1S4uw265B1qMdB3Qo1kHkCa5EdbX2NN5 xAnjITZV6+4+mjBnPtRqzzyZtxcsXYYfONPYxASyfaJ5/eee6ml9x4OGiukHTWevaIHz 4m6hEBjDScq13B+i9/FWKlRGPUPancD1peCITkYdIY3Up4XSUr3Nhyt+gifJq75V08pz nzZw== 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=zd9zUDRv2jDdpAqGYBb5Eyl0Xx2VQTYfwws6RV7WY28=; b=Ixrh45HNl8oUFbznfUtFcvcgUvlSa2zab+3RuaeZDUcRq0spVAErAhr4ViGFoNJHlD zTOnODmijv7BFJjWf1amyX3cMyQY2JiwBmmVnZ5kuL5fqkLXymLGpLSRIHY5GOk+GSmK 23ylUEUGugH3laNZmi76ip884u/ODuf/DZ8AyYQ4TNao2FfkBDigTQWe2W79yhIIh+iM F+iU9jzurYVTATIDQ0wjTPza2thAHZhAOU+jrNNd2ghYkRMp/P20Beyo+cdcuEvx6OrD 3rv8VzXZGRLEgca2bKcuGSTwG3qBx+v7mxmUa2eGVxRj2rHwwtMGWxAi3ehBiB5I3Pl+ 3Qng== X-Gm-Message-State: ACrzQf15chyLHMeSF2jsosLQSJK1/RBT2r8P8qSmlYkCJRL2jE3doAC+ 7YPna1E4d145oCK95sWBpONwrWyx3A0WTji3 X-Google-Smtp-Source: AMsMyM70BiXdccCONT1oA2eEBceKNcrbQWFMWosXBYzLG/XJIAV8muHj2m3R7g7Dqq5zMNEmL8keUA== X-Received: by 2002:a6b:6f02:0:b0:6bc:15d8:3446 with SMTP id k2-20020a6b6f02000000b006bc15d83446mr11819778ioc.108.1666321902513; Thu, 20 Oct 2022 20:11: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 z25-20020a05663822b900b0034a6d12aa25sm3890951jas.4.2022.10.20.20.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 20:11:42 -0700 (PDT) Date: Thu, 20 Oct 2022 23:11:41 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v2 5/6] 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/log.c | 1 + builtin/shortlog.c | 20 ++++++++++---------- shortlog.h | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) 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 0358397a7b..fceb84f12f 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -249,15 +249,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, @@ -377,6 +368,15 @@ void shortlog_init(struct shortlog *log) log->format.strdup_strings = 1; } +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); +} + int cmd_shortlog(int argc, const char **argv, const char *prefix) { struct shortlog log = { STRING_LIST_INIT_NODUP }; @@ -446,7 +446,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 03:11: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: 13014235 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 4044BC4332F for ; Fri, 21 Oct 2022 03:12:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbiJUDMD (ORCPT ); Thu, 20 Oct 2022 23:12:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbiJUDLs (ORCPT ); Thu, 20 Oct 2022 23:11:48 -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 59C9092F51 for ; Thu, 20 Oct 2022 20:11:46 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id i9so969489ilv.9 for ; Thu, 20 Oct 2022 20:11:46 -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=SdWuD1/2/zu6rykPbsAZpn6b0T0k1/un84tJMHJduSY=; b=FD1OENBCnaexEYA9qtnGQ50ibAI1X8GqJxMSvGcaCHcMYzoKkQjtDt/ahQuKq6huQC iKrNiNhxMmMrIQqgDYCGIyNXGk836YLIn+Qb6G67A6Sk7PufoZqWrRWV2H1BWhSq7JN6 9D2e3fTgeFCcdD/+dI0dvTY/8hFMVmnY/E68aZH8uUxOCY3KdZOP1K8TU2mdy6dvY3oJ R35CIoGn6Kv/V4O6NCDtWNxlZlbim9Zvd2qIYe7ARAzgx54D4GHfetvZkCRh2/LlUgct IcUXshdgFV2yXiutyKequ17M6y0IuYyOAWZ/Q6ugQERyvMyLCt0vsodRVJ0jbeT5u/kN zMNQ== 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=SdWuD1/2/zu6rykPbsAZpn6b0T0k1/un84tJMHJduSY=; b=PyNJP9QY5ctUEcZi6oZqC3RLWkN86gcuBf6xsSXICWmjWNg+HH29XrkFgOSrkkOqbs Ko/ZO94+0F1VQaNzJBg9mw1WVh0RZ0p9cnvN0eKCXguNPoLL/IqU44rTbVEO2kNPdaW+ naDCdX4hZMqx3+9hIba0CQhjEgmZgwXojs0VYZxnnPVNxIQ6qdTDuYkKefu1iYxFRIFI DtRPtKsvlTI1w08MHbzi2fRyanz71l7nAkMq6sVOUUoppCvLhnpyn3Vi2m8Ti4RPwgDE 9tLzBZRQLArO2N2JhFCW6OCMUTmXE4X4jv4qj1vaBDS3TQODm9fbwK/lv+q9P6cLguG4 ruhg== X-Gm-Message-State: ACrzQf3bL44eZpTEqBR0wXyiah/A1uogWkgKeItf/wm1Vn0XYEOLyKi2 5nthl9wsGQzOk3GCWja+T1vMxjyoojM9K0jf X-Google-Smtp-Source: AMsMyM5ZtAHCOQ9vEwpjcwF6hem9CAV8qqO8Fmfr6zJ7VYmpjc/ITdwaix/TX1pWxyyMiF2M9VoM5A== X-Received: by 2002:a05:6e02:1bc7:b0:2fa:876e:95a7 with SMTP id x7-20020a056e021bc700b002fa876e95a7mr12850268ilv.240.1666321905531; Thu, 20 Oct 2022 20:11: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 l41-20020a026669000000b00363a30a154asm3788440jaf.94.2022.10.20.20.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 20:11:45 -0700 (PDT) Date: Thu, 20 Oct 2022 23:11:44 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: jacob@initialcommit.io, peff@peff.net, gitster@pobox.com, avarab@gmail.com Subject: [PATCH v2 6/6] shortlog: implement `--group=committer` in terms of `--group=` Message-ID: <6a9e204177d486e786574ec682e6d73907a3ce7e.1666320509.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 fceb84f12f..b9f5af22d3 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -229,7 +229,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}; @@ -249,20 +248,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); } @@ -373,6 +362,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); }