* Parses the provided refspec 'refspec' and populates the refspec_item 'item'.
* Returns 1 if successful and 0 if the refspec is invalid.
*/
-static int parse_refspec(struct refspec_item *item, const char *refspec, int fetch)
+static int parse_refspec(struct refspec_item *item, const char *refspec,
+ const struct git_hash_algo *algo, int fetch)
{
size_t llen;
int is_glob;
*/
if (!*item->src)
return 0; /* negative refspecs must not be empty */
- else if (llen == the_hash_algo->hexsz && !get_oid_hex(item->src, &unused))
+ else if (llen == algo->hexsz && !get_oid_hex_algop(item->src, &unused, algo))
return 0; /* negative refspecs cannot be exact sha1 */
else if (!check_refname_format(item->src, flags))
; /* valid looking ref is ok */
/* LHS */
if (!*item->src)
; /* empty is ok; it means "HEAD" */
- else if (llen == the_hash_algo->hexsz && !get_oid_hex(item->src, &unused))
+ else if (llen == algo->hexsz && !get_oid_hex_algop(item->src, &unused, algo))
item->exact_sha1 = 1; /* ok */
else if (!check_refname_format(item->src, flags))
; /* valid looking ref is ok */
}
static int refspec_item_init(struct refspec_item *item, const char *refspec,
- int fetch)
+ const struct git_hash_algo *algo, int fetch)
{
memset(item, 0, sizeof(*item));
item->raw = xstrdup(refspec);
- return parse_refspec(item, refspec, fetch);
+ return parse_refspec(item, refspec, algo, fetch);
}
-int refspec_item_init_fetch(struct refspec_item *item, const char *refspec)
+int refspec_item_init_fetch(struct refspec_item *item, const char *refspec,
+ const struct git_hash_algo *algo)
{
- return refspec_item_init(item, refspec, 1);
+ return refspec_item_init(item, refspec, algo, 1);
}
-int refspec_item_init_push(struct refspec_item *item, const char *refspec)
+int refspec_item_init_push(struct refspec_item *item, const char *refspec,
+ const struct git_hash_algo *algo)
{
- return refspec_item_init(item, refspec, 0);
+ return refspec_item_init(item, refspec, algo, 0);
}
void refspec_item_clear(struct refspec_item *item)
int ret;
if (rs->fetch)
- ret = refspec_item_init_fetch(&item, refspec);
+ ret = refspec_item_init_fetch(&item, refspec, the_hash_algo);
else
- ret = refspec_item_init_push(&item, refspec);
+ ret = refspec_item_init_push(&item, refspec, the_hash_algo);
if (!ret)
die(_("invalid refspec '%s'"), refspec);
rs->fetch = 0;
}
-int valid_fetch_refspec(const char *fetch_refspec_str)
+int valid_fetch_refspec(const char *fetch_refspec_str,
+ const struct git_hash_algo *algo)
{
struct refspec_item refspec;
- int ret = refspec_item_init_fetch(&refspec, fetch_refspec_str);
+ int ret = refspec_item_init_fetch(&refspec, fetch_refspec_str, algo);
refspec_item_clear(&refspec);
return ret;
}
#ifndef REFSPEC_H
#define REFSPEC_H
+struct git_hash_algo;
struct string_list;
struct strvec;
char *raw;
};
-int refspec_item_init_fetch(struct refspec_item *item, const char *refspec);
-int refspec_item_init_push(struct refspec_item *item, const char *refspec);
+int refspec_item_init_fetch(struct refspec_item *item, const char *refspec,
+ const struct git_hash_algo *algo);
+int refspec_item_init_push(struct refspec_item *item, const char *refspec,
+ const struct git_hash_algo *algo);
void refspec_item_clear(struct refspec_item *item);
/**
void refspec_appendf(struct refspec *rs, const char *fmt, ...);
void refspec_appendn(struct refspec *rs, const char **refspecs, int nr);
-int valid_fetch_refspec(const char *refspec);
+int valid_fetch_refspec(const char *refspec, const struct git_hash_algo *algo);
/*
* Determine what <prefix> values to pass to the peer in ref-prefix lines