From: "Hariom Verma via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Hariom Verma <hariom18599@gmail.com>,
Hariom Verma <hariom18599@gmail.com>
Subject: [PATCH 5/5] ref-filter: add `sanitize` option for 'subject' atom
Date: Mon, 27 Jul 2020 20:43:08 +0000 [thread overview]
Message-ID: <7b9103cbadfc111755d2db61239fcac4f4d14a33.1595882588.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.684.git.1595882588.gitgitgadget@gmail.com>
From: Hariom Verma <hariom18599@gmail.com>
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.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Heba Waly <heba.waly@gmail.com>
Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
ref-filter.c | 21 +++++++++++++++++----
t/t6300-for-each-ref.sh | 7 +++++++
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index d5d5ff6a9d..5f8fc65b68 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -23,6 +23,7 @@
#include "worktree.h"
#include "hashmap.h"
#include "argv-array.h"
+#include "format-support.h"
static struct ref_msg {
const char *gone;
@@ -131,7 +132,7 @@ 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_LINES, C_SIG, C_SUB, C_TRAILERS } option;
+ enum { C_BARE, C_BODY, C_BODY_DEP, C_LINES, C_SIG, C_SUB, C_SUB_SANITIZE, C_TRAILERS } option;
struct process_trailer_options trailer_opts;
unsigned int nlines;
} contents;
@@ -301,8 +302,14 @@ 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"));
+ if (arg) {
+ if (!strcmp(arg, "sanitize")) {
+ atom->u.contents.option = C_SUB_SANITIZE;
+ return 0;
+ } else {
+ return strbuf_addf_ret(err, -1, _("unrecognized %%(subject) argument: %s"), arg);
+ }
+ }
atom->u.contents.option = C_SUB;
return 0;
}
@@ -1266,11 +1273,13 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
struct used_atom *atom = &used_atom[i];
const char *name = atom->name;
struct atom_value *v = &val[i];
+
if (!!deref != (*name == '*'))
continue;
if (deref)
name++;
if (strcmp(name, "subject") &&
+ strcmp(name, "subject:sanitize") &&
strcmp(name, "body") &&
!starts_with(name, "trailers") &&
!starts_with(name, "contents"))
@@ -1283,7 +1292,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_BODY)
v->s = xmemdupz(bodypos, nonsiglen);
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 533827d297..e2dd410356 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -127,6 +127,7 @@ test_atom head taggerdate ''
test_atom head creator 'C O Mitter <committer@example.com> 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 ''
@@ -180,6 +181,7 @@ test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
test_atom tag creator 'C O Mitter <committer@example.com> 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 ''
@@ -592,6 +594,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
'
@@ -612,6 +615,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
@@ -644,6 +648,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 ''
@@ -651,6 +656,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 ''
@@ -659,6 +665,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"
--
gitgitgadget
next prev parent reply other threads:[~2020-07-27 20:43 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-27 20:43 [PATCH 0/5] [GSoC] Improvements to ref-filter Hariom Verma via GitGitGadget
2020-07-27 20:43 ` [PATCH 1/5] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-07-27 22:51 ` Junio C Hamano
2020-07-28 20:31 ` Hariom verma
2020-07-28 20:43 ` Junio C Hamano
2020-07-28 13:58 ` Đoàn Trần Công Danh
2020-07-28 16:45 ` Junio C Hamano
2020-07-27 20:43 ` [PATCH 2/5] ref-filter: add `short` option for 'tree' and 'parent' Hariom Verma via GitGitGadget
2020-07-27 23:21 ` Junio C Hamano
2020-07-27 20:43 ` [PATCH 3/5] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-07-27 20:43 ` [PATCH 4/5] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-07-27 20:43 ` Hariom Verma via GitGitGadget [this message]
2020-08-05 21:51 ` [PATCH v2 0/9] [GSoC] Improvements to ref-filter Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 1/9] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 2/9] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 3/9] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 4/9] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 5/9] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 6/9] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 7/9] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 8/9] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 9/9] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-05 22:04 ` [PATCH v2 0/9] [GSoC] Improvements to ref-filter Junio C Hamano
2020-08-06 13:47 ` Hariom verma
2020-08-17 18:10 ` [PATCH v3 0/9] [Resend][GSoC] " Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 1/9] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 2/9] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 3/9] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 4/9] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 5/9] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 6/9] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 7/9] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-17 19:29 ` Junio C Hamano
2020-08-19 13:36 ` Hariom verma
2020-08-19 16:01 ` Junio C Hamano
2020-08-19 16:08 ` Junio C Hamano
2020-08-20 17:33 ` Hariom verma
2020-08-20 17:27 ` Hariom verma
2020-08-17 18:10 ` [PATCH v3 8/9] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-08-17 19:33 ` Junio C Hamano
2020-08-17 18:10 ` [PATCH v3 9/9] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-17 19:37 ` [PATCH v3 0/9] [Resend][GSoC] Improvements to ref-filter Junio C Hamano
2020-08-21 21:41 ` [PATCH v4 0/8] [GSoC] " Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 1/8] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 2/8] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 3/8] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 4/8] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 5/8] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 6/8] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 7/8] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 8/8] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7b9103cbadfc111755d2db61239fcac4f4d14a33.1595882588.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=hariom18599@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).