本文整理汇总了C++中dwim_ref函数的典型用法代码示例。如果您正苦于以下问题:C++ dwim_ref函数的具体用法?C++ dwim_ref怎么用?C++ dwim_ref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dwim_ref函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xstrdup
static char *find_branch_name(struct rev_info *rev)
{
int i, positive = -1;
struct object_id branch_oid;
const struct object_id *tip_oid;
const char *ref, *v;
char *full_ref, *branch = NULL;
for (i = 0; i < rev->cmdline.nr; i++) {
if (rev->cmdline.rev[i].flags & UNINTERESTING)
continue;
if (positive < 0)
positive = i;
else
return NULL;
}
if (positive < 0)
return NULL;
ref = rev->cmdline.rev[positive].name;
tip_oid = &rev->cmdline.rev[positive].item->oid;
if (dwim_ref(ref, strlen(ref), branch_oid.hash, &full_ref) &&
skip_prefix(full_ref, "refs/heads/", &v) &&
!oidcmp(tip_oid, &branch_oid))
branch = xstrdup(v);
free(full_ref);
return branch;
}
示例2: wt_status_get_detached_from
static void wt_status_get_detached_from(struct wt_status_state *state)
{
struct grab_1st_switch_cbdata cb;
struct commit *commit;
unsigned char sha1[20];
char *ref = NULL;
strbuf_init(&cb.buf, 0);
if (for_each_reflog_ent_reverse("HEAD", grab_1st_switch, &cb) <= 0) {
strbuf_release(&cb.buf);
return;
}
if (dwim_ref(cb.buf.buf, cb.buf.len, sha1, &ref) == 1 &&
/* sha1 is a commit? match without further lookup */
(!hashcmp(cb.nsha1, sha1) ||
/* perhaps sha1 is a tag, try to dereference to a commit */
((commit = lookup_commit_reference_gently(sha1, 1)) != NULL &&
!hashcmp(cb.nsha1, commit->object.sha1)))) {
int ofs;
if (!prefixcmp(ref, "refs/tags/"))
ofs = strlen("refs/tags/");
else if (!prefixcmp(ref, "refs/remotes/"))
ofs = strlen("refs/remotes/");
else
ofs = 0;
state->detached_from = xstrdup(ref + ofs);
} else
state->detached_from =
xstrdup(find_unique_abbrev(cb.nsha1, DEFAULT_ABBREV));
hashcpy(state->detached_sha1, cb.nsha1);
free(ref);
strbuf_release(&cb.buf);
}
示例3: handle_fork_point
static int handle_fork_point(int argc, const char **argv)
{
struct object_id oid;
char *refname;
struct commit *derived, *fork_point;
const char *commitname;
switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) {
case 0:
die("No such ref: '%s'", argv[0]);
case 1:
break; /* good */
default:
die("Ambiguous refname: '%s'", argv[0]);
}
commitname = (argc == 2) ? argv[1] : "HEAD";
if (get_oid(commitname, &oid))
die("Not a valid object name: '%s'", commitname);
derived = lookup_commit_reference(the_repository, &oid);
fork_point = get_fork_point(refname, derived);
if (!fork_point)
return 1;
printf("%s\n", oid_to_hex(&fork_point->object.oid));
return 0;
}
示例4: xstrdup
static char *find_branch_name(struct rev_info *rev)
{
int i, positive = -1;
unsigned char branch_sha1[20];
const unsigned char *tip_sha1;
const char *ref, *v;
char *full_ref, *branch = NULL;
for (i = 0; i < rev->cmdline.nr; i++) {
if (rev->cmdline.rev[i].flags & UNINTERESTING)
continue;
if (positive < 0)
positive = i;
else
return NULL;
}
if (positive < 0)
return NULL;
ref = rev->cmdline.rev[positive].name;
tip_sha1 = rev->cmdline.rev[positive].item->sha1;
if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) &&
skip_prefix(full_ref, "refs/heads/", &v) &&
!hashcmp(tip_sha1, branch_sha1))
branch = xstrdup(v);
free(full_ref);
return branch;
}
示例5: handle_fork_point
static int handle_fork_point(int argc, const char **argv)
{
unsigned char sha1[20];
char *refname;
const char *commitname;
struct rev_collect revs;
struct commit *derived;
struct commit_list *bases;
int i, ret = 0;
switch (dwim_ref(argv[0], strlen(argv[0]), sha1, &refname)) {
case 0:
die("No such ref: '%s'", argv[0]);
case 1:
break; /* good */
default:
die("Ambiguous refname: '%s'", argv[0]);
}
commitname = (argc == 2) ? argv[1] : "HEAD";
if (get_sha1(commitname, sha1))
die("Not a valid object name: '%s'", commitname);
derived = lookup_commit_reference(sha1);
memset(&revs, 0, sizeof(revs));
revs.initial = 1;
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
for (i = 0; i < revs.nr; i++)
revs.commit[i]->object.flags &= ~TMP_MARK;
bases = get_merge_bases_many_dirty(derived, revs.nr, revs.commit);
/*
* There should be one and only one merge base, when we found
* a common ancestor among reflog entries.
*/
if (!bases || bases->next) {
ret = 1;
goto cleanup_return;
}
/* And the found one must be one of the reflog entries */
for (i = 0; i < revs.nr; i++)
if (&bases->item->object == &revs.commit[i]->object)
break; /* found */
if (revs.nr <= i) {
ret = 1; /* not found */
goto cleanup_return;
}
printf("%s\n", oid_to_hex(&bases->item->object.oid));
cleanup_return:
free_commit_list(bases);
return ret;
}
示例6: parse_treeish_arg
static void parse_treeish_arg(const char **argv,
struct archiver_args *ar_args, const char *prefix,
int remote)
{
const char *name = argv[0];
const unsigned char *commit_sha1;
time_t archive_time;
struct tree *tree;
const struct commit *commit;
struct object_id oid;
/* Remotes are only allowed to fetch actual refs */
if (remote && !remote_allow_unreachable) {
char *ref = NULL;
const char *colon = strchrnul(name, ':');
int refnamelen = colon - name;
if (!dwim_ref(name, refnamelen, &oid, &ref))
die(_("no such ref: %.*s"), refnamelen, name);
free(ref);
}
if (get_oid(name, &oid))
die(_("not a valid object name: %s"), name);
commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
if (commit) {
commit_sha1 = commit->object.oid.hash;
archive_time = commit->date;
} else {
commit_sha1 = NULL;
archive_time = time(NULL);
}
tree = parse_tree_indirect(&oid);
if (tree == NULL)
die(_("not a tree object: %s"), oid_to_hex(&oid));
if (prefix) {
struct object_id tree_oid;
unsigned int mode;
int err;
err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,
&mode);
if (err || !S_ISDIR(mode))
die(_("current working directory is untracked"));
tree = parse_tree_indirect(&tree_oid);
}
ar_args->tree = tree;
ar_args->commit_sha1 = commit_sha1;
ar_args->commit = commit;
ar_args->time = archive_time;
}
示例7: parse_treeish_arg
static void parse_treeish_arg(const char **argv,
struct archiver_args *ar_args, const char *prefix,
int remote)
{
const char *name = argv[0];
const unsigned char *commit_sha1;
time_t archive_time;
struct tree *tree;
const struct commit *commit;
unsigned char sha1[20];
/* Remotes are only allowed to fetch actual refs */
if (remote && !remote_allow_unreachable) {
char *ref = NULL;
const char *colon = strchr(name, ':');
int refnamelen = colon ? colon - name : strlen(name);
if (!dwim_ref(name, refnamelen, sha1, &ref))
die("no such ref: %.*s", refnamelen, name);
free(ref);
}
if (get_sha1(name, sha1))
die("Not a valid object name");
commit = lookup_commit_reference_gently(sha1, 1);
if (commit) {
commit_sha1 = commit->object.sha1;
archive_time = commit->date;
} else {
commit_sha1 = NULL;
archive_time = time(NULL);
}
tree = parse_tree_indirect(sha1);
if (tree == NULL)
die("not a tree object");
if (prefix) {
unsigned char tree_sha1[20];
unsigned int mode;
int err;
err = get_tree_entry(tree->object.sha1, prefix,
tree_sha1, &mode);
if (err || !S_ISDIR(mode))
die("current working directory is untracked");
tree = parse_tree_indirect(tree_sha1);
}
ar_args->tree = tree;
ar_args->commit_sha1 = commit_sha1;
ar_args->commit = commit;
ar_args->time = archive_time;
}
示例8: write_refs_to_temp_dir
static int write_refs_to_temp_dir(struct strbuf *temp_dir,
int refspec_nr, const char **refspec)
{
int i;
for (i = 0; i < refspec_nr; i++) {
unsigned char sha1[20];
char *ref;
if (dwim_ref(refspec[i], strlen(refspec[i]), sha1, &ref) != 1)
return error("Could not get ref %s", refspec[i]);
if (write_one_ref(ref, sha1, 0, temp_dir)) {
free(ref);
return -1;
}
free(ref);
}
return 0;
}
示例9: write_refs_to_temp_dir
static int write_refs_to_temp_dir(struct strbuf *temp_dir,
int refspec_nr, const char **refspec)
{
int i;
for (i = 0; i < refspec_nr; i++) {
struct object_id oid;
char *ref;
if (dwim_ref(refspec[i], strlen(refspec[i]), oid.hash, &ref) != 1)
return error("Could not get ref %s", refspec[i]);
if (write_one_ref(ref, &oid, 0, temp_dir)) {
free(ref);
return -1;
}
free(ref);
}
return 0;
}
示例10: show_rev
/* Output a revision, only if filter allows it */
static void show_rev(int type, const unsigned char *sha1, const char *name)
{
if (!(filter & DO_REVS))
return;
def = NULL;
if ((symbolic || abbrev_ref) && name) {
if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) {
unsigned char discard[20];
char *full;
switch (dwim_ref(name, strlen(name), discard, &full)) {
case 0:
/*
* Not found -- not a ref. We could
* emit "name" here, but symbolic-full
* users are interested in finding the
* refs spelled in full, and they would
* need to filter non-refs if we did so.
*/
break;
case 1: /* happy */
if (abbrev_ref)
full = shorten_unambiguous_ref(full,
abbrev_ref_strict);
show_with_type(type, full);
break;
default: /* ambiguous */
error("refname '%s' is ambiguous", name);
break;
}
free(full);
} else {
show_with_type(type, name);
}
}
else if (abbrev)
show_with_type(type, find_unique_abbrev(sha1, abbrev));
else
show_with_type(type, sha1_to_hex(sha1));
}
示例11: if
static char *find_branch_name(struct rev_info *rev)
{
int i, positive = -1;
unsigned char branch_sha1[20];
const unsigned char *tip_sha1;
const char *ref;
char *full_ref, *branch = NULL;
for (i = 0; i < rev->cmdline.nr; i++) {
if (rev->cmdline.rev[i].flags & UNINTERESTING)
continue;
if (positive < 0)
positive = i;
else
return NULL;
}
if (0 <= positive) {
ref = rev->cmdline.rev[positive].name;
tip_sha1 = rev->cmdline.rev[positive].item->sha1;
} else if (!rev->cmdline.nr && rev->pending.nr == 1 &&
!strcmp(rev->pending.objects[0].name, "HEAD")) {
/*
* No actual ref from command line, but "HEAD" from
* rev->def was added in setup_revisions()
* e.g. format-patch --cover-letter -12
*/
ref = "HEAD";
tip_sha1 = rev->pending.objects[0].item->sha1;
} else {
return NULL;
}
if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) &&
!prefixcmp(full_ref, "refs/heads/") &&
!hashcmp(tip_sha1, branch_sha1))
branch = xstrdup(full_ref + strlen("refs/heads/"));
free(full_ref);
return branch;
}
示例12: get_tags_and_duplicates
static void get_tags_and_duplicates(struct rev_cmdline_info *info)
{
int i;
for (i = 0; i < info->nr; i++) {
struct rev_cmdline_entry *e = info->rev + i;
struct object_id oid;
struct commit *commit;
char *full_name;
if (e->flags & UNINTERESTING)
continue;
if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1)
continue;
if (refspecs.nr) {
char *private;
private = apply_refspecs(&refspecs, full_name);
if (private) {
free(full_name);
full_name = private;
}
}
示例13: create_bundle
int create_bundle(struct bundle_header *header, const char *path,
int argc, const char **argv)
{
static struct lock_file lock;
int bundle_fd = -1;
int bundle_to_stdout;
const char **argv_boundary = xmalloc((argc + 4) * sizeof(const char *));
const char **argv_pack = xmalloc(6 * sizeof(const char *));
int i, ref_count = 0;
struct strbuf buf = STRBUF_INIT;
struct rev_info revs;
struct child_process rls;
FILE *rls_fout;
bundle_to_stdout = !strcmp(path, "-");
if (bundle_to_stdout)
bundle_fd = 1;
else
bundle_fd = hold_lock_file_for_update(&lock, path,
LOCK_DIE_ON_ERROR);
/* write signature */
write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
/* init revs to list objects for pack-objects later */
save_commit_buffer = 0;
init_revisions(&revs, NULL);
/* write prerequisites */
memcpy(argv_boundary + 3, argv + 1, argc * sizeof(const char *));
argv_boundary[0] = "rev-list";
argv_boundary[1] = "--boundary";
argv_boundary[2] = "--pretty=oneline";
argv_boundary[argc + 2] = NULL;
memset(&rls, 0, sizeof(rls));
rls.argv = argv_boundary;
rls.out = -1;
rls.git_cmd = 1;
if (start_command(&rls))
return -1;
rls_fout = xfdopen(rls.out, "r");
while (strbuf_getwholeline(&buf, rls_fout, '\n') != EOF) {
unsigned char sha1[20];
if (buf.len > 0 && buf.buf[0] == '-') {
write_or_die(bundle_fd, buf.buf, buf.len);
if (!get_sha1_hex(buf.buf + 1, sha1)) {
struct object *object = parse_object(sha1);
object->flags |= UNINTERESTING;
add_pending_object(&revs, object, xstrdup(buf.buf));
}
} else if (!get_sha1_hex(buf.buf, sha1)) {
struct object *object = parse_object(sha1);
object->flags |= SHOWN;
}
}
strbuf_release(&buf);
fclose(rls_fout);
if (finish_command(&rls))
return error("rev-list died");
/* write references */
argc = setup_revisions(argc, argv, &revs, NULL);
if (argc > 1)
return error("unrecognized argument: %s", argv[1]);
object_array_remove_duplicates(&revs.pending);
for (i = 0; i < revs.pending.nr; i++) {
struct object_array_entry *e = revs.pending.objects + i;
unsigned char sha1[20];
char *ref;
const char *display_ref;
int flag;
if (e->item->flags & UNINTERESTING)
continue;
if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
continue;
if (read_ref_full(e->name, sha1, 1, &flag))
flag = 0;
display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
if (e->item->type == OBJ_TAG &&
!is_tag_in_date_range(e->item, &revs)) {
e->item->flags |= UNINTERESTING;
continue;
}
/*
* Make sure the refs we wrote out is correct; --max-count and
* other limiting options could have prevented all the tips
* from getting output.
*
* Non commit objects such as tags and blobs do not have
* this issue as they are not affected by those extra
* constraints.
*/
if (!(e->item->flags & SHOWN) && e->item->type == OBJ_COMMIT) {
warning("ref '%s' is excluded by the rev-list options",
//.........这里部分代码省略.........
示例14: merge_name
/* Get the name for the merge commit's message. */
static void merge_name(const char *remote, struct strbuf *msg)
{
struct commit *remote_head;
unsigned char branch_head[20];
struct strbuf buf = STRBUF_INIT;
struct strbuf bname = STRBUF_INIT;
const char *ptr;
char *found_ref;
int len, early;
strbuf_branchname(&bname, remote);
remote = bname.buf;
memset(branch_head, 0, sizeof(branch_head));
remote_head = get_merge_parent(remote);
if (!remote_head)
die(_("'%s' does not point to a commit"), remote);
if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) {
if (!prefixcmp(found_ref, "refs/heads/")) {
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
sha1_to_hex(branch_head), remote);
goto cleanup;
}
if (!prefixcmp(found_ref, "refs/tags/")) {
strbuf_addf(msg, "%s\t\ttag '%s' of .\n",
sha1_to_hex(branch_head), remote);
goto cleanup;
}
if (!prefixcmp(found_ref, "refs/remotes/")) {
strbuf_addf(msg, "%s\t\tremote-tracking branch '%s' of .\n",
sha1_to_hex(branch_head), remote);
goto cleanup;
}
}
/* See if remote matches <name>^^^.. or <name>~<number> */
for (len = 0, ptr = remote + strlen(remote);
remote < ptr && ptr[-1] == '^';
ptr--)
len++;
if (len)
early = 1;
else {
early = 0;
ptr = strrchr(remote, '~');
if (ptr) {
int seen_nonzero = 0;
len++; /* count ~ */
while (*++ptr && isdigit(*ptr)) {
seen_nonzero |= (*ptr != '0');
len++;
}
if (*ptr)
len = 0; /* not ...~<number> */
else if (seen_nonzero)
early = 1;
else if (len == 1)
early = 1; /* "name~" is "name~1"! */
}
}
if (len) {
struct strbuf truname = STRBUF_INIT;
strbuf_addstr(&truname, "refs/heads/");
strbuf_addstr(&truname, remote);
strbuf_setlen(&truname, truname.len - len);
if (ref_exists(truname.buf)) {
strbuf_addf(msg,
"%s\t\tbranch '%s'%s of .\n",
sha1_to_hex(remote_head->object.sha1),
truname.buf + 11,
(early ? " (early part)" : ""));
strbuf_release(&truname);
goto cleanup;
}
}
if (!strcmp(remote, "FETCH_HEAD") &&
!access(git_path("FETCH_HEAD"), R_OK)) {
const char *filename;
FILE *fp;
struct strbuf line = STRBUF_INIT;
char *ptr;
filename = git_path("FETCH_HEAD");
fp = fopen(filename, "r");
if (!fp)
die_errno(_("could not open '%s' for reading"),
filename);
strbuf_getline(&line, fp, '\n');
fclose(fp);
ptr = strstr(line.buf, "\tnot-for-merge\t");
if (ptr)
strbuf_remove(&line, ptr-line.buf+1, 13);
strbuf_addbuf(msg, &line);
strbuf_release(&line);
goto cleanup;
}
//.........这里部分代码省略.........
示例15: get_sha1_basic
static int get_sha1_basic(const char *str, int len, unsigned char *sha1, int warn_ambiguous_refs)
{
static const char *warn_msg = "refname '%.*s' is ambiguous.";
char *real_ref = NULL;
int refs_found = 0;
int at = 0, reflog_len = 0;
int get_sha1_hex_val = 0;
get_sha1_hex_val = get_sha1_hex(str, sha1);
if (len >= 40 && get_sha1_hex_val >= 0)
return 0;
/* [email protected]{time or number or -number} format to query ref-log */
if (len > 0 && select(str,len-1) >= '}') {
for (at = len - 2; at >= 0; at--) {
if (select(str,at) >= '@' && select(str,at+1) >= '{') {
if (upstream_mark(str + at, len - at) > 0) {
reflog_len = (len-1) - (at+2);
len = at;
}
break;
}
}
}
// Accept only unambiguous ref paths.
if (len > 0 && ambiguous_path(str, len) > 0)
return -1;
if (len <= 0 && reflog_len > 0) {
struct strbuf buf = STRBUF_INIT;
int ret = 0;
// try the @{-N} syntax for n-th checkout
ret = interpret_branch_name(str+at, &buf);
if (ret > 0) {
// substitute this branch name and restart
return get_sha1_1(buf.buf, buf.len, sha1, 0);
} else if (ret >= 0) {
return -1;
}
// allow "@{...}" to mean the current branch reflog
refs_found = dwim_ref("HEAD", 4, sha1, &real_ref);
}
else if (reflog_len > 0)
refs_found = dwim_log(str, len, sha1, &real_ref);
else
refs_found = dwim_ref(str, len, sha1, &real_ref);
if (refs_found <= 0)
return -1;
if (warn_ambiguous_refs > 0 && refs_found > 1)
warning(warn_msg, len, str);
if (reflog_len > 0) {
int nth = 0, i = 0;
unsigned long at_time = 0;
unsigned long co_time = 0;
int co_tz = 0, co_cnt = 0;
// a @{-N} placed anywhere except the start is an error
if (select(str,at+2) >= '-')
return -1;
// // Is it asking for N-th entry, or approxidate?
for (; 0 <= nth && i < reflog_len; i++) {
char ch = 0;
ch = select(str,at+2+i);
if ('0' <= ch && ch <= '9')
nth = nth * 10 + ch - '0';
else
nth = -1;
}
if (100000000 <= nth) {
at_time = nth;
nth = -1;
} else if (0 <= nth)
at_time = 0;
else {
int errors = 0;
char *tmp = xstrndup(str + at + 2, reflog_len);
at_time = approxidate_careful(tmp, &errors);
free(tmp);
if (errors)
return -1;
}
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
&co_time, &co_tz, &co_cnt) > 0) {
if (at_time > 0)
warning("Log for '%.*s' only goes "
"back to %s.", len, str,
show_date(co_time, co_tz, DATE_RFC2822));
else {
free(real_ref);
die("Log for '%.*s' only has %d entries.",
len, str, co_cnt);
}
}
}
//.........这里部分代码省略.........