From: Karthik Nayak karthik@gmail.com
Make 'tag.c' use 'ref-filter' data structures and make changes to
support the new data structures. This is a part of the process
of porting 'tag.c' to use 'ref-filter' APIs.
This is a temporary step before porting 'tag.c' to use 'ref-filter'
completely. As this is a temporary step, most of the code
introduced here will be removed when 'tag.c' is ported over to use
'ref-filter' APIs
Mentored-by: Christian Couder christian.cou...@gmail.com
Mentored-by: Matthieu Moy matthieu@grenoble-inp.fr
Signed-off-by: Karthik Nayak karthik@gmail.com
---
builtin/tag.c | 106 +++---
1 file changed, 57 insertions(+), 49 deletions(-)
diff --git a/builtin/tag.c b/builtin/tag.c
index 0fc7557..e96bae2 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -17,6 +17,7 @@
#include gpg-interface.h
#include sha1-array.h
#include column.h
+#include ref-filter.h
static const char * const git_tag_usage[] = {
N_(git tag [-a | -s | -u key-id] [-f] [-m msg | -F file]
tagname [head]),
@@ -34,15 +35,6 @@ static const char * const git_tag_usage[] = {
static int tag_sort;
-struct tag_filter {
- const char **patterns;
- int lines;
- int sort;
- struct string_list tags;
- struct commit_list *with_commit;
-};
-
-static struct sha1_array points_at;
static unsigned int colopts;
static int match_pattern(const char **patterns, const char *ref)
@@ -61,19 +53,20 @@ static int match_pattern(const char **patterns, const char
*ref)
* removed as we port tag.c to use the ref-filter APIs.
*/
static const unsigned char *match_points_at(const char *refname,
- const unsigned char *sha1)
+ const unsigned char *sha1,
+ struct sha1_array *points_at)
{
const unsigned char *tagged_sha1 = NULL;
struct object *obj;
- if (sha1_array_lookup(points_at, sha1) = 0)
+ if (sha1_array_lookup(points_at, sha1) = 0)
return sha1;
obj = parse_object(sha1);
if (!obj)
die(_(malformed object at '%s'), refname);
if (obj-type == OBJ_TAG)
tagged_sha1 = ((struct tag *)obj)-tagged-sha1;
- if (tagged_sha1 sha1_array_lookup(points_at, tagged_sha1) = 0)
+ if (tagged_sha1 sha1_array_lookup(points_at, tagged_sha1) = 0)
return tagged_sha1;
return NULL;
}
@@ -228,12 +221,24 @@ free_return:
free(buf);
}
+static void ref_array_append(struct ref_array *array, const char *refname)
+{
+ size_t len = strlen(refname);
+ struct ref_array_item *ref = xcalloc(1, sizeof(struct ref_array_item) +
len + 1);
+ memcpy(ref-refname, refname, len);
+ ref-refname[len] = '\0';
+ REALLOC_ARRAY(array-items, array-nr + 1);
+ array-items[array-nr++] = ref;
+}
+
static int show_reference(const char *refname, const struct object_id *oid,
int flag, void *cb_data)
{
- struct tag_filter *filter = cb_data;
+ struct ref_filter_cbdata *data = cb_data;
+ struct ref_array *array = data-array;
+ struct ref_filter *filter = data-filter;
- if (match_pattern(filter-patterns, refname)) {
+ if (match_pattern(filter-name_patterns, refname)) {
if (filter-with_commit) {
struct commit *commit;
@@ -244,12 +249,12 @@ static int show_reference(const char *refname, const
struct object_id *oid,
return 0;
}
- if (points_at.nr !match_points_at(refname, oid-hash))
+ if (filter-points_at.nr !match_points_at(refname,
oid-hash, filter-points_at))
return 0;
if (!filter-lines) {
- if (filter-sort)
- string_list_append(filter-tags, refname);
+ if (tag_sort)
+ ref_array_append(array, refname);
else
printf(%s\n, refname);
return 0;
@@ -264,36 +269,36 @@ static int show_reference(const char *refname, const
struct object_id *oid,
static int sort_by_version(const void *a_, const void *b_)
{
- const struct string_list_item *a = a_;
- const struct string_list_item *b = b_;
- return versioncmp(a-string, b-string);
+ const struct ref_array_item *a = *((struct ref_array_item **)a_);
+ const struct ref_array_item *b = *((struct ref_array_item **)b_);
+ return versioncmp(a-refname, b-refname);
}
-static int list_tags(const char **patterns, int lines,
-struct commit_list *with_commit, int sort)
+static int list_tags(struct ref_filter *filter, int sort)
{
- struct tag_filter filter;
+ struct ref_array array;
+