From patchwork Fri Aug 21 21:41:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11730595 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 2651D138C for ; Fri, 21 Aug 2020 21:42:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0918A207DE for ; Fri, 21 Aug 2020 21:42:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VoGALuv2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726801AbgHUVl7 (ORCPT ); Fri, 21 Aug 2020 17:41:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726457AbgHUVly (ORCPT ); Fri, 21 Aug 2020 17:41:54 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24D0AC061573 for ; Fri, 21 Aug 2020 14:41:54 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id y3so3198988wrl.4 for ; Fri, 21 Aug 2020 14:41: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=ZyGaiMZDKkBCk7ZUMG6MB7U2gFaGky2dAue7wegcrQI=; b=VoGALuv2e8+T4S5fmMcrXo14Cn4b+GGSqbuZKZcLvFNIzZWuGQ3M7SOQmazPlQh4Mt rpHBU0Aqy16ClEOjTfQ3K4I2ang+3FFGzjUfHbWmKHV6ll7gciWa1YaJG0Uqao283UAN 3OimZEclSDiptHab4fJgqKYL+wqZAdC0g918eQK1JvmLoQb8zorbtXLL7AylQFYHAEf2 Om/bJKZ18b3Z5+BfzV+sMiiMyPBuezbnVa06Zc/svKOMJMl1gMncwyWdUWdaZ0mlFO0G SsEbOjFN1uxK5sZMm4Ld68s6rEQQCRuH+jjjsST6SSfiLFvgCBYdt+Y1DpmZT06f0uF1 njnw== 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=ZyGaiMZDKkBCk7ZUMG6MB7U2gFaGky2dAue7wegcrQI=; b=KwlMRHWj9Qh7teNTC3gVJnkLFxL12VcMhChgHhUQhuHArKQfZ3c9SL678XGhXKo0wP UaKuBBUhIXk6y0+5ucXOT6PKLA2FE7i2PnJa2oHXYuhQKbA6H5E83EHp2FUXqDrqBA46 X0MRt9aQUVIkUoDi3Uqid1tTSF3YCTrZovqDxMjBPRsAmJU93rVtsw0MjIde3KzRTl9X +VRPHyyUK9Bb0MfJCfF0eYPvxVg5J7XVoaBHNYFHzbFkAMum49r2mJx8Cn1l1Bmf8L6Z pYMM8i5S3umc/6FK1gUeQTb9il4OE0/0N6CfisWR7DabA2CTEakpdMTvq08Zi6DSmJhZ yK8g== X-Gm-Message-State: AOAM5337A3SWje/p2OQZ/BC76IlEqaaWZmErurM+OXN0CIrQx4hebGQe Xx4Z/mUTfj/t7S7+2j7G3WhFnjm1pt8= X-Google-Smtp-Source: ABdhPJxHivsEyBCUmAj2vfolHgXEITmOAhv++aMoD4q0l4cnNVdBtzlHbjqsUHIZuCvHbmZSKOdrHw== X-Received: by 2002:adf:e94c:: with SMTP id m12mr4364300wrn.109.1598046112373; Fri, 21 Aug 2020 14:41:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d21sm8473602wmd.41.2020.08.21.14.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 14:41:51 -0700 (PDT) Message-Id: <55618fe4c1ea96fb0c2734121f8a54a921fb0aff.1598046110.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Fri, 21 Aug 2020 21:41:43 +0000 Subject: [PATCH v4 1/8] 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 ba85869755..e60765f156 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 Fri Aug 21 21:41:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11730599 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 DD1F81392 for ; Fri, 21 Aug 2020 21:42:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C24B2207DA for ; Fri, 21 Aug 2020 21:42:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bmSpUYkK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726817AbgHUVmC (ORCPT ); Fri, 21 Aug 2020 17:42:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbgHUVlz (ORCPT ); Fri, 21 Aug 2020 17:41:55 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14C2BC061574 for ; Fri, 21 Aug 2020 14:41:55 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id g75so3125614wme.4 for ; Fri, 21 Aug 2020 14:41: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=PSLsgbsMTwXOlHbD5s/hbx0sdlArgiwvBIPDoMGVOgM=; b=bmSpUYkKKjj7u3VWijAPgIEP3j4jAaadmetJlOSyhLWM4KNBArnA6yfQ3HbBSe1NHu u+0z7Lk1fB1md01CTmGPFfsTEM1XyZ7mX6hilzClIroQFToNSp+XWHOPMxlc9EooXBH3 GkJfLqsBkT+iBz5udBuYTlD4K0PIMDUMw5GDsT0TVFJJCBymEc71WAtr2ESNVQ3a3xz0 1svFAOGfRJdsAHScWBVK/ijL+/ZFkajlvNxOdwZYPJMpES3VjanFHsXZ1tB3dA6Rbriy /YXP6nVFsmytGPXCjtg93dE36EyvnignhS6lyHGE7SqaXgFWGTIgav/F3/PE9EB87rFQ rUKQ== 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=PSLsgbsMTwXOlHbD5s/hbx0sdlArgiwvBIPDoMGVOgM=; b=Dk+IU1MWXbkO5AJ2S5MTdjeYo9FBfzozvcvECCsrobCRO2s4OrZTMCBx84FBFTlZno jPWbwQJ/GhIS4ITY79hUMrBqDKCU5il1F7I4Pk1Ujm/rJIpy2Z8x4/yyEUPJdjYRed8m Sqvs3ZjP5J9s/e/TANYJUN+CG1GTKiz5Ztn4ebl0cK17rd0RUFQn+yVCoQ+1VsPWq4TF xTSyLSSDh5Y/fBF0xILsRTyUSGqcRKQSqEri/WYnhcOZ4BFGViDL44G9SAoGOCmdYcsp mq0nxabDR/cdAGMIgE79uDUtyiJRR+c2t6QsWml+LE8d3Ox4mtss7eDwPnRR3UBXMNUK vrCg== X-Gm-Message-State: AOAM532lz+1RdDuULEU+rQGKrANfuoItTUFA0Uw5IOxN3YvindDOraYC nI2OKxqPBClyfLz3tZ2HMbxS112x7ZM= X-Google-Smtp-Source: ABdhPJxa8CeqiCvxiqu5b90Ic62dXlyrC45wmfbXhus56XbsUomJZKaBwHAJONU+Gs1YWMiGUQeEwQ== X-Received: by 2002:a1c:1b8f:: with SMTP id b137mr5221054wmb.151.1598046113661; Fri, 21 Aug 2020 14:41:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y142sm8205274wmd.3.2020.08.21.14.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 14:41:52 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Fri, 21 Aug 2020 21:41:44 +0000 Subject: [PATCH v4 2/8] 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 e60765f156..9bf92db6df 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 Fri Aug 21 21:41:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11730601 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 76BAF1731 for ; Fri, 21 Aug 2020 21:42:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DC24207DE for ; Fri, 21 Aug 2020 21:42:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h8Y5hqa1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726818AbgHUVmH (ORCPT ); Fri, 21 Aug 2020 17:42:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726793AbgHUVl4 (ORCPT ); Fri, 21 Aug 2020 17:41:56 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D130BC061575 for ; Fri, 21 Aug 2020 14:41:55 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id l2so3191790wrc.7 for ; Fri, 21 Aug 2020 14:41: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=cRalOlriif3z6cxzVgA5CoycAdB4v2Pz0Kz77A3aYd8=; b=h8Y5hqa19BbjHAmI4mKX5IysKkasZlStRHKa+SSxo3wRa1gPVQTU2bodFWyf8YcEZw KHysO+nyC2kjIW1aiE4J8fI301p0iEK5BTnTxlNhgcP90/sbX6IipiuMORPVM8zMGjtw b06cJA3+MF8HOiEPSVXJLLws1wOhPSiHG9Rzz1VhvLibE8UQMFHSv4wzZC5Itdot1XNC lyP4Ij0bHrb2ohFWt/lXQcHErN4MLsnleKExeINwRPvu7ZQAQBNXz9x/mssWKUAzEL06 wjdO5OuXSj/07n4rR7wy3T7w4xTZwlVpIRUCqzGZX3sKEWcbAGuFRl4a2DY0p1FOm8Lx +TGQ== 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=cRalOlriif3z6cxzVgA5CoycAdB4v2Pz0Kz77A3aYd8=; b=f+Y45cz82qB1q2RZHxpGEcEq9XyjY7ipYzX7PQ/ZD2tYaERiR6XRdgYc9bAi/ikYYn 3+BnLWRRFSlFU0vjvOXbUS/UfcINlnRAeyO212Zb3t1Xwg4Y0kZJUdH0dwE5ucN+8/AU tckQkuE5Llb0h/+8zYDWxpYB6YhZZzhtmzN/jgWaRhybP8u/XoVBSpqTyYVWX5cavhUz vzgwCdd9ZUQwSbmW6ashTcvnJHkQk9sC2F4j+Q8t+NNei44wgjjV9qVocaM2wnS2gs35 8fIjFkUfjtr6HyxO5mfQOTxvLr2le+sSx56Rb+mg8ZX0dZL21kPsl1VzWuQAeOHmXX6+ cErg== X-Gm-Message-State: AOAM5334Da/cThompQjAR3mfJYHUvnvz5wTNqU2/e1iZJdk8UKLJgM0i +5jGawXeSUSJRWqCl55jRunAqcbSTFI= X-Google-Smtp-Source: ABdhPJxY6pwHTg3OXHFkBLNVVo9bnC0E+l/bCMiN3kTptPsldvCEiZAok8CMv37ovD8d9GMfQOrR9A== X-Received: by 2002:adf:e911:: with SMTP id f17mr4289353wrm.397.1598046114411; Fri, 21 Aug 2020 14:41:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m16sm6348608wrr.71.2020.08.21.14.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 14:41:54 -0700 (PDT) Message-Id: <582f00ace6b3173cfebb3f6e5d859f471ea01ab7.1598046110.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Fri, 21 Aug 2020 21:41:45 +0000 Subject: [PATCH v4 3/8] 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 9bf92db6df..4f4591cad0 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 Fri Aug 21 21:41:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11730609 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 38DB11731 for ; Fri, 21 Aug 2020 21:42:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22913207DE for ; Fri, 21 Aug 2020 21:42:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SMi2AuX+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726825AbgHUVmI (ORCPT ); Fri, 21 Aug 2020 17:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726794AbgHUVl5 (ORCPT ); Fri, 21 Aug 2020 17:41:57 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABA27C061755 for ; Fri, 21 Aug 2020 14:41:56 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id b66so880104wmb.1 for ; Fri, 21 Aug 2020 14:41: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=Je82nXeOGu8QL9bFt/iOItm11C3ZGeKZmAsav9TQxm8=; b=SMi2AuX+bhUFnQPSdh/rOfD/108mJ2N0QEBa6FQ/ThSmMqU1tLGnQK0PEd8+VR8chU b59AeTW40e0t1g8We89ocPRhd67ZIx6TMf2X9C7G3i8X3PcZIYomkuHILLS7+3foPkLF 7W5/7Wdiyqm8slTCthzBw/dLUt84HRsfk4X197knymk+1Lh3G60p7cYD5vBphgJUkXMu +1LZXhK5bpZH6Te7T2jKOIot27ieIweM+HMvAiCrl4yodMAy8Mll1cDPexhfDRYAIG03 hq7WoatUhq64tFOESADHbn4sICxLFNcAOH25JhGTPT5p5MoaL4+0BhZYr++k+iDT+YUA RwTA== 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=Je82nXeOGu8QL9bFt/iOItm11C3ZGeKZmAsav9TQxm8=; b=oR/tt+ImTrY2GgrzyGoJLi7q0sUSnPW8EO7PCktluW/5LzZp7Vs6V0nq/Riv3zjcJD R3VcFmr24TEOp7pSWPFMHoE4fNWCt01t0/vfvDLXyLwDRFbk9yITcwMIFk0XTn+YiBe2 sv9lRgM4iZjMRLL1nCSlHJSeEVFYBnvh4Dhi8jBo/bLDekal2Xl1C/FcKYTrd5Lh0hdC NNc787OmfZJ5+io2vLc8e4Vn9YfjBdaRvg0lkGulx/Kf11HabYowINEBQ/fuxmq7VECH ObUKH1MhuIjeLShPPpUk63AuuIymybaMfNTQ+Va/lvUYYcgduhuP3DoqtotXCtt4lTN0 ElHA== X-Gm-Message-State: AOAM530hAMXU7GFgSEFZzEr3Y/WjDsZ+V7H1R8yh9bTLPwUONUS86sjo 7hElWZyomsirZL4TSoKPN/ThgDRf4BM= X-Google-Smtp-Source: ABdhPJxKqkvT4FNfOQDXxldeMKjIXAangCvfHQZRmo0qYAPvYNl6l1ZKfU6Q6h9XF2BArDUo+C3jjw== X-Received: by 2002:a1c:5a41:: with SMTP id o62mr5004169wmb.16.1598046115150; Fri, 21 Aug 2020 14:41:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n24sm7479581wmi.36.2020.08.21.14.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 14:41:54 -0700 (PDT) Message-Id: <503a1874ce48192eba27d7fe3d61ffb6d44e4ee0.1598046110.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Fri, 21 Aug 2020 21:41:46 +0000 Subject: [PATCH v4 4/8] 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 4f4591cad0..066975b306 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 Fri Aug 21 21:41:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11730603 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 8BC58138C for ; Fri, 21 Aug 2020 21:42:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7130C207DE for ; Fri, 21 Aug 2020 21:42:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZrTlqILO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726828AbgHUVmI (ORCPT ); Fri, 21 Aug 2020 17:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgHUVl7 (ORCPT ); Fri, 21 Aug 2020 17:41:59 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69571C061573 for ; Fri, 21 Aug 2020 14:41:58 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id f18so2017517wmc.0 for ; Fri, 21 Aug 2020 14:41:58 -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=Zjk95pttvzZ8tvFZWB6qQy/t3H6QfpLlWhU32dZ+QXA=; b=ZrTlqILORdlUub03X4jmbsl8smER0RVG86fckkR+M0Ci7/zKRLPFBmVgKk39fcnJF0 D+bCPcwPRwlv0aubYE4oj5PTRR/tJYfCxb5Ye3byM4H5xkKm/6Wwf2sblkt25wCBiIBP oimbordRBS94ACgCOOnCgLyhIJ+fzshcXjwNtbWD1v+65MBMzxfe4C+1/acJU6b9ryh4 QO6WNY6Sb1DUwAQ7gRFAHk+VW+RTaDyEGm9w77eJjTiOfG8DNtfl9pH0TKQJdklgOHui Z3DHiBky4bnrrVTwO/pJgKy7P7YWQd2VvEd5mk37kHCimNgaLo0v9/BFYpCK5jMYpBLL gAhg== 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=Zjk95pttvzZ8tvFZWB6qQy/t3H6QfpLlWhU32dZ+QXA=; b=cBiageCNZsvs9sB0LkZBrae+XF9oFflJwhKR2WSfWmMN/rn7llKLj9SISFJnAc2Li4 hAE0UliCdlwXIYbNK4UJO2OZS6VUe0qnYXjjZFQCWwg109gGh5ZOqXUiM0Y7Sf9v68Hg LaIK5OrZMU5NBufQpYcLZxclTSQH3QCFH8hXUfIosZWKrnG4oJ6j6WJPV5GGPGZhgIlP 6MhLuq6KCJUNFyu6l37muZTmHuF9Vtm4FgvMyXVz0AGEPwizq2VVZny3bszK5HXI5GMW 8HzgA+9E+1iheH/XBgnU+uyA4T8ONMNZu/tWxSJTzC5rArKISImRYb9B1TLgDvhC/l5g eJEA== X-Gm-Message-State: AOAM5333VP+/qoizR8sDXV3yxUjj9khszLMIVVHkSl5OzEa9APXnMjYG XusrT2TJJpOGVZtk/Re29IzuqFLrniQ= X-Google-Smtp-Source: ABdhPJy9Z28AvnzbeexnR+Ge//jVhoVP6NTRziNXnS7mKnOhjNuV5APzcc6qJFcg4YMa8XMeFLPTOg== X-Received: by 2002:a7b:ca48:: with SMTP id m8mr3939389wml.36.1598046116046; Fri, 21 Aug 2020 14:41:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 31sm7191645wrp.87.2020.08.21.14.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 14:41:55 -0700 (PDT) Message-Id: <6b971667960549fb5fbd293e1880ec34169e5aea.1598046110.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Fri, 21 Aug 2020 21:41:47 +0000 Subject: [PATCH v4 5/8] 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 066975b306..3449fe45d8 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 Fri Aug 21 21:41:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11730605 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 90235138C for ; Fri, 21 Aug 2020 21:42:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 783BD207DA for ; Fri, 21 Aug 2020 21:42:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fjh9n4lA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726830AbgHUVmJ (ORCPT ); Fri, 21 Aug 2020 17:42:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726804AbgHUVl7 (ORCPT ); Fri, 21 Aug 2020 17:41:59 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EA5FC061574 for ; Fri, 21 Aug 2020 14:41:58 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id a15so3180342wrh.10 for ; Fri, 21 Aug 2020 14:41:58 -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=o5X9jZM8RxMRVE7BT4xW91an31/9I25DwJ1adalSf1Y=; b=fjh9n4lAX5DOAI9DyOx4k5WHBPfRy1ASY5ccuZS5MvR1GjMi6N6Vhqr4zZmUFu7e40 dbO+tL3jqGlAloLaJMUcwNW8W+cY3giz8pPkdmTdqTncQKJHQmMaxkFkGNjt1iAQ9Pvd fo728DGO9ip7lxKvlg30j7vKuSPfyP5LvgULkXQtTSjwJV+QMYxTC7SFIqKBUGLFwx74 1Cogpsu37fPgjGfKUMbSHs9U5yOXf5rZAFpqPsq6HOZB/IH23cIRjctZKfb8gsI2DjWc 89JZOMeJNbpvzEKSYcww2yuEU24O3rcUfR4lf69yPrV39SbTS/gsewSLYHxwClG0Rg7p JeQw== 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=o5X9jZM8RxMRVE7BT4xW91an31/9I25DwJ1adalSf1Y=; b=EmQiiYgIcBnZXf4w19pgegGA2chy+sc+hMg7iO1UPAdoUJxP4dYNUb+P9+Wf58PyBj 9qYC5CB/USBW/jGW4giaHqCj42/55Lgb70/MkWgh89hKJbHTySymSwfQjajaWIc9nhbb e1/5x0fjqCJS2Dpp7Soaqy9AzShK5MFpow6CmBMtFlnRO47YsPLYiWdcUn2jPQ/Np4yf 6WRH2vCnZ0bYzSFqKPd0lrzDA3avGXttUChsy2Ja0T5ZSpSu7ANHVFr4Hy5A9iPGpC53 e2IHkWixKQpbdWNU6ZJxQRyKB9RE4LN2clVd6B5sr2K0QA9cH4f5CYow0ZjlY2EXH5Mw fQug== X-Gm-Message-State: AOAM533BcBETSiI46KrMiPxVMbZ6We7cN5+sJ+yBIejxtM08WZtQO5KJ auqW70pB/NZ2efJeV/BRNKD33RFoYg0= X-Google-Smtp-Source: ABdhPJxG8aIee4tOlMF5ATrvIDsvRUKp5OTlw4sNd0gKoGY03aPsXz11KPGJgemf6pfwcH1tWRoylw== X-Received: by 2002:a5d:5704:: with SMTP id a4mr4278487wrv.318.1598046116946; Fri, 21 Aug 2020 14:41:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 31sm6446461wrj.94.2020.08.21.14.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 14:41:56 -0700 (PDT) Message-Id: <5ed5ac259d59b855fc5c956bc8af80fecfc7c971.1598046110.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Fri, 21 Aug 2020 21:41:48 +0000 Subject: [PATCH v4 6/8] 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 3449fe45d8..c7d81088e4 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 Fri Aug 21 21:41:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11730611 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 E441B1392 for ; Fri, 21 Aug 2020 21:42:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB898207DA for ; Fri, 21 Aug 2020 21:42:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ByIXptHY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726838AbgHUVmO (ORCPT ); Fri, 21 Aug 2020 17:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726433AbgHUVmA (ORCPT ); Fri, 21 Aug 2020 17:42:00 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91957C061575 for ; Fri, 21 Aug 2020 14:41:59 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id f18so2017558wmc.0 for ; Fri, 21 Aug 2020 14:41:59 -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=y9gz+4QhZ13A2LGFwbS6ZAj9K7bkVoWByLN4SMbwILc=; b=ByIXptHYHTLStkAnfu5e+wGfyqZ3a0t/rnCJe1h1/fsvXqpqzStSRJsUYbsMSqFlpL YhOH2QpYAD0ZJxP/Em+MN4pgcTUXqC8NURkl0rQZZaK7pUpZZqqOfJNIPDrtXRsu/xDw G9QDqhGKEliBgMT5ZUnI9rU4sQV5upixbgoaaz4gCm0bIoeT5F9AbtqITOqmALgjFvXg bSbNTn4yacevR+HFIK/7eM6h4t901RDmJzF5rqfq5ldjWA5jcc8T1GoOU0zcIifIlXnp uXY59hbIjJs7xmfVXBUa3CJ4UfObeo/7KuBcRfpicBTxuwQPALa3ZHBWe0KzAKPKAtDk 4+4A== 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=y9gz+4QhZ13A2LGFwbS6ZAj9K7bkVoWByLN4SMbwILc=; b=PBw0uJnNQMYq4Z96xMHDvPh+5CCLWsrkoRXxwncmdZXVsBPX4n35EZbUDM36eiPyak dMnHzHOSoCZZxvZL44qA3JRxBBz1PtLrwhKdQHIJLckEdB7hVtxTjjHgytFx9ES2uhec l3U6UNkNtXbr+5JX2fe2aaqo5k3Y3SYKvpjEqSv9Yqfo0b3rk/jGXDYljmefxKasoANX nG6a1DS8rjSf7tOSEFrP+MRZeac/aXVsPwUuCVutfLiqOvyzfmy+AmVqYloi0fFVuIWu vpw/6ZkE7/+YcHMf5xeMqCRkirxwoPRQ3Sk43wPSiYqKZoxsJlqqybH9SzrYNMIxMk0/ z0uA== X-Gm-Message-State: AOAM531v7vwuLlaT+cz/fnjGoLS9xFVNVB1QVEcVAhLBTX4MvUjoW4A0 KNuMZmYYGjVRcMQvLkKXtOyxLyUekHs= X-Google-Smtp-Source: ABdhPJwWQ6vJnW4/1RhOcn/r6Yenss1EOmW/IqIjLEI2RmuldKfUL9ZegYtkNCkEMFXAGrZIY40zDA== X-Received: by 2002:a7b:cb4d:: with SMTP id v13mr5935859wmj.56.1598046118097; Fri, 21 Aug 2020 14:41:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f9sm6594260wrm.62.2020.08.21.14.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 14:41:57 -0700 (PDT) Message-Id: <6105046d96223bda40ab0f0177e4f0281376ba53.1598046110.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Fri, 21 Aug 2020 21:41:49 +0000 Subject: [PATCH v4 7/8] 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`. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma --- pretty.c | 20 +++++++++++--------- pretty.h | 3 +++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pretty.c b/pretty.c index 2a3d46bf42..7a7708a0ea 100644 --- a/pretty.c +++ b/pretty.c @@ -839,21 +839,22 @@ static int istitlechar(char c) (c >= '0' && c <= '9') || c == '.' || c == '_'; } -static void format_sanitized_subject(struct strbuf *sb, const char *msg) +void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t 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 (istitlechar(msg[i])) { if (space == 1) strbuf_addch(sb, '-'); space = 0; - strbuf_addch(sb, *msg); - if (*msg == '.') - while (*(msg+1) == '.') - msg++; + strbuf_addch(sb, msg[i]); + if (msg[i] == '.') + while (msg[i+1] == '.') + i++; } else space |= 1; } @@ -1155,7 +1156,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 +1406,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); diff --git a/pretty.h b/pretty.h index 071f2fb8e4..7ce6c0b437 100644 --- a/pretty.h +++ b/pretty.h @@ -139,4 +139,7 @@ const char *format_subject(struct strbuf *sb, const char *msg, /* Check if "cmit_fmt" will produce an empty output. */ int commit_format_is_empty(enum cmit_fmt); +/* Make subject of commit message suitable for filename */ +void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len); + #endif /* PRETTY_H */ From patchwork Fri Aug 21 21:41:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11730607 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 A63C11392 for ; Fri, 21 Aug 2020 21:42:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A5CF207DE for ; Fri, 21 Aug 2020 21:42:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g+KA1IuM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726832AbgHUVmL (ORCPT ); Fri, 21 Aug 2020 17:42:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbgHUVmB (ORCPT ); Fri, 21 Aug 2020 17:42:01 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78646C061755 for ; Fri, 21 Aug 2020 14:42:00 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id b17so2419099wru.2 for ; Fri, 21 Aug 2020 14:42:00 -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=QR1w2Zp6gFF71LmnCss6TN/IzKoFjdS10xuG1zbnlSE=; b=g+KA1IuMpOqc+zGoJPb52Re91IMAPmmfVRDd2AUGsZtwXvB5ISblEw+BfJFMyEUynT EBxihQi1S5u/PfgM0X1epoWv+OLG5BDcQ2I6XLlJKtIPXxVq0M+n4pxwofhuYDoP0oZL frimwGu9MijQ5w6ocqYLiMU4ZTDl5WkASuUFonT2LLm9CJBBJLjEMeyhJ4pwxInOHHHW HZn3hsCyllXgiSgKPnssb29uKQtB1ntYLUM5S6UigB2kQzqo3mCOIS83Syi4fFxn1gZt YXz4pnSX7iXfaG0FlQEhVakzKFGFndRPhYMm0v4XNpDem75PUl7wwzslKkW8owDEVNQP dHJQ== 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=QR1w2Zp6gFF71LmnCss6TN/IzKoFjdS10xuG1zbnlSE=; b=bBdsGr6VXQKSk4W0ffR8z0v4Pf34ZMWNjv9yy5IPqTyYMHYrYD8kkWTCK0/xLv3SwW koQbU+0pwEJ1WJagXutApdvVfJ9cga8MXm7Tv4TytclIRlnifVIPpdH5bbyffB4qRWCC 52EUJvrXmPd1jZwwR0Pm3nfXR+ML5kZyw7mCHSzpOkMUBCGBqZNKlSklllbcZgJcZXCx 5DYaDx/Ls5r3MoAdtnEeHY3v0v2YUNikmaAMCr1GoqwQOojmtnuwUQEGVyfn4jJC+pkm CYtJ7Q8V/8Wt2fVURbxdqBYZq539DBLFIMEQwZ358gXSJ5Acp026uXUpEogggQm6dwZl fxgQ== X-Gm-Message-State: AOAM5304cx6/swsq2HAFhcyJYbt6vvLR6+77VwfS7vYrXC670YiEjr8g i2zlkiSvRo8SDf8qGRlEL75BOK9JHs0= X-Google-Smtp-Source: ABdhPJxLMOK8oZKw1SlWYROurYTrmkTEqbpG7S+KzEGWufjObwbiXOctSLl6FxMrNpAhKKAPsq1LkA== X-Received: by 2002:adf:9463:: with SMTP id 90mr4252534wrq.223.1598046118936; Fri, 21 Aug 2020 14:41:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b129sm7590880wmb.29.2020.08.21.14.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 14:41:58 -0700 (PDT) Message-Id: <7cba8d7a2881055e89976ca420392da2eaa596b8.1598046110.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Fri, 21 Aug 2020 21:41:50 +0000 Subject: [PATCH v4 8/8] 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 | 23 +++++++++++++++-------- t/t6300-for-each-ref.sh | 7 +++++++ 3 files changed, 25 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 c7d81088e4..12bb78ce06 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -127,8 +127,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 +301,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 +1285,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 +1298,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"