git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 5/5] [GSOC] ref-filter: add %(rest) atom

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jul 22, 2021, 08:11 UTC
Message-ID
<874kcmvjr6.fsf@evledraar.gmail.com>
In-Reply-To
<75eb2f6740eb5845afcb7d31956cc5b3e3957f97.1626939557.git.gitgitgadget@gmail.com>
On Thu, Jul 22 2021, ZheNing Hu via GitGitGadget wrote:
Show 8 quoted lines
> +		} else if (atom_type == ATOM_REST) {
> +			if (ref->rest)
> +				v->s = xstrdup(ref->rest);
> +			else
> +				v->s = xstrdup("");
> +			continue;
>  		} else
>  			continue;
Another light reading nit, maybe more readable as:
    } else if (atom_type == ATOM_REST && ref->rest) {
        ...
    } else if (atom_type == ATOM_REST) {
        ...
    }
    continue;

But we can't do that "continue" at the end because there's two cases where we don't continue, I wondered if elimanting that special case would make it easier, patch below. Probably not worth it & feel free to ignore:

 ref-filter.c | 63 +++++++++++++++++++++++++-----------------------------------
 1 file changed, 26 insertions(+), 37 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index 81e77b13ad2..189244fed6f 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1890,18 +1890,26 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 			name++;
 		}
 
