From patchwork Mon Aug 17 18:10:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11719033 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 827BA13B1 for ; Mon, 17 Aug 2020 18:10:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61FD720758 for ; Mon, 17 Aug 2020 18:10:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QUQlrIB6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388419AbgHQSKw (ORCPT ); Mon, 17 Aug 2020 14:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731100AbgHQSK2 (ORCPT ); Mon, 17 Aug 2020 14:10:28 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 537E9C061345 for ; Mon, 17 Aug 2020 11:10:28 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id x5so14015605wmi.2 for ; Mon, 17 Aug 2020 11:10:28 -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=QUQlrIB632OIigQZv71/FJpZYKT+pyRbgXdP0ZQn50IuDwEZ+oqYRP+CjA0CEOkpi/ oxgbVh28T/bZeuagM9mH74eDwOzfi55Xghj9lMfauWWkaKMuB52yDjFldyMNUbjsUonM VL5XkYPCRR8oKwTPdheyiK+UnhU3l+akYhLctSoJm5Xg6FIdveLW1Ol3VJOf+TzYGcVN I1rPk881sT+dPe1S7byaImNZFhnfVUn/m925qIqiI/eoqyFbFcxCY1MANO5D3rlSpfwF 0HdxdNSXOnshFS40cismI4c1s8ORVscww4wG3DNRr8/fQhehLPkviYdXDGwPRcqRSnfX LnBQ== 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=aU/qpSXhzfIZ5xh/rJ/yN6shy0vR2HE+IJ1XHiK8dQ4/DWD6Gtea+bYh3kGdazYaiI IcWinheD7yW9FaLji2Qu64DTKMJ2/vHj4d3llMca0N7LVtUInKPvEFm6J72oBMjDY9Ei q1pVTIHM/XloxpMFpxn783rQd8CI5aTLQxXvLFUQa1emxWpVWmqxnMsCdgRKmV8cqj/w ogzyfOASm49TFaEMneVMr8gE2Z/3bRO8NCEPdGY0H4GpYUrC5Q3ao0rIU44uqufRxruP K8nfttCqcexQpYyTq3yHzknaBKTRFGJ++V0GO2cVI30IZO02h9na+VkQKW7YkjdCBl06 bFtA== X-Gm-Message-State: AOAM530Z3oW6kkvRmn7PNBtOed+WefKnjOStBC3wPzoLTR8LCZM7HTW6 4muMMLhezPG5V5a2RT6u9DdvLhGQga0= X-Google-Smtp-Source: ABdhPJzKh0sqbh96pXIrJvU0D2OgOBh2ohxcwclusIa0RHNT4nxImWWqMsn33XJGnuIvTuLa0nmWpA== X-Received: by 2002:a1c:ed16:: with SMTP id l22mr14626798wmh.80.1597687824143; Mon, 17 Aug 2020 11:10:24 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 8sm33272029wrl.7.2020.08.17.11.10.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 11:10:23 -0700 (PDT) Message-Id: <3e6fc66a4668a8abe1eefbbce352ccd30abc096b.1597687822.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Mon, 17 Aug 2020 18:10:14 +0000 Subject: [PATCH v3 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 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 Mon Aug 17 18:10:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11719027 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 41D4F15E6 for ; Mon, 17 Aug 2020 18:10:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2755820658 for ; Mon, 17 Aug 2020 18:10:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XN0vTcb+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388474AbgHQSKh (ORCPT ); Mon, 17 Aug 2020 14:10:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729128AbgHQSK1 (ORCPT ); Mon, 17 Aug 2020 14:10:27 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80EA9C061342 for ; Mon, 17 Aug 2020 11:10:26 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id l2so15874558wrc.7 for ; Mon, 17 Aug 2020 11:10:26 -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=XN0vTcb+UH/C5LwD8FRut0VGr+hseFWANaG1I8dZn//R4VU52XBQerwCxTDze6pKKC R2M+1m9uK/Jne6v9rVh8vSO3PqWTkevFzk5/iDOllRwMBLdihkBu+3yCMvbRYdAxx+ZG R1ECwjeBWR6RwkCYfohf3iCdJjpjMdM2Z0hlWmWmS95aJkPW0qzc6hByqXJ/20T/OLjP Uww0/NwcIyOtYmSPRpS5zWf4f3AHmNmropFZ3hbn7S7pnsg4ktlIUDSgfEn/xy/d7bCg mmPJSODUJ5hnhYUMiNyIKROoAe9I2rjvYU24uBcfgYBflmNvWDG3ZAezS8CpW+eNOXrG IryQ== 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=QNwKa6mYZmmh2oRkav6qEp5ruYz02lff8SMtVNu79k/bs/SM4pR8kGRboLkb6pcyRb jlg0OFHJq24QiDTuWixS2bx0Hp/g8a1lHD2TI3/X0ZnYdEwAQginuaXloS9KMsrffNeu GdI5qANvnOWAoiEmLj381ytrm0UGkncJeKUq4CQmGiTMDS3bJxf/FClbm6D3BVxM1f4K t13Qt7aq5pJbkaJrfEFCUpgEWJDIwXT/5YpJe0j6ltDANxd9TUfLiQQn/a5v3+zj1w+X Lc532GXHFALwoUyhhuVs4MP+3oT3KX9j7sdiUkGvjAKN2UhxqO5Yz5VDj6BAoBr0YTdp fsjQ== X-Gm-Message-State: AOAM532AmwaSxVUIogAXIVqwJR41ZYS7y+r+f5+72kZklldt6pqnIg80 cajlLN8aaootWBYa6ofespoRnV4UsJ8= X-Google-Smtp-Source: ABdhPJyd8WTGaULx3bZB5HCZ29wqHkXEMRJJdJTRoOiFTUfRMtRksHgmIvmOhDPMZ/W1Xm8JY/2TSw== X-Received: by 2002:a5d:4d87:: with SMTP id b7mr17629004wru.170.1597687825097; Mon, 17 Aug 2020 11:10:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b123sm30904055wme.20.2020.08.17.11.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 11:10:24 -0700 (PDT) Message-Id: <5268b973dace3f453821a7800b5ec0dd0dfbe848.1597687822.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Mon, 17 Aug 2020 18:10:15 +0000 Subject: [PATCH v3 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 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 Mon Aug 17 18:10:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11719031 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 D34DA13B1 for ; Mon, 17 Aug 2020 18:10:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9CDB20674 for ; Mon, 17 Aug 2020 18:10:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u+QQqLmH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390306AbgHQSKr (ORCPT ); Mon, 17 Aug 2020 14:10:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730237AbgHQSK1 (ORCPT ); Mon, 17 Aug 2020 14:10:27 -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 8BABFC061343 for ; Mon, 17 Aug 2020 11:10:27 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id l2so15874582wrc.7 for ; Mon, 17 Aug 2020 11:10:27 -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=u+QQqLmH3RN7FwY9yo58VSJAsn6uDYl5cSk1Ys3safkj3wmjKSPGX14vLsYlhZ0xFr Wu8OnzmqitGaHm0FuYF163dpwgAWHoezR7aAnCu7IPBZvQWbrlYtKgcJv2SPcDmRIRIu VRktodXbNa0cCvGsT+JWzcHfPOxG0aPuXKmJA1jftpqVIwXFJgxp65bPmz5q3DeE2cV9 xhSsa8Fbpa2+CooTPzYQSQLgPZpDHvISN9Xi2PGeXR84fwygHijkXpNAckiBk+Sx8nPa lYhXwxF1lzjS6CC9NsuMHjuZqdYjGc6GXeFTluWlgaC54ymTaeXseHn7jb2uP5uPoV0c O0ag== 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=evE2NYOduGvG+YssqqnwT4mMWe5vxWS/ZqSHyB8kzsliebLOKHQ97FRm6s556muBhG K95tSWktgVF+9AWmNrK6kaUgFtuR9XypaIpz9CL+tgahHjSRTMRXTK5dod0v/h3JvG2z dx237a6KsFYw/bs8T5ts+YWSWiV0tR/Cr3HBmba3WWOLnqbVrrKUdUj6WMM9fBx2NuOQ amrgTccoGSrP5tg+c8Eeu8ULlL/Qbi/3bPtW2Iur32bdq1rNg+3OZu4Fc95zgW9JxsLQ 4+lOi6kJF2Gxddmzrw55vo89XIge+MgEKFYRh41xYd4IFbl+9vcdb181zygTsE4hwzVU P0HA== X-Gm-Message-State: AOAM532OZ5FKC7SkrqoCrBOPiucYdgq/GJkZh34+8dL7ebQD8dKyWjd0 o96YIXyNgHYqUT2/Ce4Wt4SyAjGf3GE= X-Google-Smtp-Source: ABdhPJx1C9SV+ej5cIMwVhR91Gd24TRaKL1odebEesi6P5+7iOzgdsKPU8Q08ATgtZoz9k/B8pATmw== X-Received: by 2002:adf:ab0d:: with SMTP id q13mr15675925wrc.134.1597687825930; Mon, 17 Aug 2020 11:10:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j145sm33502795wmj.12.2020.08.17.11.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 11:10:25 -0700 (PDT) Message-Id: <4a12ff821020ceab5195e406461e00cecbb8e1fb.1597687822.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Mon, 17 Aug 2020 18:10:16 +0000 Subject: [PATCH v3 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 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 Mon Aug 17 18:10:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11719035 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 8778313A4 for ; Mon, 17 Aug 2020 18:11:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67BC420758 for ; Mon, 17 Aug 2020 18:11:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y8lj2lkz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390418AbgHQSKv (ORCPT ); Mon, 17 Aug 2020 14:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730586AbgHQSK2 (ORCPT ); Mon, 17 Aug 2020 14:10:28 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34A75C061344 for ; Mon, 17 Aug 2020 11:10:28 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id d190so14008577wmd.4 for ; Mon, 17 Aug 2020 11:10:28 -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=Y8lj2lkz1FYCOdc49pHdYJMAbFWNct1xNUUX8Kq6P35Ag1rw3MflLjK0WCJrYKn1nw CVp7HTCkt5pkGvvL0hS1pTGSXzpOVcNlzf/MDpAGYnUrN32jAgDg7mq+bPBfys8+P7XW JT7KZaiqgdJCrxPfoyPYg4FzQ2S38QgTicmUBa9Ef4Hqkc7aUQSDCTMTo6/ozzeIVqHj GCtJ4egf1GLXoEPHaI1oBD0AFMoHzQw4H5NMJE2u2JAsuE7pRYPPR3DXNPoNljkHY9Cq z+l+OVZglYMNQv8iGDcahow2iqPHocWHAkcyBwIge7Zc31OFT94K2I51m8EPnFvL7+Ao 06dg== 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=hYI+oQBGaNqIE9H+drEKbO0Ek3o6MYY+vI4X6xXJWZepEVsEBa+q1kLeG0s1XM8xOV oRV+VU34TRSYW6pHnL8cG3hw81VrNyxNRv4UEYUZeTkVbG8xn9zayg3T1nLcDYBAZD0d V1UeXceqYpSGeLB3ylOIMYJVbDQqCpwWAe5xeohTIf2C0dyzhtyhcpDtvYpwGZKE4FZb p3QDXnEVjMs9DKALdvEwQMk0vkgoOa/nBXvABU8ZQEv35BAEH1hBj9/BYO1hl0one0lT 03jFrEW8LvBGMiLD7sfYlmohZVR2zA+eBaGe5/Ffe7SiEcoUM/IFKxKQbMan/on/GoCD wDrA== X-Gm-Message-State: AOAM532qY3d+G0qMXH53P4gCzSOcTRvhiiu4HorLEVZ6LPlmZZNqGMCc R9aThNhPlcJxyII+fhE+MlMMvU26peA= X-Google-Smtp-Source: ABdhPJxpEKlzA8nFZCeXnejGfw1CKAu8c6/d0HAN5NRh0OadHWx1eWeoG5ZWcfjgnkSRJgIvqEy+QA== X-Received: by 2002:a7b:c2aa:: with SMTP id c10mr15403514wmk.86.1597687826797; Mon, 17 Aug 2020 11:10:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i4sm32144599wrw.26.2020.08.17.11.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 11:10:26 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Mon, 17 Aug 2020 18:10:17 +0000 Subject: [PATCH v3 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 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 Mon Aug 17 18:10:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11719041 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 65DD413A4 for ; Mon, 17 Aug 2020 18:11:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 490E32072E for ; Mon, 17 Aug 2020 18:11:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UMYVgo4D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390462AbgHQSLh (ORCPT ); Mon, 17 Aug 2020 14:11:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731120AbgHQSKd (ORCPT ); Mon, 17 Aug 2020 14:10:33 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2097BC061346 for ; Mon, 17 Aug 2020 11:10:31 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id k8so14682277wma.2 for ; Mon, 17 Aug 2020 11:10:31 -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=UMYVgo4D3eTkcVsjyIVJDAFgj1JaeLe58IvW5WXUlFkqAVtb9zM2q2QIk3ZDyLAOxv ETDvof470U0pevyEA4eC/wXgL7tJlTHqh6xI0x+SwMPxbCr6Z/AivUh4rK6WYxjkINMt j52ySlRsR79hI5HZSk648K/670bCwt4VSMvoH87jzazXQBaGKZNsOZC7wri68PV6aKR2 Zm/2B+Sre9wDPoE8uq81GqJ0Bqy8BvBzT1NsdiPNqpdv0GjNRWGcdE6+Yfv4IzTpsBbp gzLaDsVlj3Ow0OrL4Yp6VSrTBP27+6UFODfsUzN2Qv3UxDeLgMgUVFlW+uVLwU6TQ23h a+fg== 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=IidC0EDgNG5yYtjfnNHs2yotN/s9pzlRtmwWM7uk6ZqnR9fG5baz9dWoHrld7GpkyW spqKX+PKNCjrwzOvVTk3Mv3IwYcHsFyZVwXzvR0/6oL06Y+ddtRXmtbn3z8MMzZ4aCuA nxdM81OuGlwgVSTP8N9egX0Ypx7fuSwRHTAx769egSOXqlrrs/qhGGAheFUcLjRZMXZK 729PzcBepQR+PASaIKQil13xkuR8d+KQ1EWzpbk/ot0N7+jOvrYA+fh7DVmGa6u4MIP9 +F53/z9GpBfDn1rcTtEVgRc6k87hQwIvYc7BipCDg7CSnoR78RJjJ48lkOTRGYuDJW7q pZ+g== X-Gm-Message-State: AOAM5307uKiXiT39EAhTYGuTy2qafPvMsSy+s+vRJNH5Q8PLdgzGtPY+ hKQgzdr+wwD4/C2iiDjgA3yWZoIo788= X-Google-Smtp-Source: ABdhPJyX+TJaatnywdvsV3+ji1H4QCzDQz92G54C5uZrR5UJPCHUee/if/ZeFo2Jud4W47gyQMWH9A== X-Received: by 2002:a7b:c4ce:: with SMTP id g14mr16407003wmk.51.1597687827518; Mon, 17 Aug 2020 11:10:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g18sm32768339wru.27.2020.08.17.11.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 11:10:27 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Mon, 17 Aug 2020 18:10:18 +0000 Subject: [PATCH v3 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 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 Mon Aug 17 18:10:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11719039 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 B9DFD13B1 for ; Mon, 17 Aug 2020 18:11:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DA8720758 for ; Mon, 17 Aug 2020 18:11:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZO4847i6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390454AbgHQSL0 (ORCPT ); Mon, 17 Aug 2020 14:11:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731298AbgHQSKd (ORCPT ); Mon, 17 Aug 2020 14:10:33 -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 16686C061347 for ; Mon, 17 Aug 2020 11:10:29 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id p20so15907035wrf.0 for ; Mon, 17 Aug 2020 11:10:29 -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=ZO4847i6mYeS+wgW/i37z4hqYy+YR0JK7R4cj5+ojqo/UZ6btiJP3/X0yWF8pG3qZL qEJxXjxpl0raVvLvUO63GXwuJIPsv9T35qXwWajH8eyMK7HCJe5J7GwuoqYGMjlcYUlP haiKil03Dr+7Qzw/yvU6p43cwAK4KKRGy1IKUlUFuIBCrWFVhDvzLFtHtYlb0XRwg58N dpg64517+PaBMIkVtRi8xBug7ZxhmDVxXOAc67kSy0f/AXMpVpjG6Sk3T4QwSzM4ffQs qX1EBiz4slSiQ/JBFA8V/8X//SHakdO581WPkfN8VMdSmozKFWHwadMMbxcgBI3wsk5p A16g== 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=l6K9eXa/IfwvScESaZNrlUiBk3QaYS4wMHU7+TQofMDvLz7dp7szoBDR1f3hmZza8C QBYlOGgwO8ccurRlMo61GXeYVIaGL3DejnxMAEnBAM7hPGRMdTzsH8OC9ViD6x258bSA DpKymEga9exf+GGL0GURi1hhZasZZtnjTeuUiwNhlAkQMtdCllFvV0IJyJWIxlxGIur3 ROd+YoTfeq5vlKeBA52OuZOytQazRISA9B2LfJSqvRmpFi12IBk/wIhgB3dK0WfmRXX7 t75NJDnWNhu27iKFiV3TVYKJp03Cfl61f8Qfc759bi0OH4NzE8X05BJXo41cWWYlz0AW PSgQ== X-Gm-Message-State: AOAM533YKcAtupr3qsHvmuqIgdADffnWXaWknu0tKPZEkltNuxl8AJVE Qnnqs7kV69VBLjkwzX9K+99VxM8RpZw= X-Google-Smtp-Source: ABdhPJwncicx6jJTFcpTnmeHn4HVlrMyH0q1a33jZ13yGp1rF/Uq2LbavTlN/WqFLNkJm1iKSVRE7A== X-Received: by 2002:adf:f7c3:: with SMTP id a3mr16146801wrq.162.1597687828474; Mon, 17 Aug 2020 11:10:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f63sm29928509wmf.9.2020.08.17.11.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 11:10:27 -0700 (PDT) Message-Id: <7a039823de5a684e958241773b6a27c08199fc7c.1597687822.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Mon, 17 Aug 2020 18:10:19 +0000 Subject: [PATCH v3 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 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 Mon Aug 17 18:10:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11719037 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 35C2913A4 for ; Mon, 17 Aug 2020 18:11:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D37C20758 for ; Mon, 17 Aug 2020 18:11:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z7FYQZ7R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390451AbgHQSLQ (ORCPT ); Mon, 17 Aug 2020 14:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731517AbgHQSKe (ORCPT ); Mon, 17 Aug 2020 14:10:34 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D240EC061349 for ; Mon, 17 Aug 2020 11:10:31 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id r2so15892381wrs.8 for ; Mon, 17 Aug 2020 11:10:31 -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=Z7FYQZ7RssfZLL6f2hKq2ok57KjQ/OES/rrwU0juRSfCXx3c6Pg0Dhtx7zvIRsILA2 3GbvDksCDUh8oYeBezJVO00orZb4zRBDIC2Qt6ldLNAF+YAqZkSEnbXGVbR4fTP7yx9Z ciaI/LtMF8s9IcOSS8M2eGbn1FpI1m2D0aPWNVmIAHGfZtJQ9rdv05LsJmxCTFut4bKx 33AH0+pvDCY3ADUUkyFZRGiazgOk04e2UO1ostS7bnonRKqsbxCEWjyX9iR1ydYXkL4u CTv90HztMMIH6/qqLd+Kb5DG5XKmU59OzgmYJituAnZiMEAMn4d6xCKvkJoaPX/jXhuy 33Yg== 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=qnK8ZkInZtV1HwO0WbQQjPwabXYUYOhFCexZtW1stugqPI7u6jPCDhrKKXBdtLAdrM 09qoMuE6RVl4nJKaN2qnTcfxsrqPE3DQmPs7HCZTmDfHd7fAiJpC+vzpGgHKlhsQdO6R +DSUYR6TeXpFs6WhduXWXN+8ynzw3+NZuWhmMkzAb7CiFB7yzvFfE556EdiIb3nZHzJH Z1P7G5lBatCpK/5t14/0pxXnFg0YKp3TMx9HlIbtPNmISIfv9XICOlCb7q7EVE9rYJMR UHj+xOMGL/4TfBfnXPSFjSuXojXsJ8VQ028ivjmitG6JHiZ7HR6o0e9oAZo21Ryjy9ck uPEg== X-Gm-Message-State: AOAM531NlhWtb/W7f71yx+t3bwNSfRtONm1ve5boTpNuX/IiZtVed+Jd TlmicEdoEwKB7sRavIveEQXcTs9Pcyo= X-Google-Smtp-Source: ABdhPJzG1/L6K479uuVjmdRdav74YOGs4Mme9vrQm7Uw3bjovVmM9suF+fofc1Y+ntX/mHEAERZt3A== X-Received: by 2002:adf:ef4c:: with SMTP id c12mr15523644wrp.44.1597687829295; Mon, 17 Aug 2020 11:10:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r16sm35575778wrr.13.2020.08.17.11.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 11:10:28 -0700 (PDT) Message-Id: <0ad22c7cdd3c692aa5b46444e64a3b76f1e87b4c.1597687822.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Mon, 17 Aug 2020 18:10:20 +0000 Subject: [PATCH v3 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 Mon Aug 17 18:10:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11719043 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 0AC7613A4 for ; Mon, 17 Aug 2020 18:11:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1FB320758 for ; Mon, 17 Aug 2020 18:11:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f/V5/+yv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390457AbgHQSL2 (ORCPT ); Mon, 17 Aug 2020 14:11:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731387AbgHQSKe (ORCPT ); Mon, 17 Aug 2020 14:10:34 -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 57E12C061348 for ; Mon, 17 Aug 2020 11:10:31 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id g75so14665685wme.4 for ; Mon, 17 Aug 2020 11:10:31 -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=C8PssJ/y3mWpvKmZ2Y8WW8hmj8m1ykoCbJ0QlyT7LeM=; b=f/V5/+yvi+1ef1RW2riWBMUOzaiBzX+3DDUNoSTFI9XUagBLozmUzidVYMxF+K7h20 VYdrmVPVbfpulS8chm3DL0dmGamsLKjVJSBvslw5WJNf09WZlwgiS4aWE5LOoSACtNHL MHKlSQe5yXMcLCM1TB7EolQP21NN+1rc3pcHI9Za9Abc7o+AJzlp2ucK1hudCBSFpZkc YTllaLJop6M1Bz2p/3CsMB3o+iRMzfpumgpzuI14IZrpk5nxt9B0YMgogEzoiFIUlSsg +ZMJaDO1eZoqA93L08TvusSUTVxfDSb968prj4HGUu5eMXQph171i/WLFZlmmXLfsyI1 dSZQ== 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=C8PssJ/y3mWpvKmZ2Y8WW8hmj8m1ykoCbJ0QlyT7LeM=; b=BloPNSwCRck3cn5f/5lcqj2Iq5hpXMQHJWjY5iBH/9Y0fZbn7kdHqd3Ak1lcnPUcq6 mLblFCbhDMDrdVJxg2Vdja+4SnG5UVRYsQLQnx6SNWBklZzxr5poL8QONh4KBa8cfSBD Iv/qFBBpp0B1QKO0W/+XxfR1KrflDxX/Yo85rkswQUDMz6hSzuzIsZ4OXGZgGz9Touhi 21SoPUExPRd9S410vSr4qXGNclC7ACDDwOS8IHdQPcuxuku9HP3LbJeWe79fUXHPVU9F nazckrCOu5RQov7WUv2AFNV/twg3xGal7d7f/lxb6lzPnXyHiX6WUu2d/9ouHXKBnDv0 4WXQ== X-Gm-Message-State: AOAM530DrDB3gIULm/xRhxxtfn2UzucHWr3OdeKRlBs+LuZwIheMlmU2 rqK7dvYN1rONnyHyc/IMuST6CCOe6vk= X-Google-Smtp-Source: ABdhPJxbZaH8wd3xJn+mRHdRJc/BXhpE5gcewZHOIXtFAXYRce+w5WSQAkAoYTdrywzDecHtTh725A== X-Received: by 2002:a1c:b4c1:: with SMTP id d184mr16351289wmf.26.1597687829918; Mon, 17 Aug 2020 11:10:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y142sm32229699wmd.3.2020.08.17.11.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 11:10:29 -0700 (PDT) Message-Id: <7a64495f99ec97258687695d41d106e3f946d551.1597687822.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Mon, 17 Aug 2020 18:10:21 +0000 Subject: [PATCH v3 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 65f8cfb236..4ead4a256c 100644 --- a/Makefile +++ b/Makefile @@ -881,6 +881,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 Mon Aug 17 18:10:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai via GitGitGadget X-Patchwork-Id: 11719045 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 9005213A4 for ; Mon, 17 Aug 2020 18:11:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7578E20758 for ; Mon, 17 Aug 2020 18:11:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Krgymah4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390445AbgHQSLN (ORCPT ); Mon, 17 Aug 2020 14:11:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728683AbgHQSKk (ORCPT ); Mon, 17 Aug 2020 14:10:40 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6400C06134A for ; Mon, 17 Aug 2020 11:10:32 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id p20so15907112wrf.0 for ; Mon, 17 Aug 2020 11:10:32 -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=PZX9WtYSSXlcXC8ctc8602S/pXm4lNmZH3UVaxfQBWI=; b=Krgymah4y2q2NYPgORckDQxMW4E4mrJ5/UHtflfziMZsVT5v89oZ6+ub4s/xgsB1e4 so2TplIJupEYZh0vVtaAMwUZrtETqtXPAF++zNRyU3PrFx508w/hOSCHiWOMa4KFP+r9 M9mq65niou29OTQpcKupXbrjgKwbTANDVCpbXSzKXjHuZsYcTiQd5Ld2Wk7YcJr2kjNb Y57ZYlZkVoaJePN8KavPe3UIDeKBC5Kw6Npk+n/uzdYyhvP+96uzRacGm6AlhBgVf964 3ElFAKe13QNnu+ZvT2hYMAHGAof2ThpRLZUtBLOVqVC9tiyT4YSiKUdW+1kYoryuRKe4 sDlw== 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=PZX9WtYSSXlcXC8ctc8602S/pXm4lNmZH3UVaxfQBWI=; b=oeRCZurZWAt6jFBy8ejQHwAwECOmmUR3GCbCBdYCPPpJWK/UmF0oWX4UNTfqnaoiXQ G34jX8wnbx9Pl482NRjlohUX2PEH8KKllj6/1LT+OjEhs10YoXqOEIH5I0MmYdbiSTA3 Sv2tIdriJ9VwMsb1zDzSIwtIHN4Qbxtz3uEyrl1pRZMpKVwLFWUBqGL2RTjxiOwPI1Nf HthD6xNE4eadHSiOhFfKQ2Eim1aQaYvPWKADV6qp5cnXidf+uhJlckXP5yUU2JZnJ3vG mJwDRKkj1BYswlBEf3Im0xQJpfR7g2HEsdwU9DNjqfGHdcbhBjo72Xy4T01lA4nLkN9u RAdQ== X-Gm-Message-State: AOAM530QbJqBWBoULCy8OXTzRNygdKbciDXLdny0gOl2CJXla+5DgIZ+ j236XMema2VavHO57C+13MH9ZBGlWJw= X-Google-Smtp-Source: ABdhPJx5+T7XElzdPyqoIfLthawzM1kB5YWnuiWjNjt3Md5iXhYFpQl9RhwDoW4hX4hUPvHqnkoUcA== X-Received: by 2002:adf:f3cb:: with SMTP id g11mr16255950wrp.268.1597687830849; Mon, 17 Aug 2020 11:10:30 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j2sm31530930wrp.46.2020.08.17.11.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 11:10:30 -0700 (PDT) Message-Id: <1ab35e9251ab788d0334e1dc97be98dd3a2ecc1b.1597687822.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Hariom Verma via GitGitGadget" Date: Mon, 17 Aug 2020 18:10:22 +0000 Subject: [PATCH v3 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 c7d81088e4..7f03444767 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -23,6 +23,7 @@ #include "worktree.h" #include "hashmap.h" #include "strvec.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"