git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/8] port the filtering part of ref-filter to branch.c
@ 2015-08-22  6:51 Karthik Nayak
  2015-08-22  6:51 ` [PATCH v3 1/8] branch: refactor width computation Karthik Nayak
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Karthik Nayak @ 2015-08-22  6:51 UTC (permalink / raw)
  To: git; +Cc: christian.couder, Matthieu.Moy, gitster, Karthik Nayak

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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-08-24 18:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-22  6:51 [PATCH v3 0/8] port the filtering part of ref-filter to branch.c Karthik Nayak
2015-08-22  6:51 ` [PATCH v3 1/8] branch: refactor width computation Karthik Nayak
2015-08-22  6:51 ` [PATCH v3 2/8] branch: bump get_head_description() to the top Karthik Nayak
2015-08-22  6:51 ` [PATCH v3 3/8] branch: roll show_detached HEAD into regular ref_list Karthik Nayak
2015-08-22  6:51 ` [PATCH v3 4/8] branch: move 'current' check down to the presentation layer Karthik Nayak
2015-08-22  6:51 ` [PATCH v3 5/8] branch: drop non-commit error reporting Karthik Nayak
2015-08-22  6:51 ` [PATCH v3 6/8] branch.c: use 'ref-filter' data structures Karthik Nayak
2015-08-22  6:51 ` [PATCH v3 7/8] branch.c: use 'ref-filter' APIs Karthik Nayak
2015-08-22 15:51   ` Christian Couder
2015-08-22 17:50     ` Karthik Nayak
2015-08-24 17:31       ` Junio C Hamano
2015-08-24 18:10         ` Karthik Nayak
2015-08-22  6:51 ` [PATCH v3 8/8] branch: add '--points-at' option Karthik Nayak

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 NNTP newsgroup(s).