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

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

From
Karthik Nayak <karthik.188@gmail.com>
Date
Aug 22, 2015, 06:51 UTC
Message-ID
<1440226309-25415-1-git-send-email-Karthik.188@gmail.com>
This is a follow up to porting tag.c to use ref-fitler APIs.

v2 of this patch series can be found here: http://thread.gmane.org/gmane.comp.version-control.git/276147

Changes made in this series:
* Improve comment in 3/8 and fix grammar in 5/8.
* Fix the test in t1430 to check stderr for the broken ref warning.
* Instead of showing the detached head, reducing the no of array elements
and displaying all of the other refs and then free'ing all of the refs. We
now free the detached head ref immediately after displaying so we don't have
to bother about decrementing and incrementing the no of array elements.
* 
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             | 506 +++++++++++++------------------------------
 ref-filter.c                 |   4 +-
 ref-filter.h                 |   8 +-
 t/t1430-bad-ref-name.sh      |   2 +-
 t/t3203-branch-output.sh     |  20 ++
 6 files changed, 197 insertions(+), 356 deletions(-)
Interdiff:
diff --git a/builtin/branch.c b/builtin/branch.c
index dd2fdbe..32a0d11 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -475,7 +475,7 @@ static int calc_maxwidth(struct ref_array *refs, int remote_bonus)
 
 static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sorting)
 {
-	int i, index;
+	int i;
 	struct ref_array array;
 	int maxwidth = 0;
 	const char *remote_prefix = "";
@@ -493,17 +493,16 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
 	memset(&array, 0, sizeof(array));
 
 	verify_ref_format("%(refname)%(symref)");
-	filter_refs(&array, filter, filter->kind);
+	filter_refs(&array, filter, filter->kind | FILTER_REFS_INCLUDE_BROKEN);
 
 	if (filter->verbose)
 		maxwidth = calc_maxwidth(&array, strlen(remote_prefix));
 
-	index = array.nr;
-
 	/* Print detached HEAD before sorting and printing the rest */
 	if (filter->kind & FILTER_REFS_DETACHED_HEAD) {
-		format_and_print_ref_item(array.items[index - 1], maxwidth, filter, remote_prefix);
-		array.nr -= 1;
+		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) {
@@ -517,7 +516,6 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
 	for (i = 0; i < array.nr; i++)
 		format_and_print_ref_item(array.items[i], maxwidth, filter, remote_prefix);
 
-	array.nr = index;
 	ref_array_clear(&array);
 }
 
diff --git a/ref-filter.c b/ref-filter.c
index 112feaa..3cd0c00 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1251,7 +1251,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 }
 
 /*  Free memory allocated for a ref_array_item */
-static void free_array_item(struct ref_array_item *item)
+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 3e29e5d..3e25d84 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -89,6 +89,8 @@ 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 dcf2931..db3627e 100755
--- a/t/t1430-bad-ref-name.sh
+++ b/t/t1430-bad-ref-name.sh
@@ -38,11 +38,11 @@ test_expect_success 'fast-import: fail on invalid branch name "bad[branch]name"'
 	test_must_fail git fast-import <input
 '
 
-test_expect_failure 'git branch shows badly named ref' '
-       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
-       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
-       git branch >output &&
-       grep -e "broken\.\.\.ref" output
+test_expect_success 'git branch shows badly named ref as warning' '
+	cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+	test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+	git branch 2>output &&
+	grep -e "broken\.\.\.ref" output
 '
 
 test_expect_success 'branch -d can delete badly named ref' '
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 1deb7cb..c819f3e 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -144,21 +144,21 @@ EOF
 '
 
 test_expect_success 'git branch `--sort` option' '
-	cat >expect <<EOF &&
-* (HEAD detached from fromtag)
-  branch-two
-  branch-one
-  master
-EOF
+	cat >expect <<-\EOF &&
+	* (HEAD detached from fromtag)
+	  branch-two
+	  branch-one
+	  master
+	EOF
 	git branch --sort=objectsize >actual &&
 	test_i18ncmp expect actual
 '
 
 test_expect_success 'git branch --points-at option' '
-	cat >expect <<EOF &&
-  master
-  branch-one
-EOF
+	cat >expect <<-\EOF &&
+	  master
+	  branch-one
+	EOF
 	git branch --points-at=branch-one >actual &&
 	test_cmp expect actual
 '
-- 
2.5.0
Next: Karthik Nayak
Message 1 of 13 in “port the filtering part of ref-filter to branch.c”
  1. 0/8 port the filtering part of ref-filter to branch.cKarthik Nayak, Aug 22, 2015
  2. 1/8 branch: refactor width computationKarthik Nayak, Aug 22, 2015
  3. 2/8 branch: bump get_head_description() to the topKarthik Nayak, Aug 22, 2015
  4. 3/8 branch: roll show_detached HEAD into regular ref_listKarthik Nayak, Aug 22, 2015
  5. 4/8 branch: move 'current' check down to the presentation layerKarthik Nayak, Aug 22, 2015
  6. 5/8 branch: drop non-commit error reportingKarthik Nayak, Aug 22, 2015
  7. 6/8 branch.c: use 'ref-filter' data structuresKarthik Nayak, Aug 22, 2015
  8. 7/8 branch.c: use 'ref-filter' APIsKarthik Nayak, Aug 22, 2015
  9. Christian CouderAug 22, 2015
  10. Karthik NayakAug 22, 2015
  11. Junio C HamanoAug 24, 2015
  12. Karthik NayakAug 24, 2015
  13. 8/8 branch: add '--points-at' optionKarthik Nayak, Aug 22, 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.