http-backend: allow empty CONTENT_LENGTH
[git.git] / checkout.c
blobbdefc888bae1516f0ddcf22264807d031af7c991
1 #include "cache.h"
2 #include "remote.h"
3 #include "refspec.h"
4 #include "checkout.h"
6 struct tracking_name_data {
7 /* const */ char *src_ref;
8 char *dst_ref;
9 struct object_id *dst_oid;
10 int unique;
13 static int check_tracking_name(struct remote *remote, void *cb_data)
15 struct tracking_name_data *cb = cb_data;
16 struct refspec_item query;
17 memset(&query, 0, sizeof(struct refspec_item));
18 query.src = cb->src_ref;
19 if (remote_find_tracking(remote, &query) ||
20 get_oid(query.dst, cb->dst_oid)) {
21 free(query.dst);
22 return 0;
24 if (cb->dst_ref) {
25 free(query.dst);
26 cb->unique = 0;
27 return 0;
29 cb->dst_ref = query.dst;
30 return 0;
33 const char *unique_tracking_name(const char *name, struct object_id *oid)
35 struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };
36 cb_data.src_ref = xstrfmt("refs/heads/%s", name);
37 cb_data.dst_oid = oid;
38 for_each_remote(check_tracking_name, &cb_data);
39 free(cb_data.src_ref);
40 if (cb_data.unique)
41 return cb_data.dst_ref;
42 free(cb_data.dst_ref);
43 return NULL;