本文整理汇总了C++中deref_tag函数的典型用法代码示例。如果您正苦于以下问题:C++ deref_tag函数的具体用法?C++ deref_tag怎么用?C++ deref_tag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了deref_tag函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:jjuran,项目名称:git,代码行数:18,代码来源:grep.c
示例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;
}
开发者ID:Pistos,项目名称:git,代码行数:19,代码来源:builtin-merge-recursive.c
示例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;
}
开发者ID:DinaraRigon,项目名称:TortoiseGit,代码行数:19,代码来源:gitdll.c
示例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;
}
开发者ID:AnithaPandiyan,项目名称:git,代码行数:19,代码来源:server-info.c
示例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;
}
开发者ID:120011676,项目名称:git,代码行数:19,代码来源:http-backend.c
示例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;
}
开发者ID:9b,项目名称:git,代码行数:19,代码来源:http-backend.c
示例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;
}
开发者ID:9b,项目名称:git,代码行数:20,代码来源:server-info.c
示例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);
}
开发者ID:ro-ot,项目名称:git,代码行数:38,代码来源:http-push.c
示例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;
}
开发者ID:Pistos,项目名称:git,代码行数:36,代码来源:pack-refs.c
示例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;
}
开发者ID:ovmine,项目名称:git,代码行数:36,代码来源:blame.c
示例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;
}
开发者ID:jaswope,项目名称:git,代码行数:101,代码来源:builtin-grep.c
示例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);
}
开发者ID:CCorreia,项目名称:git,代码行数:77,代码来源:fmt-merge-msg.c
示例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;
}
开发者ID:Advael,项目名称:git,代码行数:75,代码来源:show-ref.c
示例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);
}
开发者ID:Jatinpurohit,项目名称:git,代码行数:76,代码来源:builtin-fmt-merge-msg.c
示例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;
}
开发者ID:4ker,项目名称:annotated-git-1.0,代码行数:77,代码来源:sha1_name.c
示例16: cmd_diff
//.........这里部分代码省略.........
setup_diff_pager(&rev.diffopt);
/*
* Do we have --cached and not have a pending object, then
* default to HEAD by hand. Eek.
*/
if (!rev.pending.nr) {
int i;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (!strcmp(arg, "--"))
break;
else if (!strcmp(arg, "--cached") ||
!strcmp(arg, "--staged")) {
add_head_to_pending(&rev);
if (!rev.pending.nr) {
struct tree *tree;
tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
add_pending_object(&rev, &tree->object, "HEAD");
}
break;
}
}
}
for (i = 0; i < rev.pending.nr; i++) {
struct object_array_entry *entry = &rev.pending.objects[i];
struct object *obj = entry->item;
const char *name = entry->name;
int flags = (obj->flags & UNINTERESTING);
if (!obj->parsed)
obj = parse_object(obj->oid.hash);
obj = deref_tag(obj, NULL, 0);
if (!obj)
die(_("invalid object '%s' given."), name);
if (obj->type == OBJ_COMMIT)
obj = &((struct commit *)obj)->tree->object;
if (obj->type == OBJ_TREE) {
obj->flags |= flags;
add_object_array(obj, name, &ent);
} else if (obj->type == OBJ_BLOB) {
if (2 <= blobs)
die(_("more than two blobs given: '%s'"), name);
hashcpy(blob[blobs].sha1, obj->oid.hash);
blob[blobs].name = name;
blob[blobs].mode = entry->mode;
blobs++;
} else {
die(_("unhandled object '%s' given."), name);
}
}
if (rev.prune_data.nr)
paths += rev.prune_data.nr;
/*
* Now, do the arguments look reasonable?
*/
if (!ent.nr) {
switch (blobs) {
case 0:
result = builtin_diff_files(&rev, argc, argv);
break;
case 1:
开发者ID:136357477,项目名称:git,代码行数:67,代码来源:diff.c
示例17: mark_complete_and_common_ref
/*
* Mark recent commits available locally and reachable from a local ref as
* COMPLETE. If args->no_dependents is false, also mark COMPLETE remote refs as
* COMMON_REF (otherwise, we are not planning to participate in negotiation, and
* thus do not need COMMON_REF marks).
*
* The cutoff time for recency is determined by this heuristic: it is the
* earliest commit time of the objects in refs that are commits and that we know
* the commit time of.
*/
static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
struct fetch_pack_args *args,
struct ref **refs)
{
struct ref *ref;
int old_save_commit_buffer = save_commit_buffer;
timestamp_t cutoff = 0;
struct oidset loose_oid_set = OIDSET_INIT;
int use_oidset = 0;
struct loose_object_iter iter = {&loose_oid_set, *refs};
/* Enumerate all loose objects or know refs are not so many. */
use_oidset = !for_each_loose_object(add_loose_objects_to_set,
&iter, 0);
save_commit_buffer = 0;
for (ref = *refs; ref; ref = ref->next) {
struct object *o;
unsigned int flags = OBJECT_INFO_QUICK;
if (use_oidset &&
!oidset_contains(&loose_oid_set, &ref->old_oid)) {
/*
* I know this does not exist in the loose form,
* so check if it exists in a non-loose form.
*/
flags |= OBJECT_INFO_IGNORE_LOOSE;
}
if (!has_object_file_with_flags(&ref->old_oid, flags))
continue;
o = parse_object(the_repository, &ref->old_oid);
if (!o)
continue;
/* We already have it -- which may mean that we were
* in sync with the other side at some time after
* that (it is OK if we guess wrong here).
*/
if (o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o;
if (!cutoff || cutoff < commit->date)
cutoff = commit->date;
}
}
oidset_clear(&loose_oid_set);
if (!args->deepen) {
for_each_ref(mark_complete_oid, NULL);
for_each_cached_alternate(NULL, mark_alternate_complete);
commit_list_sort_by_date(&complete);
if (cutoff)
mark_recent_complete_commits(args, cutoff);
}
/*
* Mark all complete remote refs as common refs.
* Don't mark them common yet; the server has to be told so first.
*/
for (ref = *refs; ref; ref = ref->next) {
struct object *o = deref_tag(the_repository,
lookup_object(the_repository,
ref->old_oid.hash),
NULL, 0);
if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
continue;
negotiator->known_common(negotiator,
(struct commit *)o);
}
save_commit_buffer = old_save_commit_buffer;
}
开发者ID:hashpling,项目名称:git,代码行数:86,代码来源:fetch-pack.c
示例18: cmd_name_rev
int cmd_name_rev(int argc, const char **argv, const char *prefix)
{
struct object_array revs = { 0, 0, NULL };
int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0;
struct name_ref_data data = { 0, 0, NULL };
struct option opts[] = {
OPT_BOOLEAN(0, "name-only", &data.name_only, "print only names (no SHA-1)"),
OPT_BOOLEAN(0, "tags", &data.tags_only, "only use tags to name the commits"),
OPT_STRING(0, "refs", &data.ref_filter, "pattern",
"only use refs matching <pattern>"),
OPT_GROUP(""),
OPT_BOOLEAN(0, "all", &all, "list all commits reachable from all refs"),
OPT_BOOLEAN(0, "stdin", &transform_stdin, "read from stdin"),
OPT_BOOLEAN(0, "undefined", &allow_undefined, "allow to print `undefined` names"),
OPT_BOOLEAN(0, "always", &always,
"show abbreviated commit object as fallback"),
OPT_END(),
};
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
if (!!all + !!transform_stdin + !!argc > 1) {
error("Specify either a list, or --all, not both!");
usage_with_options(name_rev_usage, opts);
}
if (all || transform_stdin)
cutoff = 0;
for (; argc; argc--, argv++) {
unsigned char sha1[20];
struct object *o;
struct commit *commit;
if (get_sha1(*argv, sha1)) {
fprintf(stderr, "Could not get sha1 for %s. Skipping.\n",
*argv);
continue;
}
o = deref_tag(parse_object(sha1), *argv, 0);
if (!o || o->type != OBJ_COMMIT) {
fprintf(stderr, "Could not get commit for %s. Skipping.\n",
*argv);
continue;
}
commit = (struct commit *)o;
if (cutoff > commit->date)
cutoff = commit->date;
add_object_array((struct object *)commit, *argv, &revs);
}
if (cutoff)
cutoff = cutoff - CUTOFF_DATE_SLOP;
for_each_ref(name_ref, &data);
if (transform_stdin) {
char buffer[2048];
while (!feof(stdin)) {
char *p = fgets(buffer, sizeof(buffer), stdin);
if (!p)
break;
name_rev_line(p, &data);
}
} else if (all) {
int i, max;
max = get_max_object_index();
for (i = 0; i < max; i++) {
struct object *obj = get_indexed_object(i);
if (!obj)
continue;
show_name(obj, NULL,
always, allow_undefined, data.name_only);
}
} else {
int i;
for (i = 0; i < revs.nr; i++)
show_name(revs.objects[i].item, revs.objects[i].name,
always, allow_undefined, data.name_only);
}
return 0;
}
开发者ID:AndyA,项目名称:git-andya,代码行数:85,代码来源:name-rev.c
示例19: cmd_grep
//.........这里部分代码省略.........
argv++;
argc--;
continue;
}
die(emsg_missing_argument, arg);
}
if (!strcmp("--full-name", arg)) {
opt.relative = 0;
continue;
}
if (!strcmp("--", arg)) {
/* later processing wants to have this at argv[1] */
argv--;
argc++;
break;
}
if (*arg == '-')
usage(builtin_grep_usage);
/* First unrecognized non-option token */
if (!opt.pattern_list) {
append_grep_pattern(&opt, arg, "command line", 0,
GREP_PATTERN);
break;
}
else {
/* We are looking at the first path or rev;
* it is found at argv[1] after leaving the
* loop.
*/
argc++; argv--;
break;
}
}
if (!opt.pattern_list)
die("no pattern given.");
if ((opt.regflags != REG_NEWLINE) && opt.fixed)
die("cannot mix --fixed-strings and regexp");
compile_grep_patterns(&opt);
/* Check revs and then paths */
for (i = 1; 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);
if (opt.prefix_length && opt.relative) {
/* Make sure we do not get outside of paths */
for (i = 0; paths[i]; i++)
if (strncmp(prefix, paths[i], opt.prefix_length))
die("git grep: cannot generate relative filenames containing '..'");
}
}
else if (prefix) {
paths = xcalloc(2, sizeof(const char *));
paths[0] = prefix;
paths[1] = NULL;
}
if (!list.nr) {
if (!cached)
setup_work_tree();
return !grep_cache(&opt, paths, cached);
}
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;
}
free_grep_patterns(&opt);
return !hit;
}
开发者ID:emk,项目名称:git,代码行数:101,代码来源:builtin-grep.c
示例20: everything_local
static int everything_local(struct fetch_pack_args *args,
struct ref **refs,
struct ref **sought, int nr_sought)
{
struct ref *ref;
int retval;
int old_save_commit_buffer = save_commit_buffer;
timestamp_t cutoff = 0;
struct oidset loose_oid_set = OIDSET_INIT;
int use_oidset = 0;
struct loose_object_iter iter = {&loose_oid_set, *refs};
/* Enumerate all loose objects or know refs are not so many. */
use_oidset = !for_each_loose_object(add_loose_objects_to_set,
&iter, 0);
save_commit_buffer = 0;
for (ref = *refs; ref; ref = ref->next) {
struct object *o;
unsigned int flags = OBJECT_INFO_QUICK;
if (use_oidset &&
!oidset_contains(&loose_oid_set, &ref->old_oid)) {
/*
* I know this does not exist in the loose form,
* so check if it exists in a non-loose form.
*/
flags |= OBJECT_INFO_IGNORE_LOOSE;
}
if (!has_object_file_with_flags(&ref->old_oid, flags))
continue;
o = parse_object(&ref->old_oid);
if (!o)
continue;
/* We already have it -- which may mean that we were
* in sync with the other side at some time after
* that (it is OK if we guess wrong here).
*/
if (o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o;
if (!cutoff || cutoff < commit->date)
cutoff = commit->date;
}
}
oidset_clear(&loose_oid_set);
if (!args->no_dependents) {
if (!args->deepen) {
for_each_ref(mark_complete_oid, NULL);
for_each_cached_alternate(mark_alternate_complete);
commit_list_sort_by_date(&complete);
if (cutoff)
mark_recent_complete_commits(args, cutoff);
}
/*
* Mark all complete remote refs as common refs.
* Don't mark them common yet; the server has to be told so first.
*/
for (ref = *refs; ref; ref = ref->next) {
struct object *o = deref_tag(lookup_object(ref->old_oid.hash),
NULL, 0);
if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
continue;
if (!(o->flags & SEEN)) {
rev_list_push((struct commit *)o, COMMON_REF | SEEN);
mark_common((struct commit *)o, 1, 1);
}
}
}
filter_refs(args, refs, sought, nr_sought);
for (retval = 1, ref = *refs; ref ; ref = ref->next) {
const struct object_id *remote = &ref->old_oid;
struct object *o;
o = lookup_object(remote->hash);
if (!o || !(o->flags & COMPLETE)) {
retval = 0;
print_verbose(args, "want %s (%s)", oid_to_hex(remote),
ref->name);
continue;
}
print_verbose(args, _("already have %s (%s)"), oid_to_hex(remote),
ref->name);
}
save_commit_buffer = old_save_commit_buffer;
return retval;
}
开发者ID:DoWonJin,项目名称:git,代码行数:99,代码来源:fetch-pack.c
注:本文中的deref_tag函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论