本文整理汇总了C++中deref_tag函数的典型用法代码示例。如果您正苦于以下问题:C++ deref_tag函数的具体用法?C++ deref_tag怎么用?C++ deref_tag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了deref_tag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: grep_objects
static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
const struct object_array *list)
{
unsigned int i;
int hit = 0;
const unsigned int nr = list->nr;
for (i = 0; i < nr; i++) {
struct object *real_obj;
real_obj = deref_tag(list->objects[i].item, NULL, 0);
if (grep_object(opt, pathspec, real_obj, list->objects[i].name)) {
hit = 1;
if (opt->status_only)
break;
}
}
return hit;
}
示例2: die
static struct commit *get_ref(const char *ref)
{
unsigned char sha1[20];
struct object *object;
if (get_sha1(ref, sha1))
die("Could not resolve ref '%s'", ref);
object = deref_tag(parse_object(sha1), ref, strlen(ref));
if (!object)
return NULL;
if (object->type == OBJ_TREE)
return make_virtual_commit((struct tree*)object,
better_branch_name(ref));
if (object->type != OBJ_COMMIT)
return NULL;
if (parse_commit((struct commit *)object))
die("Could not parse commit '%s'", sha1_to_hex(object->sha1));
return (struct commit *)object;
}
示例3: git_deref_tag
int git_deref_tag(const unsigned char *tagsha1, GIT_HASH refhash)
{
struct object *obj = NULL;
obj = parse_object(tagsha1);
if (!obj)
return -1;
if (obj->type == OBJ_TAG)
{
obj = deref_tag(obj, "", 0);
if (!obj)
return -1;
memcpy(refhash, obj->sha1, sizeof(GIT_HASH));
return 0;
}
return -1;
}
示例4: add_info_ref
static int add_info_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
{
FILE *fp = cb_data;
struct object *o = parse_object(sha1);
if (!o)
return -1;
if (fprintf(fp, "%s %s\n", sha1_to_hex(sha1), path) < 0)
return -1;
if (o->type == OBJ_TAG) {
o = deref_tag(o, path, 0);
if (o)
if (fprintf(fp, "%s %s^{}\n",
sha1_to_hex(o->sha1), path) < 0)
return -1;
}
return 0;
}
示例5: show_text_ref
static int show_text_ref(const char *name, const unsigned char *sha1,
int flag, void *cb_data)
{
const char *name_nons = strip_namespace(name);
struct strbuf *buf = cb_data;
struct object *o = parse_object(sha1);
if (!o)
return 0;
strbuf_addf(buf, "%s\t%s\n", sha1_to_hex(sha1), name_nons);
if (o->type == OBJ_TAG) {
o = deref_tag(o, name, 0);
if (!o)
return 0;
strbuf_addf(buf, "%s\t%s^{}\n", sha1_to_hex(o->sha1),
name_nons);
}
return 0;
}
示例6: show_text_ref
static int show_text_ref(const char *name, const struct object_id *oid,
int flag, void *cb_data)
{
const char *name_nons = strip_namespace(name);
struct strbuf *buf = cb_data;
struct object *o = parse_object(oid->hash);
if (!o)
return 0;
strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons);
if (o->type == OBJ_TAG) {
o = deref_tag(o, name, 0);
if (!o)
return 0;
strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid),
name_nons);
}
return 0;
}
示例7: add_info_ref
static int add_info_ref(const char *path, const struct object_id *oid,
int flag, void *cb_data)
{
FILE *fp = cb_data;
struct object *o = parse_object(oid->hash);
if (!o)
return -1;
if (fprintf(fp, "%s %s\n", oid_to_hex(oid), path) < 0)
return -1;
if (o->type == OBJ_TAG) {
o = deref_tag(o, path, 0);
if (o)
if (fprintf(fp, "%s %s^{}\n",
oid_to_hex(&o->oid), path) < 0)
return -1;
}
return 0;
}
示例8: add_remote_info_ref
static void add_remote_info_ref(struct remote_ls_ctx *ls)
{
struct strbuf *buf = (struct strbuf *)ls->userData;
struct object *o;
struct ref *ref;
ref = alloc_ref(ls->dentry_name);
if (http_fetch_ref(repo->url, ref) != 0) {
fprintf(stderr,
"Unable to fetch ref %s from %s\n",
ls->dentry_name, repo->url);
aborted = 1;
free(ref);
return;
}
o = parse_object(&ref->old_oid);
if (!o) {
fprintf(stderr,
"Unable to parse object %s for remote ref %s\n",
oid_to_hex(&ref->old_oid), ls->dentry_name);
aborted = 1;
free(ref);
return;
}
strbuf_addf(buf, "%s\t%s\n",
oid_to_hex(&ref->old_oid), ls->dentry_name);
if (o->type == OBJ_TAG) {
o = deref_tag(o, ls->dentry_name, 0);
if (o)
strbuf_addf(buf, "%s\t%s^{}\n",
oid_to_hex(&o->oid), ls->dentry_name);
}
free(ref);
}
示例9: handle_one_ref
static int handle_one_ref(const char *path, const unsigned char *sha1,
int flags, void *cb_data)
{
struct pack_refs_cb_data *cb = cb_data;
int is_tag_ref;
/* Do not pack the symbolic refs */
if ((flags & REF_ISSYMREF))
return 0;
is_tag_ref = !prefixcmp(path, "refs/tags/");
/* ALWAYS pack refs that were already packed or are tags */
if (!(cb->flags & PACK_REFS_ALL) && !is_tag_ref && !(flags & REF_ISPACKED))
return 0;
fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(sha1), path);
if (is_tag_ref) {
struct object *o = parse_object(sha1);
if (o->type == OBJ_TAG) {
o = deref_tag(o, path, 0);
if (o)
fprintf(cb->refs_file, "^%s\n",
sha1_to_hex(o->sha1));
}
}
if ((cb->flags & PACK_REFS_PRUNE) && !do_not_prune(flags)) {
int namelen = strlen(path) + 1;
struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen);
hashcpy(n->sha1, sha1);
strcpy(n->name, path);
n->next = cb->ref_to_prune;
cb->ref_to_prune = n;
}
return 0;
}
示例10: deref_tag
static struct commit *dwim_reverse_initial(struct rev_info *revs,
const char **name_p)
{
/*
* DWIM "git blame --reverse ONE -- PATH" as
* "git blame --reverse ONE..HEAD -- PATH" but only do so
* when it makes sense.
*/
struct object *obj;
struct commit *head_commit;
struct object_id head_oid;
if (revs->pending.nr != 1)
return NULL;
/* Is that sole rev a committish? */
obj = revs->pending.objects[0].item;
obj = deref_tag(obj, NULL, 0);
if (obj->type != OBJ_COMMIT)
return NULL;
/* Do we have HEAD? */
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
return NULL;
head_commit = lookup_commit_reference_gently(&head_oid, 1);
if (!head_commit)
return NULL;
/* Turn "ONE" into "ONE..HEAD" then */
obj->flags |= UNINTERESTING;
add_pending_object(revs, &head_commit->object, "HEAD");
if (name_p)
*name_p = revs->pending.objects[0].name;
return (struct commit *)obj;
}
示例11: cmd_grep
//.........这里部分代码省略.........
append_grep_pattern(&opt, argv[0], "command line", 0,
GREP_PATTERN);
argv++;
argc--;
}
if (!opt.pattern_list)
die("no pattern given.");
if (!opt.fixed && opt.ignore_case)
opt.regflags |= REG_ICASE;
if ((opt.regflags != REG_NEWLINE) && opt.fixed)
die("cannot mix --fixed-strings and regexp");
#ifndef NO_PTHREADS
if (online_cpus() == 1 || !grep_threads_ok(&opt))
use_threads = 0;
if (use_threads)
start_threads(&opt);
#else
use_threads = 0;
#endif
compile_grep_patterns(&opt);
/* Check revs and then paths */
for (i = 0; i < argc; i++) {
const char *arg = argv[i];
unsigned char sha1[20];
/* Is it a rev? */
if (!get_sha1(arg, sha1)) {
struct object *object = parse_object(sha1);
if (!object)
die("bad object %s", arg);
add_object_array(object, arg, &list);
continue;
}
if (!strcmp(arg, "--")) {
i++;
seen_dashdash = 1;
}
break;
}
/* The rest are paths */
if (!seen_dashdash) {
int j;
for (j = i; j < argc; j++)
verify_filename(prefix, argv[j]);
}
if (i < argc)
paths = get_pathspec(prefix, argv + i);
else if (prefix) {
paths = xcalloc(2, sizeof(const char *));
paths[0] = prefix;
paths[1] = NULL;
}
if (!use_index) {
int hit;
if (cached)
die("--cached cannot be used with --no-index.");
if (list.nr)
die("--no-index cannot be used with revs.");
hit = grep_directory(&opt, paths);
if (use_threads)
hit |= wait_all();
return !hit;
}
if (!list.nr) {
int hit;
if (!cached)
setup_work_tree();
hit = grep_cache(&opt, paths, cached);
if (use_threads)
hit |= wait_all();
return !hit;
}
if (cached)
die("both --cached and trees are given.");
for (i = 0; i < list.nr; i++) {
struct object *real_obj;
real_obj = deref_tag(list.objects[i].item, NULL, 0);
if (grep_object(&opt, paths, real_obj, list.objects[i].name)) {
hit = 1;
if (opt.status_only)
break;
}
}
if (use_threads)
hit |= wait_all();
free_grep_patterns(&opt);
return !hit;
}
示例12: shortlog
static void shortlog(const char *name,
struct origin_data *origin_data,
struct commit *head,
struct rev_info *rev, int limit,
struct strbuf *out)
{
int i, count = 0;
struct commit *commit;
struct object *branch;
struct string_list subjects = STRING_LIST_INIT_DUP;
struct string_list authors = STRING_LIST_INIT_DUP;
struct string_list committers = STRING_LIST_INIT_DUP;
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
struct strbuf sb = STRBUF_INIT;
const unsigned char *sha1 = origin_data->sha1;
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
if (!branch || branch->type != OBJ_COMMIT)
return;
setup_revisions(0, NULL, rev, NULL);
add_pending_object(rev, branch, name);
add_pending_object(rev, &head->object, "^HEAD");
head->object.flags |= UNINTERESTING;
if (prepare_revision_walk(rev))
die("revision walk setup failed");
while ((commit = get_revision(rev)) != NULL) {
struct pretty_print_context ctx = {0};
if (commit->parents && commit->parents->next) {
/* do not list a merge but count committer */
record_person('c', &committers, commit);
continue;
}
if (!count)
/* the 'tip' committer */
record_person('c', &committers, commit);
record_person('a', &authors, commit);
count++;
if (subjects.nr > limit)
continue;
format_commit_message(commit, "%s", &sb, &ctx);
strbuf_ltrim(&sb);
if (!sb.len)
string_list_append(&subjects,
sha1_to_hex(commit->object.sha1));
else
string_list_append(&subjects, strbuf_detach(&sb, NULL));
}
add_people_info(out, &authors, &committers);
if (count > limit)
strbuf_addf(out, "\n* %s: (%d commits)\n", name, count);
else
strbuf_addf(out, "\n* %s:\n", name);
if (origin_data->is_local_branch && use_branch_desc)
add_branch_desc(out, name);
for (i = 0; i < subjects.nr; i++)
if (i >= limit)
strbuf_addf(out, " ...\n");
else
strbuf_addf(out, " %s\n", subjects.items[i].string);
clear_commit_marks((struct commit *)branch, flags);
clear_commit_marks(head, flags);
free_commit_list(rev->commits);
rev->commits = NULL;
rev->pending.nr = 0;
string_list_clear(&authors, 0);
string_list_clear(&committers, 0);
string_list_clear(&subjects, 0);
}
示例13: show_ref
static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
{
struct object *obj;
const char *hex;
unsigned char peeled[20];
if (tags_only || heads_only) {
int match;
match = heads_only && !prefixcmp(refname, "refs/heads/");
match |= tags_only && !prefixcmp(refname, "refs/tags/");
if (!match)
return 0;
}
if (pattern) {
int reflen = strlen(refname);
const char **p = pattern, *m;
while ((m = *p++) != NULL) {
int len = strlen(m);
if (len > reflen)
continue;
if (memcmp(m, refname + reflen - len, len))
continue;
if (len == reflen)
goto match;
/* "--verify" requires an exact match */
if (verify)
continue;
if (refname[reflen - len - 1] == '/')
goto match;
}
return 0;
}
match:
found_match++;
/* This changes the semantics slightly that even under quiet we
* detect and return error if the repository is corrupt and
* ref points at a nonexistent object.
*/
if (!has_sha1_file(sha1))
die("git show-ref: bad ref %s (%s)", refname,
sha1_to_hex(sha1));
if (quiet)
return 0;
show_one(refname, sha1);
if (!deref_tags)
return 0;
if ((flag & REF_ISPACKED) && !peel_ref(refname, peeled)) {
if (!is_null_sha1(peeled)) {
hex = find_unique_abbrev(peeled, abbrev);
printf("%s %s^{}\n", hex, refname);
}
}
else {
obj = parse_object(sha1);
if (!obj)
die("git show-ref: bad ref %s (%s)", refname,
sha1_to_hex(sha1));
if (obj->type == OBJ_TAG) {
obj = deref_tag(obj, refname, 0);
if (!obj)
die("git show-ref: bad tag at ref %s (%s)", refname,
sha1_to_hex(sha1));
hex = find_unique_abbrev(obj->sha1, abbrev);
printf("%s %s^{}\n", hex, refname);
}
}
return 0;
}
示例14: shortlog
static void shortlog(const char *name, unsigned char *sha1,
struct commit *head, struct rev_info *rev, int limit)
{
int i, count = 0;
struct commit *commit;
struct object *branch;
struct list subjects = { NULL, NULL, 0, 0 };
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
if (!branch || branch->type != OBJ_COMMIT)
return;
setup_revisions(0, NULL, rev, NULL);
rev->ignore_merges = 1;
add_pending_object(rev, branch, name);
add_pending_object(rev, &head->object, "^HEAD");
head->object.flags |= UNINTERESTING;
if (prepare_revision_walk(rev))
die("revision walk setup failed");
while ((commit = get_revision(rev)) != NULL) {
char *oneline, *bol, *eol;
/* ignore merges */
if (commit->parents && commit->parents->next)
continue;
count++;
if (subjects.nr > limit)
continue;
bol = strstr(commit->buffer, "\n\n");
if (bol) {
unsigned char c;
do {
c = *++bol;
} while (isspace(c));
if (!c)
bol = NULL;
}
if (!bol) {
append_to_list(&subjects, xstrdup(sha1_to_hex(
commit->object.sha1)),
NULL);
continue;
}
eol = strchr(bol, '\n');
if (eol) {
oneline = xmemdupz(bol, eol - bol);
} else {
oneline = xstrdup(bol);
}
append_to_list(&subjects, oneline, NULL);
}
if (count > limit)
printf("\n* %s: (%d commits)\n", name, count);
else
printf("\n* %s:\n", name);
for (i = 0; i < subjects.nr; i++)
if (i >= limit)
printf(" ...\n");
else
printf(" %s\n", subjects.list[i]);
clear_commit_marks((struct commit *)branch, flags);
clear_commit_marks(head, flags);
free_commit_list(rev->commits);
rev->commits = NULL;
rev->pending.nr = 0;
free_list(&subjects);
}
示例15: peel_onion
static int peel_onion(const char *name, int len, unsigned char *sha1)
{
unsigned char outer[20];
const char *sp;
const char *type_string = NULL;
struct object *o;
/*
* "ref^{type}" dereferences ref repeatedly until you cannot
* dereference anymore, or you get an object of given type,
* whichever comes first. "ref^{}" means just dereference
* tags until you get a non-tag. "ref^0" is a shorthand for
* "ref^{commit}". "commit^{tree}" could be used to find the
* top-level tree of the given commit.
*/
if (len < 4 || name[len-1] != '}')
return -1;
for (sp = name + len - 1; name <= sp; sp--) {
int ch = *sp;
if (ch == '{' && name < sp && sp[-1] == '^')
break;
}
if (sp <= name)
return -1;
sp++; /* beginning of type name, or closing brace for empty */
if (!strncmp(commit_type, sp, 6) && sp[6] == '}')
type_string = commit_type;
else if (!strncmp(tree_type, sp, 4) && sp[4] == '}')
type_string = tree_type;
else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
type_string = blob_type;
else if (sp[0] == '}')
type_string = NULL;
else
return -1;
if (get_sha1_1(name, sp - name - 2, outer))
return -1;
o = parse_object(outer);
if (!o)
return -1;
if (!type_string) {
o = deref_tag(o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(o->sha1)))
return -1;
memcpy(sha1, o->sha1, 20);
}
else {
/* At this point, the syntax look correct, so
* if we do not get the needed object, we should
* barf.
*/
while (1) {
if (!o || (!o->parsed && !parse_object(o->sha1)))
return -1;
if (o->type == type_string) {
memcpy(sha1, o->sha1, 20);
return 0;
}
if (o->type == tag_type)
o = ((struct tag*) o)->tagged;
else if (o->type == commit_type)
o = &(((struct commit *) o)->tree->object);
else
return error("%.*s: expected %s type, but the object dereferences to %s type",
len, name, type_string,
o->type);
if (!o->parsed)
parse_object(o->sha1);
}
}
return 0;
}