summaryrefslogtreecommitdiff
path: root/refspec.c
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2018-05-16 22:57:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-05-17 21:19:42 (GMT)
commit6d4c05785946e302e611be9ac1f5ca0b5ada9214 (patch)
tree94e5e42fc1b0cc1895d23457b13d2bb504b5d5ae /refspec.c
parent3eec3700fdc4d5b0a33729d45e7fb9735ed7e0f5 (diff)
downloadgit-6d4c05785946e302e611be9ac1f5ca0b5ada9214.zip
git-6d4c05785946e302e611be9ac1f5ca0b5ada9214.tar.gz
git-6d4c05785946e302e611be9ac1f5ca0b5ada9214.tar.bz2
refspec: introduce struct refspec
Introduce 'struct refspec', an abstraction around a collection of 'struct refspec_item's much like how 'struct pathspec' holds a collection of 'struct pathspec_item's. A refspec struct also contains an array of the original refspec strings which will be used to facilitate the migration to using this new abstraction throughout the code base. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refspec.c')
-rw-r--r--refspec.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/refspec.c b/refspec.c
index 8bf4ebb..af9d0d4 100644
--- a/refspec.c
+++ b/refspec.c
@@ -178,3 +178,67 @@ void free_refspec(int nr_refspec, struct refspec_item *refspec)
}
free(refspec);
}
+
+void refspec_item_init(struct refspec_item *item, const char *refspec, int fetch)
+{
+ memset(item, 0, sizeof(*item));
+
+ if (!parse_refspec(item, refspec, fetch))
+ die("Invalid refspec '%s'", refspec);
+}
+
+void refspec_item_clear(struct refspec_item *item)
+{
+ FREE_AND_NULL(item->src);
+ FREE_AND_NULL(item->dst);
+ item->force = 0;
+ item->pattern = 0;
+ item->matching = 0;
+ item->exact_sha1 = 0;
+}
+
+void refspec_init(struct refspec *rs, int fetch)
+{
+ memset(rs, 0, sizeof(*rs));
+ rs->fetch = fetch;
+}
+
+void refspec_append(struct refspec *rs, const char *refspec)
+{
+ struct refspec_item item;
+
+ refspec_item_init(&item, refspec, rs->fetch);
+
+ ALLOC_GROW(rs->items, rs->nr + 1, rs->alloc);
+ rs->items[rs->nr++] = item;
+
+ ALLOC_GROW(rs->raw, rs->raw_nr + 1, rs->raw_alloc);
+ rs->raw[rs->raw_nr++] = xstrdup(refspec);
+}
+
+void refspec_appendn(struct refspec *rs, const char **refspecs, int nr)
+{
+ int i;
+ for (i = 0; i < nr; i++)
+ refspec_append(rs, refspecs[i]);
+}
+
+void refspec_clear(struct refspec *rs)
+{
+ int i;
+
+ for (i = 0; i < rs->nr; i++)
+ refspec_item_clear(&rs->items[i]);
+
+ FREE_AND_NULL(rs->items);
+ rs->alloc = 0;
+ rs->nr = 0;
+
+ for (i = 0; i < rs->raw_nr; i++)
+ free((char *)rs->raw[i]);
+ FREE_AND_NULL(rs->raw);
+ rs->raw_alloc = 0;
+ rs->raw_nr = 0;
+
+ rs->fetch = 0;
+}