mirror of
https://github.com/git/git.git
synced 2026-01-10 12:53:12 +09:00
In 036876a1067 (config: hide functions using `the_repository` by default, 2024-08-13) we have moved around a bunch of functions in the config subsystem that depend on `the_repository`. Those function have been converted into mere wrappers around their equivalent function that takes in a repository as parameter, and the intent was that we'll eventually remove those wrappers to make the dependency on the global repository variable explicit at the callsite. Follow through with that intent and remove `git_config_get_string()`. All callsites are adjusted so that they use `repo_config_get_string(the_repository, ...)` instead. While some callsites might already have a repository available, this mechanical conversion is the exact same as the current situation and thus cannot cause any regression. Those sites should eventually be cleaned up in a later patch series. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
76 lines
2.0 KiB
C
76 lines
2.0 KiB
C
#define USE_THE_REPOSITORY_VARIABLE
|
|
|
|
#include "git-compat-util.h"
|
|
#include "object-name.h"
|
|
#include "remote.h"
|
|
#include "refspec.h"
|
|
#include "repository.h"
|
|
#include "checkout.h"
|
|
#include "config.h"
|
|
#include "strbuf.h"
|
|
|
|
struct tracking_name_data {
|
|
/* const */ char *src_ref;
|
|
char *dst_ref;
|
|
struct object_id *dst_oid;
|
|
int num_matches;
|
|
const char *default_remote;
|
|
char *default_dst_ref;
|
|
struct object_id *default_dst_oid;
|
|
};
|
|
|
|
#define TRACKING_NAME_DATA_INIT { 0 }
|
|
|
|
static int check_tracking_name(struct remote *remote, void *cb_data)
|
|
{
|
|
struct tracking_name_data *cb = cb_data;
|
|
struct refspec_item query;
|
|
memset(&query, 0, sizeof(struct refspec_item));
|
|
query.src = cb->src_ref;
|
|
if (remote_find_tracking(remote, &query) ||
|
|
repo_get_oid(the_repository, query.dst, cb->dst_oid)) {
|
|
free(query.dst);
|
|
return 0;
|
|
}
|
|
cb->num_matches++;
|
|
if (cb->default_remote && !strcmp(remote->name, cb->default_remote)) {
|
|
struct object_id *dst = xmalloc(sizeof(*cb->default_dst_oid));
|
|
cb->default_dst_ref = xstrdup(query.dst);
|
|
oidcpy(dst, cb->dst_oid);
|
|
cb->default_dst_oid = dst;
|
|
}
|
|
if (cb->dst_ref) {
|
|
free(query.dst);
|
|
return 0;
|
|
}
|
|
cb->dst_ref = query.dst;
|
|
return 0;
|
|
}
|
|
|
|
char *unique_tracking_name(const char *name, struct object_id *oid,
|
|
int *dwim_remotes_matched)
|
|
{
|
|
struct tracking_name_data cb_data = TRACKING_NAME_DATA_INIT;
|
|
const char *default_remote = NULL;
|
|
if (!repo_config_get_string_tmp(the_repository, "checkout.defaultremote", &default_remote))
|
|
cb_data.default_remote = default_remote;
|
|
cb_data.src_ref = xstrfmt("refs/heads/%s", name);
|
|
cb_data.dst_oid = oid;
|
|
for_each_remote(check_tracking_name, &cb_data);
|
|
if (dwim_remotes_matched)
|
|
*dwim_remotes_matched = cb_data.num_matches;
|
|
free(cb_data.src_ref);
|
|
if (cb_data.num_matches == 1) {
|
|
free(cb_data.default_dst_ref);
|
|
free(cb_data.default_dst_oid);
|
|
return cb_data.dst_ref;
|
|
}
|
|
free(cb_data.dst_ref);
|
|
if (cb_data.default_dst_ref) {
|
|
oidcpy(oid, cb_data.default_dst_oid);
|
|
free(cb_data.default_dst_oid);
|
|
return cb_data.default_dst_ref;
|
|
}
|
|
return NULL;
|
|
}
|