From patchwork Wed Aug 5 21:51:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11702563 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E1931575 for ; Wed, 5 Aug 2020 21:51:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F61522CBB for ; Wed, 5 Aug 2020 21:51:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UiItR4w2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbgHEVvx (ORCPT ); Wed, 5 Aug 2020 17:51:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725996AbgHEVvv (ORCPT ); Wed, 5 Aug 2020 17:51:51 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F63AC061756 for ; Wed, 5 Aug 2020 14:51:51 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id c15so5849191wrs.11 for ; Wed, 05 Aug 2020 14:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=uNUsuTHd76WaG7QGyi2UOuWlYlIFt0ajBuAczYpj/+I=; b=UiItR4w29RAFQGiih51bCf2ym3hnm5vUv3t9SSEMuyIkllsekTKzPfyjL9V4pG9Zqa 5ymmfehxCqfUpEGctTJ9JQE/OczZAdN+RK+pl9exZdu8jIkgAqOB3GW4HoVc3lGm3l6a yKB2GEU0tdzXUSEjlWmf/0ofPWmO9kezw4VCLdOzp19LH2iXwPlK7BZjdZZmp6mnBm6v ctxQFSLesYl7s/DXPp2vPPklnoYj4zIRl32gbVVElfuPo6itnQNtIIDQ7rpVaK2Fv7VU 8y8t79dBjOvpMlBWvO2uwdb8YI+yQtyMxVsPiGnp5whvpqBwdEeSA/FfLw2ee0+8MtTR cy0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=uNUsuTHd76WaG7QGyi2UOuWlYlIFt0ajBuAczYpj/+I=; b=q24xGh/E5nd8kSSP4XQ44AyqOWwp1Vz1n4AkPT1LviRQHBksBnURq4s5EvrI1rJDRF sufTW5ARjMqK+7zY0brfjqRU0X6U8hz3hoe1iOSgE/npg1Ve8AhjLNCIF55xwviKG0yl viQpVOc99YfeMqsc8ysiYt1r5qs/vPOa4klKSwOlU9WYIrVRqQOMjpII07VY/QZXCjlX nCxRtUEB9VGHq6X9zn2ETs2dto3COTzS36aXdxHSM2D/z8SDN1H0u0RbUZirVPA50BAH 968DDkek6SCkpQ9XbKvSqA6a6WyCrcpDYBu/2JVHIqPvEXFg/Zypx1Zr+/rtdTjMTChu JDtw== X-Gm-Message-State: AOAM531ZsOGBP3uEMOOAEhFefyjD/76vlneDqinRDFvuEpm5vbNO+hnq K0Xw63wGDXrruLkwgqPgnXA8nRUS X-Google-Smtp-Source: ABdhPJzRHetvUSHFs8Qek8SNgltXvXuZwoVrYa2y1hpT1zZMxVepS0sZr8pU2yYnQGFhRsIPVtp4tA== X-Received: by 2002:adf:fd41:: with SMTP id h1mr4755793wrs.124.1596664309476; Wed, 05 Aug 2020 14:51:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n5sm4067748wrx.22.2020.08.05.14.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 14:51:48 -0700 (PDT) Message-Id: <78e69032df68f8edd0f88798936a3e85e5ddf34c.1596664306.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 05 Aug 2020 21:51:37 +0000 Subject: [PATCH v2 1/9] ref-filter: support different email formats Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma Currently, ref-filter only supports printing email with angle brackets. Let's add support for two more email options. - trim : for email without angle brackets. - localpart : for the part before the @ sign out of trimmed email Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- Documentation/git-for-each-ref.txt | 5 ++- ref-filter.c | 54 +++++++++++++++++++++++++----- t/t6300-for-each-ref.sh | 16 +++++++++ 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 2ea71c5f6c..e6ce8af612 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -230,7 +230,10 @@ These are intended for working on a mix of annotated and lightweight tags. Fields that have name-email-date tuple as its value (`author`, `committer`, and `tagger`) can be suffixed with `name`, `email`, -and `date` to extract the named component. +and `date` to extract the named component. For email fields (`authoremail`, +`committeremail` and `taggeremail`), `:trim` can be appended to get the email +without angle brackets, and `:localpart` to get the part before the `@` symbol +out of the trimmed email. The message in a commit or a tag object is `contents`, from which `contents:` can be used to extract various parts out of: diff --git a/ref-filter.c b/ref-filter.c index f2b078db11..307069219f 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -140,6 +140,9 @@ static struct used_atom { enum { O_FULL, O_LENGTH, O_SHORT } option; unsigned int length; } objectname; + struct email_option { + enum { EO_RAW, EO_TRIM, EO_LOCALPART } option; + } email_option; struct refname_atom refname; char *head; } u; @@ -377,6 +380,20 @@ static int objectname_atom_parser(const struct ref_format *format, struct used_a return 0; } +static int person_email_atom_parser(const struct ref_format *format, struct used_atom *atom, + const char *arg, struct strbuf *err) +{ + if (!arg) + atom->u.email_option.option = EO_RAW; + else if (!strcmp(arg, "trim")) + atom->u.email_option.option = EO_TRIM; + else if (!strcmp(arg, "localpart")) + atom->u.email_option.option = EO_LOCALPART; + else + return strbuf_addf_ret(err, -1, _("unrecognized email option: %s"), arg); + return 0; +} + static int refname_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) { @@ -488,15 +505,15 @@ static struct { { "tag", SOURCE_OBJ }, { "author", SOURCE_OBJ }, { "authorname", SOURCE_OBJ }, - { "authoremail", SOURCE_OBJ }, + { "authoremail", SOURCE_OBJ, FIELD_STR, person_email_atom_parser }, { "authordate", SOURCE_OBJ, FIELD_TIME }, { "committer", SOURCE_OBJ }, { "committername", SOURCE_OBJ }, - { "committeremail", SOURCE_OBJ }, + { "committeremail", SOURCE_OBJ, FIELD_STR, person_email_atom_parser }, { "committerdate", SOURCE_OBJ, FIELD_TIME }, { "tagger", SOURCE_OBJ }, { "taggername", SOURCE_OBJ }, - { "taggeremail", SOURCE_OBJ }, + { "taggeremail", SOURCE_OBJ, FIELD_STR, person_email_atom_parser }, { "taggerdate", SOURCE_OBJ, FIELD_TIME }, { "creator", SOURCE_OBJ }, { "creatordate", SOURCE_OBJ, FIELD_TIME }, @@ -1037,16 +1054,35 @@ static const char *copy_name(const char *buf) return xstrdup(""); } -static const char *copy_email(const char *buf) +static const char *copy_email(const char *buf, struct used_atom *atom) { const char *email = strchr(buf, '<'); const char *eoemail; if (!email) return xstrdup(""); - eoemail = strchr(email, '>'); + switch (atom->u.email_option.option) { + case EO_RAW: + eoemail = strchr(email, '>'); + if (eoemail) + eoemail++; + break; + case EO_TRIM: + email++; + eoemail = strchr(email, '>'); + break; + case EO_LOCALPART: + email++; + eoemail = strchr(email, '@'); + if (!eoemail) + eoemail = strchr(email, '>'); + break; + default: + BUG("unknown email option"); + } + if (!eoemail) return xstrdup(""); - return xmemdupz(email, eoemail + 1 - email); + return xmemdupz(email, eoemail - email); } static char *copy_subject(const char *buf, unsigned long len) @@ -1116,7 +1152,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void continue; if (name[wholen] != 0 && strcmp(name + wholen, "name") && - strcmp(name + wholen, "email") && + !starts_with(name + wholen, "email") && !starts_with(name + wholen, "date")) continue; if (!wholine) @@ -1127,8 +1163,8 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void v->s = copy_line(wholine); else if (!strcmp(name + wholen, "name")) v->s = copy_name(wholine); - else if (!strcmp(name + wholen, "email")) - v->s = copy_email(wholine); + else if (starts_with(name + wholen, "email")) + v->s = copy_email(wholine, &used_atom[i]); else if (starts_with(name + wholen, "date")) grab_date(wholine, v, name); } diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index a83579fbdf..64fbc91146 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -125,15 +125,21 @@ test_atom head '*objecttype' '' test_atom head author 'A U Thor 1151968724 +0200' test_atom head authorname 'A U Thor' test_atom head authoremail '' +test_atom head authoremail:trim 'author@example.com' +test_atom head authoremail:localpart 'author' test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200' test_atom head committer 'C O Mitter 1151968723 +0200' test_atom head committername 'C O Mitter' test_atom head committeremail '' +test_atom head committeremail:trim 'committer@example.com' +test_atom head committeremail:localpart 'committer' test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200' test_atom head tag '' test_atom head tagger '' test_atom head taggername '' test_atom head taggeremail '' +test_atom head taggeremail:trim '' +test_atom head taggeremail:localpart '' test_atom head taggerdate '' test_atom head creator 'C O Mitter 1151968723 +0200' test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200' @@ -170,15 +176,21 @@ test_atom tag '*objecttype' 'commit' test_atom tag author '' test_atom tag authorname '' test_atom tag authoremail '' +test_atom tag authoremail:trim '' +test_atom tag authoremail:localpart '' test_atom tag authordate '' test_atom tag committer '' test_atom tag committername '' test_atom tag committeremail '' +test_atom tag committeremail:trim '' +test_atom tag committeremail:localpart '' test_atom tag committerdate '' test_atom tag tag 'testtag' test_atom tag tagger 'C O Mitter 1151968725 +0200' test_atom tag taggername 'C O Mitter' test_atom tag taggeremail '' +test_atom tag taggeremail:trim 'committer@example.com' +test_atom tag taggeremail:localpart 'committer' test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200' test_atom tag creator 'C O Mitter 1151968725 +0200' test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200' @@ -564,10 +576,14 @@ test_atom refs/tags/taggerless tag 'taggerless' test_atom refs/tags/taggerless tagger '' test_atom refs/tags/taggerless taggername '' test_atom refs/tags/taggerless taggeremail '' +test_atom refs/tags/taggerless taggeremail:trim '' +test_atom refs/tags/taggerless taggeremail:localpart '' test_atom refs/tags/taggerless taggerdate '' test_atom refs/tags/taggerless committer '' test_atom refs/tags/taggerless committername '' test_atom refs/tags/taggerless committeremail '' +test_atom refs/tags/taggerless committeremail:trim '' +test_atom refs/tags/taggerless committeremail:localpart '' test_atom refs/tags/taggerless committerdate '' test_atom refs/tags/taggerless subject 'Broken tag' From patchwork Wed Aug 5 21:51:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11702567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86C8D1510 for ; Wed, 5 Aug 2020 21:51:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72E4022CAF for ; Wed, 5 Aug 2020 21:51:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XVqCIc3I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726545AbgHEVv4 (ORCPT ); Wed, 5 Aug 2020 17:51:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726158AbgHEVvw (ORCPT ); Wed, 5 Aug 2020 17:51:52 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3628C061757 for ; Wed, 5 Aug 2020 14:51:51 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id 3so7771630wmi.1 for ; Wed, 05 Aug 2020 14:51:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=zh/SM7bEToiUSBKDmzJ3iJ6Bqe83IxresQCCJLW6RrI=; b=XVqCIc3ISKW+GwV8LiQU64utTEB9xBjgdzDSiSnpg3n9XZBKkpI2jNbOnp2fIKtKVR 0opOKJIygTFmBAXeVhQhdCcPtdSR+noNw2IkBqA0XxOV34gFcqHmxfm+sd8VPUj5cftC jFqpMLZJl7R8Mvqo+/3n2roUaRiDqrtPKvyJsQKpfpgXjXK4ru1NczLZZZI0uiNzysRh Rb8b/afaV1Y5jMameGlCwA9gEJ95uBky4dTYc0Hs4ZV/hZi1DbK5y5kwZPJ9Aa+6Ka8o 0PWFbmBNi3T0sdGNFQtd7654ZHEHVASGUtys7MNxZxkjQZb+GS5++etqJUgcVjwj0bQh UKrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=zh/SM7bEToiUSBKDmzJ3iJ6Bqe83IxresQCCJLW6RrI=; b=o0V/6p55CqnZBUwbVz9m2P/IDDtHpbWjIdVm7JtGnRkEE0kxzn8aMjH/GCM+pwEKPR 0dYuGr04HdabmCZb8/PVKCjS8oSGOU995585Rr6Vdh60lPj8wPCsosvtMjYHyh+teNhh Slrxf0ZPNIC5WvXNApnwsTpGlmx5atbwjJ32XhdE15RQkm3JHGB/SKJFZwtOaq+enojm 9Igpt2Nt0htrc7LDIRwP0gnkKX7Vb+cnRX2eXEM9JuZDJzhAi0q5AoP5+3bHXoUmUVFu IFGtt8EsmcETMUCERBNm6RUW6u6dlVMHnl3t0acMeeXtOuwMr+It8rLYnw+K2/Als/58 m2ZA== X-Gm-Message-State: AOAM533uqgYg7B/6Sw08jMDmkQInJ7mzVxKrVboDJ8FDeRpOscramTEI ctnHELGtpsmiZlK8aU/rtUaJymiX X-Google-Smtp-Source: ABdhPJw6qrEst2B/XNZV0B9VxLC3AgMOLrhE7gYuhcIAtdLVPpYs6cELKVhowQRp0g+rFwm6SbYQkA== X-Received: by 2002:a1c:2e4e:: with SMTP id u75mr3973458wmu.134.1596664310254; Wed, 05 Aug 2020 14:51:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 15sm3888335wmo.33.2020.08.05.14.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 14:51:49 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 05 Aug 2020 21:51:38 +0000 Subject: [PATCH v2 2/9] ref-filter: refactor `grab_objectname()` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma Prepares `grab_objectname()` for more generic usage. This change will allow us to reuse `grab_objectname()` for the `tree` and `parent` atoms in a following commit. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- ref-filter.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 307069219f..d078f893ff 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -918,21 +918,27 @@ int verify_ref_format(struct ref_format *format) return 0; } -static int grab_objectname(const char *name, const struct object_id *oid, +static const char *do_grab_objectname(const char *field, const struct object_id *oid, + struct used_atom *atom) +{ + switch (atom->u.objectname.option) { + case O_FULL: + return oid_to_hex(oid); + case O_LENGTH: + return find_unique_abbrev(oid, atom->u.objectname.length); + case O_SHORT: + return find_unique_abbrev(oid, DEFAULT_ABBREV); + default: + BUG("unknown %%(%s) option", field); + } +} + +static int grab_objectname(const char *name, const char *field, const struct object_id *oid, struct atom_value *v, struct used_atom *atom) { - if (starts_with(name, "objectname")) { - if (atom->u.objectname.option == O_SHORT) { - v->s = xstrdup(find_unique_abbrev(oid, DEFAULT_ABBREV)); - return 1; - } else if (atom->u.objectname.option == O_FULL) { - v->s = xstrdup(oid_to_hex(oid)); - return 1; - } else if (atom->u.objectname.option == O_LENGTH) { - v->s = xstrdup(find_unique_abbrev(oid, atom->u.objectname.length)); - return 1; - } else - BUG("unknown %%(objectname) option"); + if (starts_with(name, field)) { + v->s = xstrdup(do_grab_objectname(field, oid, atom)); + return 1; } return 0; } @@ -960,7 +966,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_ } else if (!strcmp(name, "deltabase")) v->s = xstrdup(oid_to_hex(&oi->delta_base_oid)); else if (deref) - grab_objectname(name, &oi->oid, v, &used_atom[i]); + grab_objectname(name, "objectname", &oi->oid, v, &used_atom[i]); } } @@ -1740,7 +1746,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) v->s = xstrdup(buf + 1); } continue; - } else if (!deref && grab_objectname(name, &ref->objectname, v, atom)) { + } else if (!deref && grab_objectname(name, "objectname", &ref->objectname, v, atom)) { continue; } else if (!strcmp(name, "HEAD")) { if (atom->u.head && !strcmp(ref->refname, atom->u.head)) From patchwork Wed Aug 5 21:51:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11702569 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0415A1510 for ; Wed, 5 Aug 2020 21:52:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E590022CBB for ; Wed, 5 Aug 2020 21:52:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s1/dd40A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726569AbgHEVv7 (ORCPT ); Wed, 5 Aug 2020 17:51:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725969AbgHEVvx (ORCPT ); Wed, 5 Aug 2020 17:51:53 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A259FC061575 for ; Wed, 5 Aug 2020 14:51:52 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id k8so7781917wma.2 for ; Wed, 05 Aug 2020 14:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=tx+R+LPXT+fwJZibIA4ZN5AmqEODGGIiyerNaCjUIyQ=; b=s1/dd40Axp6mD8oa1SsxZa4ODrpuwEnX1sNPjrg6QPSztA736Cv1+ARFlG62itAG0v Z6/0mxEEjKJPD+2Yw7vp99StWQGjjKrwMkmsKVia72E5BIUDi8MbYYbNaY1+sycf2PXk cZcROPw5LGuoX18wXXTHqJ7lO8M24qlPv9xLaUbA6FCIirdayIzDwovr9tGWvyaJRJgi u+ZyJFTr/ALD5WotCej8lSYJKqscs51k6PJtb/C2TJrVm8uy4uRZ0RAu69hKU7DlsmBy lDf4GPPpGaMn2/jMwNK+5mNdOAdewtwj/FI0ZQKb10T3Va93DzCpCa60LgZNWsARl/1W T3YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=tx+R+LPXT+fwJZibIA4ZN5AmqEODGGIiyerNaCjUIyQ=; b=EBmDqAsL5uKn/A1XlnZL3PVVTKghmIA8YURrGWlelNhkrfC/MFrUmvlKk2pV9Xt2F9 dZmD5/iuHjgyQlod5UX9/OcvJSgIWpCegoHZsNomEXOgPYtbjRFkU0uQVMKuaQgTRPDI 5/YJ4y3x5TReKxeI3wXpqHV3qNtXS26olW1ngRoQQfdAXljdbvEgwfZ5W7KRHv62Hs9D vIVB4bzob1TAyht+KhNADLzw0GuQERmdjFSLUESLTCK9RrJAEL2xsGwMduphfTevHzcQ 9el9bVteUFI1CNa73IpO7KQhXQa7VUjhk23GNV0TLp6BDaYelx4L96Q6jgwPjeMCbnPV 8oZg== X-Gm-Message-State: AOAM5335b25ejTSStqZzn97YKPgJqj6edOBLfcgatetOsspg3n05Ax4A 6sXftY5oJTvas/X1iq4II7H+lcCY X-Google-Smtp-Source: ABdhPJxRyjvBcoACN7TIT5ZA9RbQUwx1TnFadEdDQvy/MsRj1efSC42J98RxIIvhhEOncQ06toyi6A== X-Received: by 2002:a1c:6002:: with SMTP id u2mr4933447wmb.170.1596664311260; Wed, 05 Aug 2020 14:51:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j5sm4355834wmb.12.2020.08.05.14.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 14:51:50 -0700 (PDT) Message-Id: <65fee332a3819fcaaf557d4c29e414350e62c5db.1596664306.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 05 Aug 2020 21:51:39 +0000 Subject: [PATCH v2 3/9] ref-filter: modify error messages in `grab_objectname()` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma As we plan to use `grab_objectname()` for `tree` and `parent` atom, it's better to parameterize the error messages in the function `grab_objectname()` where "objectname" is hard coded. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- ref-filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index d078f893ff..4183ee2797 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -372,11 +372,11 @@ static int objectname_atom_parser(const struct ref_format *format, struct used_a atom->u.objectname.option = O_LENGTH; if (strtoul_ui(arg, 10, &atom->u.objectname.length) || atom->u.objectname.length == 0) - return strbuf_addf_ret(err, -1, _("positive value expected objectname:short=%s"), arg); + return strbuf_addf_ret(err, -1, _("positive value expected '%s' in %%(%s)"), arg, atom->name); if (atom->u.objectname.length < MINIMUM_ABBREV) atom->u.objectname.length = MINIMUM_ABBREV; } else - return strbuf_addf_ret(err, -1, _("unrecognized %%(objectname) argument: %s"), arg); + return strbuf_addf_ret(err, -1, _("unrecognized argument '%s' in %%(%s)"), arg, atom->name); return 0; } From patchwork Wed Aug 5 21:51:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11702571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF36913B6 for ; Wed, 5 Aug 2020 21:52:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BD5222CBB for ; Wed, 5 Aug 2020 21:52:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="inhKOB2E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726571AbgHEVwC (ORCPT ); Wed, 5 Aug 2020 17:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726524AbgHEVvy (ORCPT ); Wed, 5 Aug 2020 17:51:54 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1385BC061575 for ; Wed, 5 Aug 2020 14:51:54 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id q76so7756196wme.4 for ; Wed, 05 Aug 2020 14:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Y/VnjvghSksd9o7DTiGkVg7LSzd8v4R354PReIpNDDk=; b=inhKOB2EzwX8hg7diggS9LUoYxeTtPfPXFJcmgKmJw+PMOwk1Cwgr+UZ58vVwNScEP rYWooqoDcrsCJ2SSoULyrguUd1OkF2fd3iNXKmSiRqfG7vfXjSCUhUGV/AuxlLux0puf Z7ZLVxhE+P8kdyJhHGZjI7qK7cWxernBEDMkTIcjrsJhV2JUMfjshfuKhsEeZ78I6Onp gmbhtVtrIyyo/2yoI1h723S/Dv7VgKDJnAy8lmYL8HL46CMZ87Q2AdwXedt8KTp+j6Cx 3xYfV5kcSommtRm8ovwtMAe02vNM3bUmIZhslwFxqScKFNpFHVRIv0SszAtVAIKKryzx rdpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Y/VnjvghSksd9o7DTiGkVg7LSzd8v4R354PReIpNDDk=; b=t+awsSfDe767ESZ0N625a/5NDX3EC1mtD+4ijQ46rD87dEX4X1PYQCEmx+PCk6dkMX ukFFGXLtV9aGWXwssvnGsmDXcQ542UjJncbIfuskhzrA+RtJMk3iFOxUEbOzhbSBd0b2 KHLb7gKIda6+qhFFl5psj4gdBSR8pvFa753RZnoRwW9+XGJu8wF63PZaddWV6FJikR+L INrpb73jwPPyXJHGCW4tNxza1WIxD1WNJG8eGsX/5IvXIPwclrpp2/U7bL4l1gfzPP91 T0FYNpmJpKgQ88U3GckPmB+q4m6CQwEt9DoEJMhBl1DA2unZVuOZFObd63bOxgQQcqq9 wphA== X-Gm-Message-State: AOAM533IqretAD4xk66Ocqgo5vc2wfMHGg9a9kB/hD9gBeDRQvlNCbyE MyaKW0qipVLHa1/d/pR8xbxMDlBF X-Google-Smtp-Source: ABdhPJzIJW8cQHlbkFko39NA2QXQ8G44kEPw7uPMkO3sSnfYsXBczhUiYH8g1Wwn8DoCIakzxGEPOw== X-Received: by 2002:a7b:cbd0:: with SMTP id n16mr4998050wmi.123.1596664312019; Wed, 05 Aug 2020 14:51:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p8sm4460961wrq.9.2020.08.05.14.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 14:51:51 -0700 (PDT) Message-Id: <976f2041a41a6b2043c1bece262cb0a3f7a8af35.1596664306.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 05 Aug 2020 21:51:40 +0000 Subject: [PATCH v2 4/9] ref-filter: rename `objectname` related functions and fields Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma In previous commits, we prepared some `objectname` related functions for more generic usage, so that these functions can be used for `tree` and `parent` atom. But the name of some functions and fields may mislead someone. For ex: function `objectname_atom_parser()` implies that it is for atom `objectname`. Let's rename all such functions and fields. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- ref-filter.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 4183ee2797..cc544eadaf 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -139,7 +139,7 @@ static struct used_atom { struct { enum { O_FULL, O_LENGTH, O_SHORT } option; unsigned int length; - } objectname; + } oid; struct email_option { enum { EO_RAW, EO_TRIM, EO_LOCALPART } option; } email_option; @@ -361,20 +361,20 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato return 0; } -static int objectname_atom_parser(const struct ref_format *format, struct used_atom *atom, - const char *arg, struct strbuf *err) +static int oid_atom_parser(const struct ref_format *format, struct used_atom *atom, + const char *arg, struct strbuf *err) { if (!arg) - atom->u.objectname.option = O_FULL; + atom->u.oid.option = O_FULL; else if (!strcmp(arg, "short")) - atom->u.objectname.option = O_SHORT; + atom->u.oid.option = O_SHORT; else if (skip_prefix(arg, "short=", &arg)) { - atom->u.objectname.option = O_LENGTH; - if (strtoul_ui(arg, 10, &atom->u.objectname.length) || - atom->u.objectname.length == 0) + atom->u.oid.option = O_LENGTH; + if (strtoul_ui(arg, 10, &atom->u.oid.length) || + atom->u.oid.length == 0) return strbuf_addf_ret(err, -1, _("positive value expected '%s' in %%(%s)"), arg, atom->name); - if (atom->u.objectname.length < MINIMUM_ABBREV) - atom->u.objectname.length = MINIMUM_ABBREV; + if (atom->u.oid.length < MINIMUM_ABBREV) + atom->u.oid.length = MINIMUM_ABBREV; } else return strbuf_addf_ret(err, -1, _("unrecognized argument '%s' in %%(%s)"), arg, atom->name); return 0; @@ -495,7 +495,7 @@ static struct { { "refname", SOURCE_NONE, FIELD_STR, refname_atom_parser }, { "objecttype", SOURCE_OTHER, FIELD_STR, objecttype_atom_parser }, { "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser }, - { "objectname", SOURCE_OTHER, FIELD_STR, objectname_atom_parser }, + { "objectname", SOURCE_OTHER, FIELD_STR, oid_atom_parser }, { "deltabase", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser }, { "tree", SOURCE_OBJ }, { "parent", SOURCE_OBJ }, @@ -918,14 +918,14 @@ int verify_ref_format(struct ref_format *format) return 0; } -static const char *do_grab_objectname(const char *field, const struct object_id *oid, - struct used_atom *atom) +static const char *do_grab_oid(const char *field, const struct object_id *oid, + struct used_atom *atom) { - switch (atom->u.objectname.option) { + switch (atom->u.oid.option) { case O_FULL: return oid_to_hex(oid); case O_LENGTH: - return find_unique_abbrev(oid, atom->u.objectname.length); + return find_unique_abbrev(oid, atom->u.oid.length); case O_SHORT: return find_unique_abbrev(oid, DEFAULT_ABBREV); default: @@ -933,11 +933,11 @@ static const char *do_grab_objectname(const char *field, const struct object_id } } -static int grab_objectname(const char *name, const char *field, const struct object_id *oid, - struct atom_value *v, struct used_atom *atom) +static int grab_oid(const char *name, const char *field, const struct object_id *oid, + struct atom_value *v, struct used_atom *atom) { if (starts_with(name, field)) { - v->s = xstrdup(do_grab_objectname(field, oid, atom)); + v->s = xstrdup(do_grab_oid(field, oid, atom)); return 1; } return 0; @@ -966,7 +966,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_ } else if (!strcmp(name, "deltabase")) v->s = xstrdup(oid_to_hex(&oi->delta_base_oid)); else if (deref) - grab_objectname(name, "objectname", &oi->oid, v, &used_atom[i]); + grab_oid(name, "objectname", &oi->oid, v, &used_atom[i]); } } @@ -1746,7 +1746,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) v->s = xstrdup(buf + 1); } continue; - } else if (!deref && grab_objectname(name, "objectname", &ref->objectname, v, atom)) { + } else if (!deref && grab_oid(name, "objectname", &ref->objectname, v, atom)) { continue; } else if (!strcmp(name, "HEAD")) { if (atom->u.head && !strcmp(ref->refname, atom->u.head)) From patchwork Wed Aug 5 21:51:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11702573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 663AD13B6 for ; Wed, 5 Aug 2020 21:52:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5291C22CBB for ; Wed, 5 Aug 2020 21:52:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TbSKq/Us" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726605AbgHEVwD (ORCPT ); Wed, 5 Aug 2020 17:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgHEVvy (ORCPT ); Wed, 5 Aug 2020 17:51:54 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39C0EC061756 for ; Wed, 5 Aug 2020 14:51:54 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id f18so5238095wmc.0 for ; Wed, 05 Aug 2020 14:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=eC0RldrHJKKcuVrYX6mEuMdA03cruZ1Gex1FZxdHl60=; b=TbSKq/UsXGIoGav1h/CEZqld6ozpjbDgTezg7Tuzc8fA2cGSe/QOJQYtAWqrEKRgJ/ 3FPTLtU78zB5VL1gx/brP7LBv8S3RAzUyqeAVAxOPWDDUVxLIfdaRrlyxewVeBP34Ay+ uDI2p/qZHPzhcTRpbUdU630FIiwmXE5ISUUiurlhNIY5uMza4MNiq7O1Nyu8PW2GyP5t arjVMQwHf5GgpgkJm+69VUE18fpfwTgxL8s+jm7bFGJODxQc6jMEEjwLFYMixCitx/jR Og/EdnpKFT2vI1jns13ff2XoNVDRrW0WghsbMJLRrvT4MeMU1+Fabp9civrmLSupI8HW Glhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=eC0RldrHJKKcuVrYX6mEuMdA03cruZ1Gex1FZxdHl60=; b=qDwMFt+sqpmIIpSN0rkYKTwA4PTOWaTtRPgTPTVPwWAtxCKBxMOAmOIhxUZWUZo3VD 0xpQq8SkrTmXq72UucCS8eQWxrVkuUQTcpz2jKvM4D5F3fHipsPPECC1ZkefXnyia8p+ W+slFb6flnvgpQWGgn/6NEl5X/mwRYUXApnV1bzsBMC2A2boXxtwgI1Ieg7D9CiIVxj7 HMpGR0GDXrM46nPB859r7tGnXqUn9tuFUcZzAhUincj4uqnBra2Ai9gRPqHD8hHtfenY aV+J5HeAwca9TpIHj1PNqteM+9byF6IgD2SlVcX8mvsneOSu2bC9q74ucu7K3sZGr06o VQBA== X-Gm-Message-State: AOAM531cU3W2Zw2HC5otmDHU6IMSKRdicbJwUbhE5ThC+wzhiuK1PntO CfRKvWAAv6HWxDI6nfyy0T6w06Mm X-Google-Smtp-Source: ABdhPJwFodwMPK4TL9UOhBk5mPyL/gaEgrDINg0JK5vL+KBjXjMPtESrVkcAYWrFhaaj+s0H72amSA== X-Received: by 2002:a1c:2e4e:: with SMTP id u75mr3973556wmu.134.1596664312755; Wed, 05 Aug 2020 14:51:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p14sm4533410wrx.90.2020.08.05.14.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 14:51:52 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 05 Aug 2020 21:51:41 +0000 Subject: [PATCH v2 5/9] ref-filter: add `short` modifier to 'tree' atom Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma Sometimes while using 'tree' atom, user might want to see abbrev hash instead of full 40 character hash. Just like 'objectname', it might be convenient for users to have the `:short` and `:short=` option for printing 'tree' hash. Let's introduce `short` option to 'tree' atom. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- Documentation/git-for-each-ref.txt | 2 ++ ref-filter.c | 9 ++++----- t/t6300-for-each-ref.sh | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index e6ce8af612..40ebdfcc41 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -222,6 +222,8 @@ worktreepath:: In addition to the above, for commit and tag objects, the header field names (`tree`, `parent`, `object`, `type`, and `tag`) can be used to specify the value in the header field. +Field `tree` can also be used with modifier `:short` and +`:short=` just like `objectname`. For commit and tag objects, the special `creatordate` and `creator` fields will correspond to the appropriate date or name-email-date tuple diff --git a/ref-filter.c b/ref-filter.c index cc544eadaf..f9d85661eb 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -497,7 +497,7 @@ static struct { { "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser }, { "objectname", SOURCE_OTHER, FIELD_STR, oid_atom_parser }, { "deltabase", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser }, - { "tree", SOURCE_OBJ }, + { "tree", SOURCE_OBJ, FIELD_STR, oid_atom_parser }, { "parent", SOURCE_OBJ }, { "numparent", SOURCE_OBJ, FIELD_ULONG }, { "object", SOURCE_OBJ }, @@ -1005,10 +1005,9 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object continue; if (deref) name++; - if (!strcmp(name, "tree")) { - v->s = xstrdup(oid_to_hex(get_commit_tree_oid(commit))); - } - else if (!strcmp(name, "numparent")) { + if (grab_oid(name, "tree", get_commit_tree_oid(commit), v, &used_atom[i])) + continue; + if (!strcmp(name, "numparent")) { v->value = commit_list_count(commit->parents); v->s = xstrfmt("%lu", (unsigned long)v->value); } diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 64fbc91146..e30bbff6d9 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -116,6 +116,9 @@ test_atom head objectname:short $(git rev-parse --short refs/heads/master) test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master) test_atom head tree $(git rev-parse refs/heads/master^{tree}) +test_atom head tree:short $(git rev-parse --short refs/heads/master^{tree}) +test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/master^{tree}) +test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/master^{tree}) test_atom head parent '' test_atom head numparent 0 test_atom head object '' @@ -167,6 +170,9 @@ test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag) test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master) test_atom tag tree '' +test_atom tag tree:short '' +test_atom tag tree:short=1 '' +test_atom tag tree:short=10 '' test_atom tag parent '' test_atom tag numparent '' test_atom tag object $(git rev-parse refs/tags/testtag^0) From patchwork Wed Aug 5 21:51:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11702575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37A3C1510 for ; Wed, 5 Aug 2020 21:52:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22A6522CAF for ; Wed, 5 Aug 2020 21:52:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jN7J0FK7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726609AbgHEVwE (ORCPT ); Wed, 5 Aug 2020 17:52:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726533AbgHEVvz (ORCPT ); Wed, 5 Aug 2020 17:51:55 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E25BAC061757 for ; Wed, 5 Aug 2020 14:51:54 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id 184so7778764wmb.0 for ; Wed, 05 Aug 2020 14:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=L08+yYfUa4/4fG9INuh22rKNPpKoqshaYos5skwuxCo=; b=jN7J0FK701TnzVFpk24xPMk95jPrxvkDO8o+YhHpXEDVDI3AXgB/yQSQ524+rj63tu J9wRrFmqjRBaJUjdkyoImjNpACNsmdUojdwacTEehlg4Ztp40AjQfDmDGwOrXk0eHKSL 1HOOvqtE0Yf8lmjelC/m8P6J6JXiavB519xeyVSLK7ZSMlsmC3qikBc6NW5ZlQf3j+uv beW8MFjhm7/XDAf+VcqJdQByT/mTlNZA2Pg7oZ1tDAJOVsO84QWR36tVMx3zIxBtgefG zKT3vgqIaiqdi5+exebc9rpFoWMTUZG59a9Vn5Ct2MCnZ943HhbTSCTQOzh829pFsdSj fQVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=L08+yYfUa4/4fG9INuh22rKNPpKoqshaYos5skwuxCo=; b=EgtDpzrmxDvW1pKKOXLai8OEM7mULvzfvwGdI8m7scFGVFZGLbavQEJmcH79jdVdcf bXLi4FCngwcuEUIsCfb2BYvWR1zoiUvPlls6KXbvIX0YENt8oMyhGcUAqtGPxNqjn/nF IOZXYe/t1jLyhEjh9Y3OACtxIp//isw1LLbrP1H9Od1n72WVriknmJHBuvZHpfV5CX+q cMA4IP+I2yhQEwGzCqVsNnsmF36xOk37OTHmJtDdx5mBOJCG3r0Q1yZziu0vO5vUpmki eOataA/BK34pOxC62A6Gi3MWETnrxhUF8KT7+k8fhxedAwccg88mrBo4I3yTvVt4//hF Bpzw== X-Gm-Message-State: AOAM530LYRo7Lr8P0Qe4ptKtbaCrKczMSChnEAhr1BDnLDdCYOfqcb6v eTujGpGm8aKwcg538BkCGcjkqTRy X-Google-Smtp-Source: ABdhPJzEe/nHpbTfmTDvHtyzjItHzJ1oASRIUqwnLD+SQYZNr77a6mvsw3zAd2QuO6Cg5j7Ygoz2Ow== X-Received: by 2002:a7b:ce83:: with SMTP id q3mr4906935wmj.5.1596664313487; Wed, 05 Aug 2020 14:51:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t25sm3924389wmj.18.2020.08.05.14.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 14:51:53 -0700 (PDT) Message-Id: <764bb23b5974214335cc6a93fb4eab46e8f2a49b.1596664306.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 05 Aug 2020 21:51:42 +0000 Subject: [PATCH v2 6/9] ref-filter: add `short` modifier to 'parent' atom Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma Sometimes while using 'parent' atom, user might want to see abbrev hash instead of full 40 character hash. Just like 'objectname', it might be convenient for users to have the `:short` and `:short=` option for printing 'parent' hash. Let's introduce `short` option to 'parent' atom. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- Documentation/git-for-each-ref.txt | 2 +- ref-filter.c | 8 ++++---- t/t6300-for-each-ref.sh | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 40ebdfcc41..dd09763e7d 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -222,7 +222,7 @@ worktreepath:: In addition to the above, for commit and tag objects, the header field names (`tree`, `parent`, `object`, `type`, and `tag`) can be used to specify the value in the header field. -Field `tree` can also be used with modifier `:short` and +Fields `tree` and `parent` can also be used with modifier `:short` and `:short=` just like `objectname`. For commit and tag objects, the special `creatordate` and `creator` diff --git a/ref-filter.c b/ref-filter.c index f9d85661eb..6d5bbb14a2 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -498,7 +498,7 @@ static struct { { "objectname", SOURCE_OTHER, FIELD_STR, oid_atom_parser }, { "deltabase", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser }, { "tree", SOURCE_OBJ, FIELD_STR, oid_atom_parser }, - { "parent", SOURCE_OBJ }, + { "parent", SOURCE_OBJ, FIELD_STR, oid_atom_parser }, { "numparent", SOURCE_OBJ, FIELD_ULONG }, { "object", SOURCE_OBJ }, { "type", SOURCE_OBJ }, @@ -1011,14 +1011,14 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object v->value = commit_list_count(commit->parents); v->s = xstrfmt("%lu", (unsigned long)v->value); } - else if (!strcmp(name, "parent")) { + else if (starts_with(name, "parent")) { struct commit_list *parents; struct strbuf s = STRBUF_INIT; for (parents = commit->parents; parents; parents = parents->next) { - struct commit *parent = parents->item; + struct object_id *oid = &parents->item->object.oid; if (parents != commit->parents) strbuf_addch(&s, ' '); - strbuf_addstr(&s, oid_to_hex(&parent->object.oid)); + strbuf_addstr(&s, do_grab_oid("parent", oid, &used_atom[i])); } v->s = strbuf_detach(&s, NULL); } diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index e30bbff6d9..79d5b29387 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -120,6 +120,9 @@ test_atom head tree:short $(git rev-parse --short refs/heads/master^{tree}) test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/master^{tree}) test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/master^{tree}) test_atom head parent '' +test_atom head parent:short '' +test_atom head parent:short=1 '' +test_atom head parent:short=10 '' test_atom head numparent 0 test_atom head object '' test_atom head type '' @@ -174,6 +177,9 @@ test_atom tag tree:short '' test_atom tag tree:short=1 '' test_atom tag tree:short=10 '' test_atom tag parent '' +test_atom tag parent:short '' +test_atom tag parent:short=1 '' +test_atom tag parent:short=10 '' test_atom tag numparent '' test_atom tag object $(git rev-parse refs/tags/testtag^0) test_atom tag type 'commit' From patchwork Wed Aug 5 21:51:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11702581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 974FE1510 for ; Wed, 5 Aug 2020 21:52:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83FA022CBB for ; Wed, 5 Aug 2020 21:52:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I6AoF8J3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726634AbgHEVwI (ORCPT ); Wed, 5 Aug 2020 17:52:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726542AbgHEVv4 (ORCPT ); Wed, 5 Aug 2020 17:51:56 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03E82C06179E for ; Wed, 5 Aug 2020 14:51:56 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id c19so5232203wmd.1 for ; Wed, 05 Aug 2020 14:51:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=/3K3rLxxpmRR344POofiaEMr0WkE1QzMRZWO54dh4ts=; b=I6AoF8J3SIXjNSQGCwvkGlsn4AQcV/sZXhSrR4cP28Fa+lPh3BdT0mthoaHk85xN/H G8tGD73x4XZoJcK+GSwHaoDkfRqQUxnTmweI+6ejxetK5/eztJ+fh4BxpdQ8xHBMheXl KLfzeWPEt1JAX0Jo2oRPgXW9WKZtNcA8BeIaDS0WINGy35cjMwDlVubH2oigvsT3Lz7Z hA2+53+5G5nmXVDCUyatfaujfiJl4jiayQ50wZQhD1SCvQRw1gbd68+qgK0vPizkX1Ek 5BD9O0LXhGA9waUWt+slmEYd/k8kdwZIz+QRBXN/sW521UDmqlx5/o62P6jNS317fsKh ++FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=/3K3rLxxpmRR344POofiaEMr0WkE1QzMRZWO54dh4ts=; b=ubBttjAN9aWvdI8VXsVuLVFXT83Ck8/3bDTYMHJLnMoy53J3lRXiAk/hru0WzG2hMo Ex1dhg0Omoewhg9icILmxzIayk0VxKpP1JYL+Er/zmn4bMGWnD8zE5UlUKCAdrw10URC /1URAieaY7SZwJB8hS82XoKh5fGV7qhdgH1GR+gbQcllSLlRbG/7ILZv0F1xx652uhK/ cJ4poOLCLHgvPIwXauHa+8pdn48XpX2susc89Lr0FPj4NxmEUrwhGLEWqWgJCr/SAC1v EXHfwZffWiI9G8cSMdg+I/zsQNC4N59V4i3S+4ZQDIiaWVGMZQM8QhZ7zi9+zWTTaeXa YHjA== X-Gm-Message-State: AOAM531WRhcVbU7kvZ3temYCsEMyMHTYZd70p1PEh5i4IFAG7lBUi+7/ RX4TDQhtUku9m3KXhNHRwMHKV7bM X-Google-Smtp-Source: ABdhPJzJUqhSpAoIu+c5SCSaQXm0cTwG2X/4+CbClP924UB+BWt9m/QHiS0a9lHCMh7YSFPL23ZyAQ== X-Received: by 2002:a05:600c:2116:: with SMTP id u22mr4941224wml.35.1596664314545; Wed, 05 Aug 2020 14:51:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f16sm3807786wro.34.2020.08.05.14.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 14:51:53 -0700 (PDT) Message-Id: <95035765a00b4d553c2c43773bc1ab65c3c2ede9.1596664306.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 05 Aug 2020 21:51:43 +0000 Subject: [PATCH v2 7/9] pretty: refactor `format_sanitized_subject()` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma The function 'format_sanitized_subject()' is responsible for sanitized subject line in pretty.c e.g. the subject line the-sanitized-subject-line It would be a nice enhancement to `subject` atom to have the same feature. So in the later commits, we plan to add this feature to ref-filter. Refactor `format_sanitized_subject()`, so it can be reused in ref-filter.c for adding new modifier `sanitize` to "subject" atom. Currently, the loop inside `format_sanitized_subject()` runs until `\n` is found. But now, we stored the first occurrence of `\n` in a variable `eol` and passed it in `format_sanitized_subject()`. And the loop runs upto `eol`. But this change isn't sufficient to reuse this function in ref-filter.c because there exist tags with multiline subject. It's wise to replace `\n` with ' ', if `format_sanitized_subject()` encounters `\n` before end of subject line, just like `copy_subject()`. Because we'll be only using `format_sanitized_subject()` for "%(subject:sanitize)", instead of `copy_subject()` and `format_sanitized_subject()` both. So, added the code: ``` if (char == '\n') /* never true if called inside pretty.c */ char = ' '; ``` Now, it's ready to be reused in ref-filter.c Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- pretty.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pretty.c b/pretty.c index 2a3d46bf42..8d08e8278a 100644 --- a/pretty.c +++ b/pretty.c @@ -839,24 +839,29 @@ static int istitlechar(char c) (c >= '0' && c <= '9') || c == '.' || c == '_'; } -static void format_sanitized_subject(struct strbuf *sb, const char *msg) +static void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len) { + char *r = xmemdupz(msg, len); size_t trimlen; size_t start_len = sb->len; int space = 2; + int i; - for (; *msg && *msg != '\n'; msg++) { - if (istitlechar(*msg)) { + for (i = 0; i < len; i++) { + if (r[i] == '\n') + r[i] = ' '; + if (istitlechar(r[i])) { if (space == 1) strbuf_addch(sb, '-'); space = 0; - strbuf_addch(sb, *msg); - if (*msg == '.') - while (*(msg+1) == '.') - msg++; + strbuf_addch(sb, r[i]); + if (r[i] == '.') + while (r[i+1] == '.') + i++; } else space |= 1; } + free(r); /* trim any trailing '.' or '-' characters */ trimlen = 0; @@ -1155,7 +1160,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ const struct commit *commit = c->commit; const char *msg = c->message; struct commit_list *p; - const char *arg; + const char *arg, *eol; size_t res; char **slot; @@ -1405,7 +1410,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ format_subject(sb, msg + c->subject_off, " "); return 1; case 'f': /* sanitized subject */ - format_sanitized_subject(sb, msg + c->subject_off); + eol = strchrnul(msg + c->subject_off, '\n'); + format_sanitized_subject(sb, msg + c->subject_off, eol - (msg + c->subject_off)); return 1; case 'b': /* body */ strbuf_addstr(sb, msg + c->body_off); From patchwork Wed Aug 5 21:51:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11702577 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F16061510 for ; Wed, 5 Aug 2020 21:52:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DEE2C22CAF for ; Wed, 5 Aug 2020 21:52:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LaB41Hmg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726629AbgHEVwH (ORCPT ); Wed, 5 Aug 2020 17:52:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726547AbgHEVv5 (ORCPT ); Wed, 5 Aug 2020 17:51:57 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5CA0C06179F for ; Wed, 5 Aug 2020 14:51:56 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id p14so7093753wmg.1 for ; Wed, 05 Aug 2020 14:51:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=H7l2w2s3HhCb+5oejFFtuQYCJu1bxocpCZKJxQqgaLA=; b=LaB41Hmg4JKLn7V6qgGLqVRbsKSnyJVJ/brpDFxacAEPcYnZ9neydxArXqeve9JKgQ lJz8VbL6/ARaOtkqVMS8oAxBRTj9d8a4lpPAXb0ulOsQJEK0RlX+3j8TWumjZXX1mcdT faYsSgnv/InDe5AYArSrC51lll7sxv4+XyFyfpcHPwAcGzlnU2B3n5/lEdmdPN+cr/oY y/F6pCpOU0qbYfsju8yAHLHFvMw8lmI7F1bGm5rkf3HCfTEVhitCtkoO2deFjxcwAihZ urDxrfLtLGBBj5D/eYRiJfI017ylw6682VFXbSm4oDyyGfj56WISXVak29QsHM0vvAwn CeWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=H7l2w2s3HhCb+5oejFFtuQYCJu1bxocpCZKJxQqgaLA=; b=JeFsrmUG1NkpbZi51ScHz8AUAe0mag++t9GVFyePCXXU1dIi5WnfMzLi7CJhGi/J9W Ej/xChU9Vjcr6h1Z62WTFYu12Z6Q42eH43imwgrxw26J9KyT5UeRA7bBrFy58WMnHMvy h/xfJjumInBzaxIgd8NpoZcbUjMm32pBLsMWjYZvepxMDSfwlX+z9fSkL1nwEncP7WcA X0PJTXqE3qKBsR6WLhvvVZ6z7pj9kJOr0IQrhfwrdLkmjb6tjUT7iBsmiPfoHC/aGfdn reyeOaPjgnHt348ulKKtGMyKFvJqsaCWAOjPGga7eGpCAkuFhWRjT6rtnF9Tta8gedPn xPKw== X-Gm-Message-State: AOAM530D++hrKHXGrP9PoMQ2hU/ZgCi9nhGrH+dCuGcrOdn8dyoPdG6a 46wvhJUZx8ff5q3h8FCca+BiYZy0 X-Google-Smtp-Source: ABdhPJyA3SOtC4wZlkYK14pnCMVfIQJicN0nbD1heAHgOGbayOT1BZP85CUA48IwYggZEPx7+fw+QQ== X-Received: by 2002:a7b:c7c6:: with SMTP id z6mr5330322wmk.17.1596664315348; Wed, 05 Aug 2020 14:51:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g18sm4389642wru.27.2020.08.05.14.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 14:51:55 -0700 (PDT) Message-Id: <1c43f55d7c1d5a16031115d5de56b5a5302b5597.1596664306.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 05 Aug 2020 21:51:44 +0000 Subject: [PATCH v2 8/9] format-support: move `format_sanitized_subject()` from pretty Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma In hope of some new features in `subject` atom, move funtion `format_sanitized_subject()` and all the function it uses to new file format-support.{c,h}. Consider this new file as a common interface between functions that pretty.c and ref-filter.c shares. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- Makefile | 1 + format-support.c | 43 +++++++++++++++++++++++++++++++++++++++++++ format-support.h | 6 ++++++ pretty.c | 40 +--------------------------------------- 4 files changed, 51 insertions(+), 39 deletions(-) create mode 100644 format-support.c create mode 100644 format-support.h diff --git a/Makefile b/Makefile index 372139f1f2..4dfc384b49 100644 --- a/Makefile +++ b/Makefile @@ -882,6 +882,7 @@ LIB_OBJS += exec-cmd.o LIB_OBJS += fetch-negotiator.o LIB_OBJS += fetch-pack.o LIB_OBJS += fmt-merge-msg.o +LIB_OBJS += format-support.o LIB_OBJS += fsck.o LIB_OBJS += fsmonitor.o LIB_OBJS += gettext.o diff --git a/format-support.c b/format-support.c new file mode 100644 index 0000000000..d693aa1744 --- /dev/null +++ b/format-support.c @@ -0,0 +1,43 @@ +#include "diff.h" +#include "log-tree.h" +#include "color.h" +#include "format-support.h" + +static int istitlechar(char c) +{ + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9') || c == '.' || c == '_'; +} + +void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len) +{ + char *r = xmemdupz(msg, len); + size_t trimlen; + size_t start_len = sb->len; + int space = 2; + int i; + + for (i = 0; i < len; i++) { + if (r[i] == '\n') + r[i] = ' '; + if (istitlechar(r[i])) { + if (space == 1) + strbuf_addch(sb, '-'); + space = 0; + strbuf_addch(sb, r[i]); + if (r[i] == '.') + while (r[i+1] == '.') + i++; + } else + space |= 1; + } + free(r); + + /* trim any trailing '.' or '-' characters */ + trimlen = 0; + while (sb->len - trimlen > start_len && + (sb->buf[sb->len - 1 - trimlen] == '.' + || sb->buf[sb->len - 1 - trimlen] == '-')) + trimlen++; + strbuf_remove(sb, sb->len - trimlen, trimlen); +} diff --git a/format-support.h b/format-support.h new file mode 100644 index 0000000000..c344ccbc33 --- /dev/null +++ b/format-support.h @@ -0,0 +1,6 @@ +#ifndef FORMAT_SUPPORT_H +#define FORMAT_SUPPORT_H + +void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len); + +#endif /* FORMAT_SUPPORT_H */ diff --git a/pretty.c b/pretty.c index 8d08e8278a..2de01b7115 100644 --- a/pretty.c +++ b/pretty.c @@ -12,6 +12,7 @@ #include "reflog-walk.h" #include "gpg-interface.h" #include "trailer.h" +#include "format-support.h" static char *user_format; static struct cmt_fmt_map { @@ -833,45 +834,6 @@ static void parse_commit_header(struct format_commit_context *context) context->commit_header_parsed = 1; } -static int istitlechar(char c) -{ - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || c == '.' || c == '_'; -} - -static void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len) -{ - char *r = xmemdupz(msg, len); - size_t trimlen; - size_t start_len = sb->len; - int space = 2; - int i; - - for (i = 0; i < len; i++) { - if (r[i] == '\n') - r[i] = ' '; - if (istitlechar(r[i])) { - if (space == 1) - strbuf_addch(sb, '-'); - space = 0; - strbuf_addch(sb, r[i]); - if (r[i] == '.') - while (r[i+1] == '.') - i++; - } else - space |= 1; - } - free(r); - - /* trim any trailing '.' or '-' characters */ - trimlen = 0; - while (sb->len - trimlen > start_len && - (sb->buf[sb->len - 1 - trimlen] == '.' - || sb->buf[sb->len - 1 - trimlen] == '-')) - trimlen++; - strbuf_remove(sb, sb->len - trimlen, trimlen); -} - const char *format_subject(struct strbuf *sb, const char *msg, const char *line_separator) { From patchwork Wed Aug 5 21:51:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 11702579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B16813B6 for ; Wed, 5 Aug 2020 21:52:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07DAE22CBB for ; Wed, 5 Aug 2020 21:52:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xp8lQbmA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726624AbgHEVwG (ORCPT ); Wed, 5 Aug 2020 17:52:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726551AbgHEVv7 (ORCPT ); Wed, 5 Aug 2020 17:51:59 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D62EC0617A0 for ; Wed, 5 Aug 2020 14:51:57 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id p14so7093782wmg.1 for ; Wed, 05 Aug 2020 14:51:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=eayZ8iqKjfrVZq20Nn41q2KGBtxB2MvtcvFO0SPVCGM=; b=Xp8lQbmAtIPdT31KdCWMqlK0bQk+6tNO8xSzvfSllUI33lx8PvSDY2VUV2b/IcAhvm vdBkQqyglHss+bEpmtBmsi4Wr3AS3UPD0fXQcxsvvWQivjZVbL1XhfR7A8Rpx9xvVciP Y8zJgIGtzqg8/ObgMXnsPdDYFC1GBygAGhr58wwuKXgqiOGVYef0iFNNLMtmbBuFCzet icZyx1YHNouvmLKTQrednw9m7OHEHGSaXjBFyt7VT/ejlkgUytgVCfG3TPta5g+jo5+d xO+DKVKLrhvF0Ze3mtyzCEz/P/enhPAc2XE+ghPLivDYZKv22Z4kjdszp3kTjo+CyDwP 1MxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=eayZ8iqKjfrVZq20Nn41q2KGBtxB2MvtcvFO0SPVCGM=; b=cf3h8Mq+4EeSHUOiEG5Nej5RdMK1qfAGmGNSsZQeqaSoxU+z56mzPzghqwD8Hi0211 4BCj98nTN2rjNSmFEBJQTf2G80Eht4DZ/bbTvzvB/JIk7xpiNZr4IJJohaW5InOuGXPE IxWBRgWgrWpcBSgdvqyW7v3/wCopNt7m/ePOIFJvFvSvYD+zEgmr70+7vpsZ9U2SLAA2 jDudOvleUa9ztaNRxW4cvidsfN8aUraX/sFQ/Ou+H/SboE9P0hQNlo3oTWUpu42knfvd 1WKf/5Xm6xJh2A8LXW25lynNVTiJS4TGUNcTpYKpnzp7UXTYA55NwP7VCUltBXSAgo55 xH/A== X-Gm-Message-State: AOAM5326EjSUbpuzhLMIyi2+lJIZV+7/JDwhKbOmPfcyE3qvi2dYGQWq Lm2q91WfUZb67K+wJZhHUjS/eDj1 X-Google-Smtp-Source: ABdhPJwu4ZVeuQVZw9mGDcY/mXkWY/KS4QzSBcubiQPlUXpcrS9l2l0rCt9bOGCmMpUjn6+PAxdm4g== X-Received: by 2002:a7b:c24e:: with SMTP id b14mr5355200wmj.128.1596664316144; Wed, 05 Aug 2020 14:51:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e16sm4201978wrx.30.2020.08.05.14.51.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 14:51:55 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Wed, 05 Aug 2020 21:51:45 +0000 Subject: [PATCH v2 9/9] ref-filter: add `sanitize` option for 'subject' atom Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Hariom Verma , Hariom Verma Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Hariom Verma Currently, subject does not take any arguments. This commit introduce `sanitize` formatting option to 'subject' atom. `subject:sanitize` - print sanitized subject line, suitable for a filename. e.g. %(subject): "the subject line" %(subject:sanitize): "the-subject-line" Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- Documentation/git-for-each-ref.txt | 3 +++ ref-filter.c | 24 ++++++++++++++++-------- t/t6300-for-each-ref.sh | 7 +++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index dd09763e7d..616ce46087 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -247,6 +247,9 @@ contents:subject:: The first paragraph of the message, which typically is a single line, is taken as the "subject" of the commit or the tag message. + Instead of `contents:subject`, field `subject` can also be used to + obtain same results. `:sanitize` can be appended to `subject` for + subject line suitable for filename. contents:body:: The remainder of the commit or the tag message that follows diff --git a/ref-filter.c b/ref-filter.c index 6d5bbb14a2..016a03ef20 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -23,6 +23,7 @@ #include "worktree.h" #include "hashmap.h" #include "argv-array.h" +#include "format-support.h" static struct ref_msg { const char *gone; @@ -127,8 +128,8 @@ static struct used_atom { unsigned int nobracket : 1, push : 1, push_remote : 1; } remote_ref; struct { - enum { C_BARE, C_BODY, C_BODY_DEP, C_LENGTH, - C_LINES, C_SIG, C_SUB, C_TRAILERS } option; + enum { C_BARE, C_BODY, C_BODY_DEP, C_LENGTH, C_LINES, + C_SIG, C_SUB, C_SUB_SANITIZE, C_TRAILERS } option; struct process_trailer_options trailer_opts; unsigned int nlines; } contents; @@ -301,9 +302,12 @@ static int body_atom_parser(const struct ref_format *format, struct used_atom *a static int subject_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) { - if (arg) - return strbuf_addf_ret(err, -1, _("%%(subject) does not take arguments")); - atom->u.contents.option = C_SUB; + if (!arg) + atom->u.contents.option = C_SUB; + else if (!strcmp(arg, "sanitize")) + atom->u.contents.option = C_SUB_SANITIZE; + else + return strbuf_addf_ret(err, -1, _("unrecognized %%(subject) argument: %s"), arg); return 0; } @@ -1282,8 +1286,8 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf) continue; if (deref) name++; - if (strcmp(name, "subject") && - strcmp(name, "body") && + if (strcmp(name, "body") && + !starts_with(name, "subject") && !starts_with(name, "trailers") && !starts_with(name, "contents")) continue; @@ -1295,7 +1299,11 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf) if (atom->u.contents.option == C_SUB) v->s = copy_subject(subpos, sublen); - else if (atom->u.contents.option == C_BODY_DEP) + else if (atom->u.contents.option == C_SUB_SANITIZE) { + struct strbuf sb = STRBUF_INIT; + format_sanitized_subject(&sb, subpos, sublen); + v->s = strbuf_detach(&sb, NULL); + } else if (atom->u.contents.option == C_BODY_DEP) v->s = xmemdupz(bodypos, bodylen); else if (atom->u.contents.option == C_LENGTH) v->s = xstrfmt("%"PRIuMAX, (uintmax_t)strlen(subpos)); diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 79d5b29387..220ff5c3c2 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -150,6 +150,7 @@ test_atom head taggerdate '' test_atom head creator 'C O Mitter 1151968723 +0200' test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200' test_atom head subject 'Initial' +test_atom head subject:sanitize 'Initial' test_atom head contents:subject 'Initial' test_atom head body '' test_atom head contents:body '' @@ -207,6 +208,7 @@ test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200' test_atom tag creator 'C O Mitter 1151968725 +0200' test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200' test_atom tag subject 'Tagging at 1151968727' +test_atom tag subject:sanitize 'Tagging-at-1151968727' test_atom tag contents:subject 'Tagging at 1151968727' test_atom tag body '' test_atom tag contents:body '' @@ -619,6 +621,7 @@ test_expect_success 'create tag with subject and body content' ' git tag -F msg subject-body ' test_atom refs/tags/subject-body subject 'the subject line' +test_atom refs/tags/subject-body subject:sanitize 'the-subject-line' test_atom refs/tags/subject-body body 'first body line second body line ' @@ -639,6 +642,7 @@ test_expect_success 'create tag with multiline subject' ' git tag -F msg multiline ' test_atom refs/tags/multiline subject 'first subject line second subject line' +test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line' test_atom refs/tags/multiline contents:subject 'first subject line second subject line' test_atom refs/tags/multiline body 'first body line second body line @@ -671,6 +675,7 @@ sig='-----BEGIN PGP SIGNATURE----- PREREQ=GPG test_atom refs/tags/signed-empty subject '' +test_atom refs/tags/signed-empty subject:sanitize '' test_atom refs/tags/signed-empty contents:subject '' test_atom refs/tags/signed-empty body "$sig" test_atom refs/tags/signed-empty contents:body '' @@ -678,6 +683,7 @@ test_atom refs/tags/signed-empty contents:signature "$sig" test_atom refs/tags/signed-empty contents "$sig" test_atom refs/tags/signed-short subject 'subject line' +test_atom refs/tags/signed-short subject:sanitize 'subject-line' test_atom refs/tags/signed-short contents:subject 'subject line' test_atom refs/tags/signed-short body "$sig" test_atom refs/tags/signed-short contents:body '' @@ -686,6 +692,7 @@ test_atom refs/tags/signed-short contents "subject line $sig" test_atom refs/tags/signed-long subject 'subject line' +test_atom refs/tags/signed-long subject:sanitize 'subject-line' test_atom refs/tags/signed-long contents:subject 'subject line' test_atom refs/tags/signed-long body "body contents $sig"