本文整理汇总了C++中resolve_ref函数的典型用法代码示例。如果您正苦于以下问题:C++ resolve_ref函数的具体用法?C++ resolve_ref怎么用?C++ resolve_ref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve_ref函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rename_branch
static void rename_branch(const char *oldname, const char *newname, int force)
{
struct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT;
unsigned char sha1[20];
struct strbuf oldsection = STRBUF_INIT, newsection = STRBUF_INIT;
int recovery = 0;
if (!oldname)
die("cannot rename the current branch while not on any.");
if (strbuf_check_branch_ref(&oldref, oldname)) {
/*
* Bad name --- this could be an attempt to rename a
* ref that we used to allow to be created by accident.
*/
if (resolve_ref(oldref.buf, sha1, 1, NULL))
recovery = 1;
else
die("Invalid branch name: '%s'", oldname);
}
if (strbuf_check_branch_ref(&newref, newname))
die("Invalid branch name: '%s'", newname);
if (resolve_ref(newref.buf, sha1, 1, NULL) && !force)
die("A branch named '%s' already exists.", newref.buf + 11);
strbuf_addf(&logmsg, "Branch: renamed %s to %s",
oldref.buf, newref.buf);
if (rename_ref(oldref.buf, newref.buf, logmsg.buf))
die("Branch rename failed");
strbuf_release(&logmsg);
if (recovery)
warning("Renamed a misnamed branch '%s' away", oldref.buf + 11);
/* no need to pass logmsg here as HEAD didn't really move */
if (!strcmp(oldname, head) && create_symref("HEAD", newref.buf, NULL))
die("Branch renamed to %s, but HEAD is not updated!", newname);
strbuf_addf(&oldsection, "branch.%s", oldref.buf + 11);
strbuf_release(&oldref);
strbuf_addf(&newsection, "branch.%s", newref.buf + 11);
strbuf_release(&newref);
if (git_config_rename_section(oldsection.buf, newsection.buf) < 0)
die("Branch is renamed, but update of config-file failed");
strbuf_release(&oldsection);
strbuf_release(&newsection);
}
示例2: gidit_pushobj
int gidit_pushobj(FILE *fp, char * signingkey, int sign, unsigned int flags)
{
const char *head;
unsigned char head_sha1[21];
struct gidit_refs_cb_data cbdata;
struct strbuf buf = STRBUF_INIT;
cbdata.buf = &buf;
cbdata.flags = flags;
head = resolve_ref("HEAD", head_sha1, 0, NULL);
head_sha1[20] = '\0';
if (!head) {
strbuf_release(&buf);
return error("Failed to resolve HEAD as a valid ref.");
}
strbuf_add(&buf, sha1_to_hex(head_sha1), 40);
strbuf_addstr(&buf, " HEAD\n");
for_each_ref(resolve_one_ref, &cbdata);
if (sign)
do_sign(&buf, signingkey);
if (fwrite(buf.buf, buf.len, 1, fp) != 1) {
strbuf_release(&buf);
return error("Error while writing pushobj");
}
strbuf_release(&buf);
return 0;
}
示例3: execute_commands
static void execute_commands(const char *unpacker_error)
{
struct command *cmd = commands;
unsigned char sha1[20];
if (unpacker_error) {
while (cmd) {
cmd->error_string = "n/a (unpacker error)";
cmd = cmd->next;
}
return;
}
if (run_receive_hook(pre_receive_hook)) {
while (cmd) {
cmd->error_string = "pre-receive hook declined";
cmd = cmd->next;
}
return;
}
head_name = resolve_ref("HEAD", sha1, 0, NULL);
while (cmd) {
cmd->error_string = update(cmd);
cmd = cmd->next;
}
}
示例4: execute_commands
static void execute_commands(struct command *commands, const char *unpacker_error)
{
struct command *cmd;
unsigned char sha1[20];
if (unpacker_error) {
for (cmd = commands; cmd; cmd = cmd->next)
cmd->error_string = "n/a (unpacker error)";
return;
}
cmd = commands;
if (check_everything_connected(iterate_receive_command_list,
0, &cmd))
set_connectivity_errors(commands);
if (run_receive_hook(commands, pre_receive_hook, 0)) {
for (cmd = commands; cmd; cmd = cmd->next)
cmd->error_string = "pre-receive hook declined";
return;
}
check_aliased_updates(commands);
free((char*)head_name);
head_name = resolve_ref("HEAD", sha1, 0, NULL);
if (head_name)
head_name = xstrdup(head_name);
for (cmd = commands; cmd; cmd = cmd->next)
if (!cmd->skip_update)
cmd->error_string = update(cmd);
}
示例5: fmt_merge_msg
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
struct fmt_merge_msg_opts *opts)
{
int i = 0, pos = 0;
unsigned char head_sha1[20];
const char *current_branch;
/* get current branch */
current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
if (!current_branch)
die("No current branch");
if (!prefixcmp(current_branch, "refs/heads/"))
current_branch += 11;
current_branch = xstrdup(current_branch);
/* get a line */
while (pos < in->len) {
int len;
char *newline, *p = in->buf + pos;
newline = strchr(p, '\n');
len = newline ? newline - p : strlen(p);
pos += len + !!newline;
i++;
p[len] = 0;
if (handle_line(p))
die ("Error in line %d: %.*s", i, len, p);
}
if (opts->add_title && srcs.nr)
fmt_merge_msg_title(out, current_branch);
if (origins.nr)
fmt_merge_msg_sigs(out);
if (opts->shortlog_len) {
struct commit *head;
struct rev_info rev;
head = lookup_commit_or_die(head_sha1, "HEAD");
init_revisions(&rev, NULL);
rev.commit_format = CMIT_FMT_ONELINE;
rev.ignore_merges = 1;
rev.limited = 1;
if (suffixcmp(out->buf, "\n"))
strbuf_addch(out, '\n');
for (i = 0; i < origins.nr; i++)
shortlog(origins.items[i].string,
origins.items[i].util,
head, &rev, opts->shortlog_len, out);
}
strbuf_complete_line(out);
free((char*)current_branch);
return 0;
}
示例6: head_ref
int head_ref(each_ref_fn fn, void *cb_data)
{
unsigned char sha1[20];
int flag;
if (resolve_ref("HEAD", sha1, 1, &flag))
return fn("HEAD", sha1, flag, cb_data);
return 0;
}
示例7: wt_status_prepare
void wt_status_prepare(struct wt_status *s)
{
unsigned char sha1[20];
const char *head;
memset(s, 0, sizeof(*s));
head = resolve_ref("HEAD", sha1, 0, NULL);
s->branch = head ? xstrdup(head) : NULL;
s->reference = "HEAD";
s->fp = stdout;
s->index_file = get_index_file();
}
示例8: branch_merged
static int branch_merged(int kind, const char *name,
struct commit *rev, struct commit *head_rev)
{
/*
* This checks whether the merge bases of branch and HEAD (or
* the other branch this branch builds upon) contains the
* branch, which means that the branch has already been merged
* safely to HEAD (or the other branch).
*/
struct commit *reference_rev = NULL;
const char *reference_name = NULL;
int merged;
if (kind == REF_LOCAL_BRANCH) {
struct branch *branch = branch_get(name);
unsigned char sha1[20];
if (branch &&
branch->merge &&
branch->merge[0] &&
branch->merge[0]->dst &&
(reference_name =
resolve_ref(branch->merge[0]->dst, sha1, 1, NULL)) != NULL) {
reference_name = xstrdup(reference_name);
reference_rev = lookup_commit_reference(sha1);
}
}
if (!reference_rev)
reference_rev = head_rev;
merged = in_merge_bases(rev, &reference_rev, 1);
/*
* After the safety valve is fully redefined to "check with
* upstream, if any, otherwise with HEAD", we should just
* return the result of the in_merge_bases() above without
* any of the following code, but during the transition period,
* a gentle reminder is in order.
*/
if ((head_rev != reference_rev) &&
in_merge_bases(rev, &head_rev, 1) != merged) {
if (merged)
warning(_("deleting branch '%s' that has been merged to\n"
" '%s', but not yet merged to HEAD."),
name, reference_name);
else
warning(_("not deleting branch '%s' that is not yet merged to\n"
" '%s', even though it is merged to HEAD."),
name, reference_name);
}
free((char*)reference_name);
return merged;
}
示例9: rollback_single_pick
static int rollback_single_pick(void)
{
unsigned char head_sha1[20];
if (!file_exists(git_path("CHERRY_PICK_HEAD")) &&
!file_exists(git_path("REVERT_HEAD")))
return error(_("no cherry-pick or revert in progress"));
if (!resolve_ref("HEAD", head_sha1, 0, NULL))
return error(_("cannot resolve HEAD"));
if (is_null_sha1(head_sha1))
return error(_("cannot abort from a branch yet to be born"));
return reset_for_rollback(head_sha1);
}
示例10: resolve_ref
static char *resolve_symref(const char *src, const char *prefix)
{
unsigned char sha1[20];
int flag;
const char *dst, *cp;
dst = resolve_ref(src, sha1, 0, &flag);
if (!(dst && (flag & REF_ISSYMREF)))
return NULL;
if (prefix && (cp = skip_prefix(dst, prefix)))
dst = cp;
return xstrdup(dst);
}
示例11: is_ref_checked_out
static int is_ref_checked_out(const char *ref)
{
unsigned char sha1[20];
const char *head;
if (is_bare_repository())
return 0;
head = resolve_ref("HEAD", sha1, 0, NULL);
if (!head)
return 0;
return !strcmp(head, ref);
}
示例12: head_ref_namespaced
int head_ref_namespaced(each_ref_fn fn, void *cb_data)
{
struct strbuf buf = STRBUF_INIT;
int ret = 0;
unsigned char sha1[20];
int flag;
strbuf_addf(&buf, "%sHEAD", get_git_namespace());
if (resolve_ref(buf.buf, sha1, 1, &flag))
ret = fn(buf.buf, sha1, flag, cb_data);
strbuf_release(&buf);
return ret;
}
示例13: check_aliased_update
static void check_aliased_update(struct command *cmd, struct string_list *list)
{
struct strbuf buf = STRBUF_INIT;
const char *dst_name;
struct string_list_item *item;
struct command *dst_cmd;
unsigned char sha1[20];
char cmd_oldh[41], cmd_newh[41], dst_oldh[41], dst_newh[41];
int flag;
strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
dst_name = resolve_ref(buf.buf, sha1, 0, &flag);
strbuf_release(&buf);
if (!(flag & REF_ISSYMREF))
return;
dst_name = strip_namespace(dst_name);
if (!dst_name) {
rp_error("refusing update to broken symref '%s'", cmd->ref_name);
cmd->skip_update = 1;
cmd->error_string = "broken symref";
return;
}
if ((item = string_list_lookup(list, dst_name)) == NULL)
return;
cmd->skip_update = 1;
dst_cmd = (struct command *) item->util;
if (!hashcmp(cmd->old_sha1, dst_cmd->old_sha1) &&
!hashcmp(cmd->new_sha1, dst_cmd->new_sha1))
return;
dst_cmd->skip_update = 1;
strcpy(cmd_oldh, find_unique_abbrev(cmd->old_sha1, DEFAULT_ABBREV));
strcpy(cmd_newh, find_unique_abbrev(cmd->new_sha1, DEFAULT_ABBREV));
strcpy(dst_oldh, find_unique_abbrev(dst_cmd->old_sha1, DEFAULT_ABBREV));
strcpy(dst_newh, find_unique_abbrev(dst_cmd->new_sha1, DEFAULT_ABBREV));
rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
" its target '%s' (%s..%s)",
cmd->ref_name, cmd_oldh, cmd_newh,
dst_cmd->ref_name, dst_oldh, dst_newh);
cmd->error_string = dst_cmd->error_string =
"inconsistent aliased update";
}
示例14: merge_commit
static int merge_commit(struct notes_merge_options *o)
{
struct strbuf msg = STRBUF_INIT;
unsigned char sha1[20], parent_sha1[20];
struct notes_tree *t;
struct commit *partial;
struct pretty_print_context pretty_ctx;
/*
* Read partial merge result from .git/NOTES_MERGE_PARTIAL,
* and target notes ref from .git/NOTES_MERGE_REF.
*/
if (get_sha1("NOTES_MERGE_PARTIAL", sha1))
die("Failed to read ref NOTES_MERGE_PARTIAL");
else if (!(partial = lookup_commit_reference(sha1)))
die("Could not find commit from NOTES_MERGE_PARTIAL.");
else if (parse_commit(partial))
die("Could not parse commit from NOTES_MERGE_PARTIAL.");
if (partial->parents)
hashcpy(parent_sha1, partial->parents->item->object.sha1);
else
hashclr(parent_sha1);
t = xcalloc(1, sizeof(struct notes_tree));
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
o->local_ref = resolve_ref("NOTES_MERGE_REF", sha1, 0, NULL);
if (!o->local_ref)
die("Failed to resolve NOTES_MERGE_REF");
if (notes_merge_commit(o, t, partial, sha1))
die("Failed to finalize notes merge");
/* Reuse existing commit message in reflog message */
memset(&pretty_ctx, 0, sizeof(pretty_ctx));
format_commit_message(partial, "%s", &msg, &pretty_ctx);
strbuf_trim(&msg);
strbuf_insert(&msg, 0, "notes: ", 7);
update_ref(msg.buf, o->local_ref, sha1,
is_null_sha1(parent_sha1) ? NULL : parent_sha1,
0, DIE_ON_ERR);
free_notes(t);
strbuf_release(&msg);
return merge_abort(o);
}
示例15:
static struct ref_lock *verify_lock(struct ref_lock *lock,
const unsigned char *old_sha1, int mustexist)
{
if (!resolve_ref(lock->ref_name, lock->old_sha1, mustexist, NULL)) {
error("Can't verify ref %s", lock->ref_name);
unlock_ref(lock);
return NULL;
}
if (hashcmp(lock->old_sha1, old_sha1)) {
error("Ref %s is at %s but expected %s", lock->ref_name,
sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));
unlock_ref(lock);
return NULL;
}
return lock;
}