зеркало из https://github.com/microsoft/git.git
Rename resolve_ref() to resolve_ref_unsafe()
resolve_ref() may return a pointer to a shared buffer and can be overwritten by the next resolve_ref() calls. Callers need to pay attention, not to keep the pointer when the next call happens. Rename with "_unsafe" suffix to warn developers (or reviewers) before introducing new call sites. This patch is generated using the following command git grep -l 'resolve_ref(' -- '*.[ch]'|xargs sed -i 's/resolve_ref(/resolve_ref_unsafe(/g' Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
96ec7b1e70
Коммит
8cad4744ee
2
branch.c
2
branch.c
|
@ -182,7 +182,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
|
||||||
const char *head;
|
const char *head;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
|
|
||||||
head = resolve_ref("HEAD", sha1, 0, NULL);
|
head = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
|
||||||
if (!is_bare_repository() && head && !strcmp(head, ref->buf))
|
if (!is_bare_repository() && head && !strcmp(head, ref->buf))
|
||||||
die("Cannot force update the current branch.");
|
die("Cannot force update the current branch.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,7 +252,7 @@ static char *resolve_symref(const char *src, const char *prefix)
|
||||||
int flag;
|
int flag;
|
||||||
const char *dst, *cp;
|
const char *dst, *cp;
|
||||||
|
|
||||||
dst = resolve_ref(src, sha1, 0, &flag);
|
dst = resolve_ref_unsafe(src, sha1, 0, &flag);
|
||||||
if (!(dst && (flag & REF_ISSYMREF)))
|
if (!(dst && (flag & REF_ISSYMREF)))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (prefix && (cp = skip_prefix(dst, prefix)))
|
if (prefix && (cp = skip_prefix(dst, prefix)))
|
||||||
|
|
|
@ -1304,7 +1304,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
|
||||||
rev.diffopt.break_opt = 0;
|
rev.diffopt.break_opt = 0;
|
||||||
diff_setup_done(&rev.diffopt);
|
diff_setup_done(&rev.diffopt);
|
||||||
|
|
||||||
head = resolve_ref("HEAD", junk_sha1, 0, NULL);
|
head = resolve_ref_unsafe("HEAD", junk_sha1, 0, NULL);
|
||||||
printf("[%s%s ",
|
printf("[%s%s ",
|
||||||
!prefixcmp(head, "refs/heads/") ?
|
!prefixcmp(head, "refs/heads/") ?
|
||||||
head + 11 :
|
head + 11 :
|
||||||
|
|
|
@ -563,7 +563,7 @@ static int fsck_head_link(void)
|
||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr, "Checking HEAD link\n");
|
fprintf(stderr, "Checking HEAD link\n");
|
||||||
|
|
||||||
head_points_at = resolve_ref("HEAD", head_sha1, 0, &flag);
|
head_points_at = resolve_ref_unsafe("HEAD", head_sha1, 0, &flag);
|
||||||
if (!head_points_at)
|
if (!head_points_at)
|
||||||
return error("Invalid HEAD");
|
return error("Invalid HEAD");
|
||||||
if (!strcmp(head_points_at, "HEAD"))
|
if (!strcmp(head_points_at, "HEAD"))
|
||||||
|
|
|
@ -1040,7 +1040,7 @@ static char *find_branch_name(struct rev_info *rev)
|
||||||
if (positive < 0)
|
if (positive < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
strbuf_addf(&buf, "refs/heads/%s", rev->cmdline.rev[positive].name);
|
strbuf_addf(&buf, "refs/heads/%s", rev->cmdline.rev[positive].name);
|
||||||
branch = resolve_ref(buf.buf, branch_sha1, 1, NULL);
|
branch = resolve_ref_unsafe(buf.buf, branch_sha1, 1, NULL);
|
||||||
if (!branch ||
|
if (!branch ||
|
||||||
prefixcmp(branch, "refs/heads/") ||
|
prefixcmp(branch, "refs/heads/") ||
|
||||||
hashcmp(rev->cmdline.rev[positive].item->sha1, branch_sha1))
|
hashcmp(rev->cmdline.rev[positive].item->sha1, branch_sha1))
|
||||||
|
@ -1268,7 +1268,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
||||||
|
|
||||||
rev.pending.objects[0].item->flags |= UNINTERESTING;
|
rev.pending.objects[0].item->flags |= UNINTERESTING;
|
||||||
add_head_to_pending(&rev);
|
add_head_to_pending(&rev);
|
||||||
ref = resolve_ref("HEAD", sha1, 1, NULL);
|
ref = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
|
||||||
if (ref && !prefixcmp(ref, "refs/heads/"))
|
if (ref && !prefixcmp(ref, "refs/heads/"))
|
||||||
branch_name = xstrdup(ref + strlen("refs/heads/"));
|
branch_name = xstrdup(ref + strlen("refs/heads/"));
|
||||||
else
|
else
|
||||||
|
|
|
@ -572,7 +572,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
|
strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
|
||||||
dst_name = resolve_ref(buf.buf, sha1, 0, &flag);
|
dst_name = resolve_ref_unsafe(buf.buf, sha1, 0, &flag);
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
|
|
||||||
if (!(flag & REF_ISSYMREF))
|
if (!(flag & REF_ISSYMREF))
|
||||||
|
|
|
@ -573,7 +573,7 @@ static int read_remote_branches(const char *refname,
|
||||||
strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
|
strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
|
||||||
if (!prefixcmp(refname, buf.buf)) {
|
if (!prefixcmp(refname, buf.buf)) {
|
||||||
item = string_list_append(rename->remote_branches, xstrdup(refname));
|
item = string_list_append(rename->remote_branches, xstrdup(refname));
|
||||||
symref = resolve_ref(refname, orig_sha1, 1, &flag);
|
symref = resolve_ref_unsafe(refname, orig_sha1, 1, &flag);
|
||||||
if (flag & REF_ISSYMREF)
|
if (flag & REF_ISSYMREF)
|
||||||
item->util = xstrdup(symref);
|
item->util = xstrdup(symref);
|
||||||
else
|
else
|
||||||
|
|
|
@ -789,7 +789,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
head_p = resolve_ref("HEAD", head_sha1, 1, NULL);
|
head_p = resolve_ref_unsafe("HEAD", head_sha1, 1, NULL);
|
||||||
if (head_p) {
|
if (head_p) {
|
||||||
head_len = strlen(head_p);
|
head_len = strlen(head_p);
|
||||||
memcpy(head, head_p, head_len + 1);
|
memcpy(head, head_p, head_len + 1);
|
||||||
|
|
|
@ -12,7 +12,7 @@ static void check_symref(const char *HEAD, int quiet)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
int flag;
|
int flag;
|
||||||
const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag);
|
const char *refs_heads_master = resolve_ref_unsafe(HEAD, sha1, 0, &flag);
|
||||||
|
|
||||||
if (!refs_heads_master)
|
if (!refs_heads_master)
|
||||||
die("No such ref: %s", HEAD);
|
die("No such ref: %s", HEAD);
|
||||||
|
|
2
cache.h
2
cache.h
|
@ -865,7 +865,7 @@ extern int read_ref(const char *filename, unsigned char *sha1);
|
||||||
*
|
*
|
||||||
* errno is sometimes set on errors, but not always.
|
* errno is sometimes set on errors, but not always.
|
||||||
*/
|
*/
|
||||||
extern const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag);
|
extern const char *resolve_ref_unsafe(const char *ref, unsigned char *sha1, int reading, int *flag);
|
||||||
extern char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag);
|
extern char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag);
|
||||||
|
|
||||||
extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
|
extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
|
||||||
|
|
22
refs.c
22
refs.c
|
@ -361,7 +361,7 @@ static int warn_if_dangling_symref(const char *refname, const unsigned char *sha
|
||||||
if (!(flags & REF_ISSYMREF))
|
if (!(flags & REF_ISSYMREF))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
resolves_to = resolve_ref(refname, junk, 0, NULL);
|
resolves_to = resolve_ref_unsafe(refname, junk, 0, NULL);
|
||||||
if (!resolves_to || strcmp(resolves_to, d->refname))
|
if (!resolves_to || strcmp(resolves_to, d->refname))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -497,7 +497,7 @@ static int get_packed_ref(const char *ref, unsigned char *sha1)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag)
|
const char *resolve_ref_unsafe(const char *ref, unsigned char *sha1, int reading, int *flag)
|
||||||
{
|
{
|
||||||
int depth = MAXDEPTH;
|
int depth = MAXDEPTH;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
@ -607,7 +607,7 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
|
||||||
|
|
||||||
char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag)
|
char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag)
|
||||||
{
|
{
|
||||||
const char *ret = resolve_ref(ref, sha1, reading, flag);
|
const char *ret = resolve_ref_unsafe(ref, sha1, reading, flag);
|
||||||
return ret ? xstrdup(ret) : NULL;
|
return ret ? xstrdup(ret) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,7 +620,7 @@ struct ref_filter {
|
||||||
|
|
||||||
int read_ref_full(const char *ref, unsigned char *sha1, int reading, int *flags)
|
int read_ref_full(const char *ref, unsigned char *sha1, int reading, int *flags)
|
||||||
{
|
{
|
||||||
if (resolve_ref(ref, sha1, reading, flags))
|
if (resolve_ref_unsafe(ref, sha1, reading, flags))
|
||||||
return 0;
|
return 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1117,7 +1117,7 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
|
||||||
|
|
||||||
this_result = refs_found ? sha1_from_ref : sha1;
|
this_result = refs_found ? sha1_from_ref : sha1;
|
||||||
mksnpath(fullref, sizeof(fullref), *p, len, str);
|
mksnpath(fullref, sizeof(fullref), *p, len, str);
|
||||||
r = resolve_ref(fullref, this_result, 1, &flag);
|
r = resolve_ref_unsafe(fullref, this_result, 1, &flag);
|
||||||
if (r) {
|
if (r) {
|
||||||
if (!refs_found++)
|
if (!refs_found++)
|
||||||
*ref = xstrdup(r);
|
*ref = xstrdup(r);
|
||||||
|
@ -1147,7 +1147,7 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
|
||||||
const char *ref, *it;
|
const char *ref, *it;
|
||||||
|
|
||||||
mksnpath(path, sizeof(path), *p, len, str);
|
mksnpath(path, sizeof(path), *p, len, str);
|
||||||
ref = resolve_ref(path, hash, 1, NULL);
|
ref = resolve_ref_unsafe(path, hash, 1, NULL);
|
||||||
if (!ref)
|
if (!ref)
|
||||||
continue;
|
continue;
|
||||||
if (!stat(git_path("logs/%s", path), &st) &&
|
if (!stat(git_path("logs/%s", path), &st) &&
|
||||||
|
@ -1183,7 +1183,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
|
||||||
lock = xcalloc(1, sizeof(struct ref_lock));
|
lock = xcalloc(1, sizeof(struct ref_lock));
|
||||||
lock->lock_fd = -1;
|
lock->lock_fd = -1;
|
||||||
|
|
||||||
ref = resolve_ref(ref, lock->old_sha1, mustexist, &type);
|
ref = resolve_ref_unsafe(ref, lock->old_sha1, mustexist, &type);
|
||||||
if (!ref && errno == EISDIR) {
|
if (!ref && errno == EISDIR) {
|
||||||
/* we are trying to lock foo but we used to
|
/* we are trying to lock foo but we used to
|
||||||
* have foo/bar which now does not exist;
|
* have foo/bar which now does not exist;
|
||||||
|
@ -1196,7 +1196,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char
|
||||||
error("there are still refs under '%s'", orig_ref);
|
error("there are still refs under '%s'", orig_ref);
|
||||||
goto error_return;
|
goto error_return;
|
||||||
}
|
}
|
||||||
ref = resolve_ref(orig_ref, lock->old_sha1, mustexist, &type);
|
ref = resolve_ref_unsafe(orig_ref, lock->old_sha1, mustexist, &type);
|
||||||
}
|
}
|
||||||
if (type_p)
|
if (type_p)
|
||||||
*type_p = type;
|
*type_p = type;
|
||||||
|
@ -1359,7 +1359,7 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
|
||||||
if (log && S_ISLNK(loginfo.st_mode))
|
if (log && S_ISLNK(loginfo.st_mode))
|
||||||
return error("reflog for %s is a symlink", oldref);
|
return error("reflog for %s is a symlink", oldref);
|
||||||
|
|
||||||
symref = resolve_ref(oldref, orig_sha1, 1, &flag);
|
symref = resolve_ref_unsafe(oldref, orig_sha1, 1, &flag);
|
||||||
if (flag & REF_ISSYMREF)
|
if (flag & REF_ISSYMREF)
|
||||||
return error("refname %s is a symbolic ref, renaming it is not supported",
|
return error("refname %s is a symbolic ref, renaming it is not supported",
|
||||||
oldref);
|
oldref);
|
||||||
|
@ -1648,7 +1648,7 @@ int write_ref_sha1(struct ref_lock *lock,
|
||||||
unsigned char head_sha1[20];
|
unsigned char head_sha1[20];
|
||||||
int head_flag;
|
int head_flag;
|
||||||
const char *head_ref;
|
const char *head_ref;
|
||||||
head_ref = resolve_ref("HEAD", head_sha1, 1, &head_flag);
|
head_ref = resolve_ref_unsafe("HEAD", head_sha1, 1, &head_flag);
|
||||||
if (head_ref && (head_flag & REF_ISSYMREF) &&
|
if (head_ref && (head_flag & REF_ISSYMREF) &&
|
||||||
!strcmp(head_ref, lock->ref_name))
|
!strcmp(head_ref, lock->ref_name))
|
||||||
log_ref_write("HEAD", lock->old_sha1, sha1, logmsg);
|
log_ref_write("HEAD", lock->old_sha1, sha1, logmsg);
|
||||||
|
@ -1985,7 +1985,7 @@ int update_ref(const char *action, const char *refname,
|
||||||
int ref_exists(const char *refname)
|
int ref_exists(const char *refname)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
return !!resolve_ref(refname, sha1, 1, NULL);
|
return !!resolve_ref_unsafe(refname, sha1, 1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ref *find_ref_by_name(const struct ref *list, const char *name)
|
struct ref *find_ref_by_name(const struct ref *list, const char *name)
|
||||||
|
|
6
remote.c
6
remote.c
|
@ -482,7 +482,7 @@ static void read_config(void)
|
||||||
return;
|
return;
|
||||||
default_remote_name = xstrdup("origin");
|
default_remote_name = xstrdup("origin");
|
||||||
current_branch = NULL;
|
current_branch = NULL;
|
||||||
head_ref = resolve_ref("HEAD", sha1, 0, &flag);
|
head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
|
||||||
if (head_ref && (flag & REF_ISSYMREF) &&
|
if (head_ref && (flag & REF_ISSYMREF) &&
|
||||||
!prefixcmp(head_ref, "refs/heads/")) {
|
!prefixcmp(head_ref, "refs/heads/")) {
|
||||||
current_branch =
|
current_branch =
|
||||||
|
@ -1007,7 +1007,7 @@ static char *guess_ref(const char *name, struct ref *peer)
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
|
|
||||||
const char *r = resolve_ref(peer->name, sha1, 1, NULL);
|
const char *r = resolve_ref_unsafe(peer->name, sha1, 1, NULL);
|
||||||
if (!r)
|
if (!r)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1058,7 +1058,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
dst_value = resolve_ref(matched_src->name, sha1, 1, &flag);
|
dst_value = resolve_ref_unsafe(matched_src->name, sha1, 1, &flag);
|
||||||
if (!dst_value ||
|
if (!dst_value ||
|
||||||
((flag & REF_ISSYMREF) &&
|
((flag & REF_ISSYMREF) &&
|
||||||
prefixcmp(dst_value, "refs/heads/")))
|
prefixcmp(dst_value, "refs/heads/")))
|
||||||
|
|
|
@ -163,7 +163,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
|
||||||
/* Follow symbolic refs (mainly for HEAD). */
|
/* Follow symbolic refs (mainly for HEAD). */
|
||||||
localname = ref->peer_ref->name;
|
localname = ref->peer_ref->name;
|
||||||
remotename = ref->name;
|
remotename = ref->name;
|
||||||
tmp = resolve_ref(localname, sha, 1, &flag);
|
tmp = resolve_ref_unsafe(localname, sha, 1, &flag);
|
||||||
if (tmp && flag & REF_ISSYMREF &&
|
if (tmp && flag & REF_ISSYMREF &&
|
||||||
!prefixcmp(tmp, "refs/heads/"))
|
!prefixcmp(tmp, "refs/heads/"))
|
||||||
localname = tmp;
|
localname = tmp;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче