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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]