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

[PATCH v5 0/8] port the filtering part of branch.c to use ref-filter APIs

From
Karthik Nayak <karthik.188@gmail.com>
Date
Sep 20, 2015, 18:10 UTC
Message-ID
<1442772627-25421-1-git-send-email-Karthik.188@gmail.com>
This is part of porting 'branch -l' to use ref-filter APIs

The previous version of this series (v4) can be found here: thread.gmane.org/gmane.comp.version-control.git/277761

Changes in this version include:
* Now we sort by 'refname' by default, this eliminates the need
for attaching the detached head at the end of the array and printing
it initially.
* Fix broken tests.
Karthik Nayak (8):
  branch: refactor width computation
  branch: bump get_head_description() to the top
  branch: roll show_detached HEAD into regular ref_list
  branch: move 'current' check down to the presentation layer
  branch: drop non-commit error reporting
  branch.c: use 'ref-filter' data structures
  branch.c: use 'ref-filter' APIs
  branch: add '--points-at' option
 Documentation/git-branch.txt |  13 +-
 builtin/branch.c             | 501 +++++++++++++------------------------------
 ref-filter.c                 |   2 +-
 ref-filter.h                 |   6 +-
 t/t1430-bad-ref-name.sh      |  31 ++-
 t/t3203-branch-output.sh     |  20 ++
 6 files changed, 207 insertions(+), 366 deletions(-)
Interdiff:
diff --git a/builtin/branch.c b/builtin/branch.c
index 32a0d11..9065c70 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -480,7 +480,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
 	int maxwidth = 0;
 	const char *remote_prefix = "";
 	struct ref_sorting def_sorting;
-	const char *sort_type = "type";
+	const char *sort_type = "refname";
 
 	/*
 	 * If we are listing more than just remote branches,
@@ -498,13 +498,6 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
 	if (filter->verbose)
 		maxwidth = calc_maxwidth(&array, strlen(remote_prefix));
 
-	/* Print detached HEAD before sorting and printing the rest */
-	if (filter->kind & FILTER_REFS_DETACHED_HEAD) {
-		format_and_print_ref_item(array.items[array.nr - 1], maxwidth, filter, remote_prefix);
-		free_array_item(array.items[array.nr - 1]);
-		array.nr--;
-	}
-
 	if (!sorting) {
 		def_sorting.next = NULL;
 		def_sorting.atom = parse_ref_filter_atom(sort_type,
diff --git a/ref-filter.c b/ref-filter.c
index c536aea..dbd8fce 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1356,7 +1356,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 }
 
 /*  Free memory allocated for a ref_array_item */
-void free_array_item(struct ref_array_item *item)
+static void free_array_item(struct ref_array_item *item)
 {
 	free((char *)item->symref);
 	free(item);
diff --git a/ref-filter.h b/ref-filter.h
index 9316031..14d435e 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -90,8 +90,6 @@ struct ref_filter_cbdata {
  * filtered refs in the ref_array structure.
  */
 int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type);
-/*  Clear memory allocated to a ref_array_item */
-void free_array_item(struct ref_array_item *item);
 /*  Clear all memory allocated to ref_array */
 void ref_array_clear(struct ref_array *array);
 /*  Parse format string and sort specifiers */
diff --git a/t/t1430-bad-ref-name.sh b/t/t1430-bad-ref-name.sh
index 070cf06..c465abe 100755
--- a/t/t1430-bad-ref-name.sh
+++ b/t/t1430-bad-ref-name.sh
@@ -139,7 +139,7 @@ test_expect_failure 'push --mirror can delete badly named ref' '
 	) &&
 	git -C src push --mirror "file://$top/dest" &&
 	git -C dest branch >output 2>error &&
-	! grep -e "broken\.\.\.ref" error
+	! grep -e "broken\.\.\.ref" error &&
 	! grep -e "broken\.\.\.ref" output
 '
 
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index c819f3e..f1ae5ff 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -145,8 +145,8 @@ EOF
 
 test_expect_success 'git branch `--sort` option' '
 	cat >expect <<-\EOF &&
-	* (HEAD detached from fromtag)
 	  branch-two
+	* (HEAD detached from fromtag)
 	  branch-one
 	  master
 	EOF
@@ -156,8 +156,8 @@ test_expect_success 'git branch `--sort` option' '
 
 test_expect_success 'git branch --points-at option' '
 	cat >expect <<-\EOF &&
-	  master
 	  branch-one
+	  master
 	EOF
 	git branch --points-at=branch-one >actual &&
 	test_cmp expect actual
-- 
2.5.1
Next: Karthik Nayak
Message 1 of 19 in “port the filtering part of branch.c to use ref-filter APIs”
  1. 0/8 port the filtering part of branch.c to use ref-filter APIsKarthik Nayak, Sep 20, 2015
  2. 1/8 branch: refactor width computationKarthik Nayak, Sep 20, 2015
  3. 2/8 branch: bump get_head_description() to the topKarthik Nayak, Sep 20, 2015
  4. 3/8 branch: roll show_detached HEAD into regular ref_listKarthik Nayak, Sep 20, 2015
  5. Matthieu MoySep 20, 2015
  6. 4/8 branch: move 'current' check down to the presentation layerKarthik Nayak, Sep 20, 2015
  7. 5/8 branch: drop non-commit error reportingKarthik Nayak, Sep 20, 2015
  8. Matthieu MoySep 20, 2015
  9. Karthik NayakSep 21, 2015
  10. Karthik NayakSep 21, 2015
  11. 6/8 branch.c: use 'ref-filter' data structuresKarthik Nayak, Sep 20, 2015
  12. 7/8 branch.c: use 'ref-filter' APIsKarthik Nayak, Sep 20, 2015
  13. Matthieu MoySep 20, 2015
  14. Karthik NayakSep 21, 2015
  15. 8/8 branch: add '--points-at' optionKarthik Nayak, Sep 20, 2015
  16. Matthieu MoySep 20, 2015
  17. Karthik NayakSep 21, 2015
  18. Matthieu MoySep 21, 2015
  19. Karthik NayakSep 21, 2015

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.