-		if (atom_type == ATOM_REFNAME)
+		if (atom_type == ATOM_REFNAME) {
 			refname = get_refname(atom, ref);
-		else if (atom_type == ATOM_WORKTREEPATH) {
-			if (ref->kind == FILTER_REFS_BRANCHES)
-				v->s = get_worktree_path(atom, ref);
+			if (!deref)
+				v->s = xstrdup(refname);
 			else
-				v->s = xstrdup("");
-			continue;
-		}
-		else if (atom_type == ATOM_SYMREF)
+				v->s = xstrfmt("%s^{}", refname);
+			free((char *)refname);
+		} else if (atom_type == ATOM_WORKTREEPATH &&
+			   ref->kind == FILTER_REFS_BRANCHES) {
+			v->s = get_worktree_path(atom, ref);
+		} else if (atom_type == ATOM_WORKTREEPATH) {
+			v->s = xstrdup("");
+		} else if (atom_type == ATOM_SYMREF) {
 			refname = get_symref(atom, ref);
-		else if (atom_type == ATOM_UPSTREAM) {
+			if (!deref)
+				v->s = xstrdup(refname);
+			else
+				v->s = xstrfmt("%s^{}", refname);
+			free((char *)refname);
+		} else if (atom_type == ATOM_UPSTREAM) {
 			const char *branch_name;
 			/* only local branches may have an upstream */
 			if (!skip_prefix(ref->refname, "refs/heads/",
@@ -1916,7 +1924,6 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 				fill_remote_ref_details(atom, refname, branch, &v->s);
 			else
 				v->s = xstrdup("");
-			continue;
 		} else if (atom_type == ATOM_PUSH && atom->u.remote_ref.push) {
 			const char *branch_name;
 			v->s = xstrdup("");
@@ -1935,10 +1942,8 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 			/* We will definitely re-init v->s on the next line. */
 			free((char *)v->s);
 			fill_remote_ref_details(atom, refname, branch, &v->s);
-			continue;
 		} else if (atom_type == ATOM_COLOR) {
 			v->s = xstrdup(atom->u.color);
-			continue;
 		} else if (atom_type == ATOM_FLAG) {
 			char buf[256], *cp = buf;
 			if (ref->flag & REF_ISSYMREF)
@@ -1951,24 +1956,20 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 				*cp = '\0';
 				v->s = xstrdup(buf + 1);
 			}
-			continue;
 		} else if (!deref && atom_type == ATOM_OBJECTNAME) {
 			   v->s = xstrdup(do_grab_oid("objectname", &ref->objectname, atom));
-			   continue;
+		} else if (atom_type == ATOM_HEAD &&
+			   atom->u.head &&
+			   !strcmp(ref->refname, atom->u.head)) {
+			v->s = xstrdup("*");
 		} else if (atom_type == ATOM_HEAD) {
-			if (atom->u.head && !strcmp(ref->refname, atom->u.head))
-				v->s = xstrdup("*");
-			else
-				v->s = xstrdup(" ");
-			continue;
+			v->s = xstrdup(" ");
 		} else if (atom_type == ATOM_ALIGN) {
 			v->handler = align_atom_handler;
 			v->s = xstrdup("");
-			continue;
 		} else if (atom_type == ATOM_END) {
 			v->handler = end_atom_handler;
 			v->s = xstrdup("");
-			continue;
 		} else if (atom_type == ATOM_IF) {
 			const char *s;
 			if (skip_prefix(name, "if:", &s))
@@ -1976,29 +1977,17 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
 			else
 				v->s = xstrdup("");
 			v->handler = if_atom_handler;
-			continue;
 		} else if (atom_type == ATOM_THEN) {
 			v->handler = then_atom_handler;
 			v->s = xstrdup("");
-			continue;
 		} else if (atom_type == ATOM_ELSE) {
 			v->handler = else_atom_handler;
 			v->s = xstrdup("");
-			continue;
+		} else if (atom_type == ATOM_REST && ref->rest) {
+			v->s = xstrdup(ref->rest);
 		} else if (atom_type == ATOM_REST) {
-			if (ref->rest)
-				v->s = xstrdup(ref->rest);
-			else
-				v->s = xstrdup("");
-			continue;
-		} else
-			continue;
-
-		if (!deref)
-			v->s = xstrdup(refname);
-		else
-			v->s = xstrfmt("%s^{}", refname);
-		free((char *)refname);
+			v->s = xstrdup("");
+		}
 	}
 
 	for (i = 0; i < used_atom_cnt; i++) {
Previous: ZheNing Hu via GitGitGadgetNext: ZheNing Hu
Message 11 of 45 in “[GSOC] ref-filter: add %(raw) and %(rest) atoms”
  1. 0/5 [GSOC] ref-filter: add %(raw) and %(rest) atomsZheNing Hu via GitGitGadget, Jul 22, 2021
  2. 1/5 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jul 22, 2021
  3. Christian CouderJul 22, 2021
  4. ZheNing HuJul 22, 2021
  5. 2/5 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jul 22, 2021
  6. Ævar Arnfjörð BjarmasonJul 22, 2021
  7. ZheNing HuJul 22, 2021
  8. 3/5 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jul 22, 2021
  9. 4/5 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jul 22, 2021
  10. 5/5 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jul 22, 2021
  11. Ævar Arnfjörð BjarmasonJul 22, 2021
  12. ZheNing HuJul 22, 2021
  13. Jacob KellerJul 23, 2021
  14. ZheNing HuJul 23, 2021
  15. Christian CouderJul 22, 2021
  16. ZheNing HuJul 22, 2021
  17. 0/5 [GSOC] ref-filter: add %(raw) and %(rest) atomsZheNing Hu via GitGitGadget, Jul 23, 2021
  18. 1/5 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jul 23, 2021
  19. 3/5 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jul 23, 2021
  20. 2/5 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jul 23, 2021
  21. Junio C HamanoJul 23, 2021
  22. ZheNing HuJul 24, 2021
  23. Junio C HamanoJul 24, 2021
  24. ZheNing HuJul 25, 2021
  25. 4/5 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jul 23, 2021
  26. 5/5 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jul 23, 2021
  27. 0/5 [GSOC] ref-filter: add %(raw) and %(rest) atomsZheNing Hu via GitGitGadget, Jul 24, 2021
  28. 1/5 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jul 24, 2021
  29. Jacob KellerJul 25, 2021
  30. 2/5 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jul 24, 2021
  31. 3/5 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jul 24, 2021
  32. Jacob KellerJul 25, 2021
  33. ZheNing HuJul 25, 2021
  34. 4/5 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jul 24, 2021
  35. 5/5 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jul 24, 2021
  36. Jacob KellerJul 25, 2021
  37. Junio C HamanoJul 26, 2021
  38. 0/5 [GSOC] ref-filter: add %(raw) and %(rest) atomsZheNing Hu via GitGitGadget, Jul 26, 2021
  39. 1/5 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jul 26, 2021
  40. Junio C HamanoJul 26, 2021
  41. ZheNing HuJul 27, 2021
  42. 2/5 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jul 26, 2021
  43. 3/5 [GSOC] ref-filter: --format=%(raw) support --perlZheNing Hu via GitGitGadget, Jul 26, 2021
  44. 4/5 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jul 26, 2021
  45. 5/5 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jul 26, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.