本文整理汇总了C++中resolve_ref函数的典型用法代码示例。如果您正苦于以下问题:C++ resolve_ref函数的具体用法?C++ resolve_ref怎么用?C++ resolve_ref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve_ref函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:dmr0605,项目名称:dmr0605,代码行数:50,代码来源:builtin-branch.c
示例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;
}
开发者ID:zhaoz,项目名称:gidit,代码行数:33,代码来源:gidit.c
示例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;
}
}
开发者ID:AndyA,项目名称:git-andya,代码行数:28,代码来源:builtin-receive-pack.c
示例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);
}
开发者ID:Lisda,项目名称:git,代码行数:33,代码来源:receive-pack.c
示例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;
}
开发者ID:Lisda,项目名称:git,代码行数:58,代码来源:fmt-merge-msg.c
示例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;
}
开发者ID:777,项目名称:test-proj,代码行数:9,代码来源:refs.c
示例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();
}
开发者ID:certik,项目名称:git,代码行数:12,代码来源:wt-status.c
示例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;
}
开发者ID:Lisda,项目名称:git,代码行数:53,代码来源:branch.c
示例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);
}
开发者ID:cesar23,项目名称:dento4,代码行数:13,代码来源:revert.c
示例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);
}
开发者ID:dmr0605,项目名称:dmr0605,代码行数:13,代码来源:builtin-branch.c
示例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);
}
开发者ID:certik,项目名称:git,代码行数:13,代码来源:builtin-receive-pack.c
示例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;
}
开发者ID:a-suenami,项目名称:git,代码行数:14,代码来源:refs.c
示例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";
}
开发者ID:Lisda,项目名称:git,代码行数:50,代码来源:receive-pack.c
示例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);
}
开发者ID:tnachen,项目名称:git,代码行数:48,代码来源:notes.c
示例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;
}
开发者ID:ratnikov,项目名称:git,代码行数:16,代码来源:refs.c
示例16: check_symref
static void check_symref(const char *HEAD, int quiet)
{
unsigned char sha1[20];
int flag;
const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag);
if (!refs_heads_master)
die("No such ref: %s", HEAD);
else if (!(flag & REF_ISSYMREF)) {
if (!quiet)
die("ref %s is not a symbolic ref", HEAD);
else
exit(1);
}
puts(refs_heads_master);
}
开发者ID:julesbowden,项目名称:git,代码行数:16,代码来源:symbolic-ref.c
示例17: do_for_each_reflog
static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data)
{
DIR *dir = opendir(git_path("logs/%s", base));
int retval = 0;
if (dir) {
struct dirent *de;
int baselen = strlen(base);
char *log = xmalloc(baselen + 257);
memcpy(log, base, baselen);
if (baselen && base[baselen-1] != '/')
log[baselen++] = '/';
while ((de = readdir(dir)) != NULL) {
struct stat st;
int namelen;
if (de->d_name[0] == '.')
continue;
namelen = strlen(de->d_name);
if (namelen > 255)
continue;
if (has_extension(de->d_name, ".lock"))
continue;
memcpy(log + baselen, de->d_name, namelen+1);
if (stat(git_path("logs/%s", log), &st) < 0)
continue;
if (S_ISDIR(st.st_mode)) {
retval = do_for_each_reflog(log, fn, cb_data);
} else {
unsigned char sha1[20];
if (!resolve_ref(log, sha1, 0, NULL))
retval = error("bad ref for %s", log);
else
retval = fn(log, sha1, 0, cb_data);
}
if (retval)
break;
}
free(log);
closedir(dir);
}
else if (*base)
return errno;
return retval;
}
开发者ID:ratnikov,项目名称:git,代码行数:47,代码来源:refs.c
示例18: warn_if_dangling_symref
static int warn_if_dangling_symref(const char *refname, const unsigned char *sha1,
int flags, void *cb_data)
{
struct warn_if_dangling_data *d = cb_data;
const char *resolves_to;
unsigned char junk[20];
if (!(flags & REF_ISSYMREF))
return 0;
resolves_to = resolve_ref(refname, junk, 0, NULL);
if (!resolves_to || strcmp(resolves_to, d->refname))
return 0;
fprintf(d->fp, d->msg_fmt, refname);
return 0;
}
开发者ID:ratnikov,项目名称:git,代码行数:17,代码来源:refs.c
示例19: do_head_ref
static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)
{
unsigned char sha1[20];
int flag;
if (submodule) {
if (resolve_gitlink_ref(submodule, "HEAD", sha1) == 0)
return fn("HEAD", sha1, 0, cb_data);
return 0;
}
if (resolve_ref("HEAD", sha1, 1, &flag))
return fn("HEAD", sha1, flag, cb_data);
return 0;
}
开发者ID:ratnikov,项目名称:git,代码行数:17,代码来源:refs.c
示例20: print_summary
static void print_summary(const char *prefix, const unsigned char *sha1)
{
struct rev_info rev;
struct commit *commit;
static const char *format = "format:%h: \"%s\"";
unsigned char junk_sha1[20];
const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
commit = lookup_commit(sha1);
if (!commit)
die("couldn't look up newly created commit");
if (!commit || parse_commit(commit))
die("could not parse newly created commit");
init_revisions(&rev, prefix);
setup_revisions(0, NULL, &rev, NULL);
rev.abbrev = 0;
rev.diff = 1;
rev.diffopt.output_format =
DIFF_FORMAT_SHORTSTAT | DIFF_FORMAT_SUMMARY;
rev.verbose_header = 1;
rev.show_root_diff = 1;
get_commit_format(format, &rev);
rev.always_show_header = 0;
rev.diffopt.detect_rename = 1;
rev.diffopt.rename_limit = 100;
rev.diffopt.break_opt = 0;
diff_setup_done(&rev.diffopt);
printf("[%s%s]: created ",
!prefixcmp(head, "refs/heads/") ?
head + 11 :
!strcmp(head, "HEAD") ?
"detached HEAD" :
head,
initial_commit ? " (root-commit)" : "");
if (!log_tree_commit(&rev, commit)) {
struct strbuf buf = STRBUF_INIT;
format_commit_message(commit, format + 7, &buf, DATE_NORMAL);
printf("%s\n", buf.buf);
strbuf_release(&buf);
}
}
开发者ID:Inkdit,项目名称:git,代码行数:46,代码来源:builtin-commit.c
注:本文中的resolve_ref函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论