mbox series

[v4,0/8,GSoC] Improvements to ref-filter

Message ID pull.684.v4.git.1598046110.gitgitgadget@gmail.com (mailing list archive)
Headers show
Series Improvements to ref-filter | expand

Message

Philippe Blain via GitGitGadget Aug. 21, 2020, 9:41 p.m. UTC
This is the first patch series that introduces some improvements and
features to file ref-filter.{c,h}. These changes are useful to ref-filter,
but in near future also will allow us to use ref-filter's logic in pretty.c

I plan to add more to format-support.{c,h} in the upcoming patch series.
That will lead to more improved and feature-rich ref-filter.c

Hariom Verma (8):
  ref-filter: support different email formats
  ref-filter: refactor `grab_objectname()`
  ref-filter: modify error messages in `grab_objectname()`
  ref-filter: rename `objectname` related functions and fields
  ref-filter: add `short` modifier to 'tree' atom
  ref-filter: add `short` modifier to 'parent' atom
  pretty: refactor `format_sanitized_subject()`
  ref-filter: add `sanitize` option for 'subject' atom

 Documentation/git-for-each-ref.txt |  10 +-
 pretty.c                           |  20 ++--
 pretty.h                           |   3 +
 ref-filter.c                       | 158 +++++++++++++++++++----------
 t/t6300-for-each-ref.sh            |  35 +++++++
 5 files changed, 161 insertions(+), 65 deletions(-)


base-commit: 675a4aaf3b226c0089108221b96559e0baae5de9
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-684%2Fharry-hov%2Fonly-rf6-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-684/harry-hov/only-rf6-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/684

Range-diff vs v3:

  1:  3e6fc66a46 =  1:  55618fe4c1 ref-filter: support different email formats
  2:  5268b973da =  2:  c508c96eb8 ref-filter: refactor `grab_objectname()`
  3:  4a12ff8210 =  3:  582f00ace6 ref-filter: modify error messages in `grab_objectname()`
  4:  d53ca56778 =  4:  503a1874ce ref-filter: rename `objectname` related functions and fields
  5:  fd4ed82e80 =  5:  6b97166796 ref-filter: add `short` modifier to 'tree' atom
  6:  7a039823de =  6:  5ed5ac259d ref-filter: add `short` modifier to 'parent' atom
  7:  0ad22c7cdd !  7:  6105046d96 pretty: refactor `format_sanitized_subject()`
     @@ Commit message
          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 <chriscool@tuxfamily.org>
          Mentored-by: Heba Waly <heba.waly@gmail.com>
          Signed-off-by: Hariom Verma <hariom18599@gmail.com>
     @@ pretty.c: static int istitlechar(char 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)
     ++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;
     @@ pretty.c: static int istitlechar(char c)
      -	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 (istitlechar(msg[i])) {
       			if (space == 1)
       				strbuf_addch(sb, '-');
       			space = 0;
     @@ pretty.c: static int istitlechar(char c)
      -			if (*msg == '.')
      -				while (*(msg+1) == '.')
      -					msg++;
     -+			strbuf_addch(sb, r[i]);
     -+			if (r[i] == '.')
     -+				while (r[i+1] == '.')
     ++			strbuf_addch(sb, msg[i]);
     ++			if (msg[i] == '.')
     ++				while (msg[i+1] == '.')
      +					i++;
       		} else
       			space |= 1;
       	}
     -+	free(r);
     - 
     - 	/* trim any trailing '.' or '-' characters */
     - 	trimlen = 0;
      @@ pretty.c: static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
       	const struct commit *commit = c->commit;
       	const char *msg = c->message;
     @@ pretty.c: static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
       		return 1;
       	case 'b':	/* body */
       		strbuf_addstr(sb, msg + c->body_off);
     +
     + ## pretty.h ##
     +@@ pretty.h: 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 */
  8:  7a64495f99 <  -:  ---------- format-support: move `format_sanitized_subject()` from pretty
  9:  1ab35e9251 !  8:  7cba8d7a28 ref-filter: add `sanitize` option for 'subject' atom
     @@ Documentation/git-for-each-ref.txt: contents:subject::
       	The remainder of the commit or the tag message that follows
      
       ## ref-filter.c ##
     -@@
     - #include "worktree.h"
     - #include "hashmap.h"
     - #include "strvec.h"
     -+#include "format-support.h"
     - 
     - static struct ref_msg {
     - 	const char *gone;
      @@ ref-filter.c: static struct used_atom {
       			unsigned int nobracket : 1, push : 1, push_remote : 1;
       		} remote_ref;