本文整理汇总了C++中dwim_ref函数的典型用法代码示例。如果您正苦于以下问题:C++ dwim_ref函数的具体用法?C++ dwim_ref怎么用?C++ dwim_ref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dwim_ref函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:BT-ojossen,项目名称:git,代码行数:27,代码来源:log.c
示例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);
}
开发者ID:ANKIT-KS,项目名称:git,代码行数:35,代码来源:wt-status.c
示例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;
}
开发者ID:Noffica,项目名称:git,代码行数:30,代码来源:merge-base.c
示例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;
}
开发者ID:AbelTian,项目名称:git,代码行数:27,代码来源:log.c
示例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;
}
开发者ID:0369,项目名称:git,代码行数:57,代码来源:merge-base.c
示例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;
}
开发者ID:fcharlie,项目名称:git,代码行数:55,代码来源:archive.c
示例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;
}
开发者ID:B-Rich,项目名称:git,代码行数:55,代码来源:archive.c
示例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;
}
开发者ID:ruoso,项目名称:git,代码行数:20,代码来源:transport.c
示例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;
}
开发者ID:Carina26,项目名称:git,代码行数:20,代码来源:transport.c
示例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));
}
开发者ID:beyond2002,项目名称:GT813C,代码行数:42,代码来源:rev-parse.c
示例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;
}
开发者ID:carey94tt,项目名称:git,代码行数:38,代码来源:log.c
示例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;
}
}
开发者ID:osugi5050,项目名称:git,代码行数:24,代码来源:fast-export.c
示例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",
//.........这里部分代码省略.........
开发者ID:avish,项目名称:git,代码行数:101,代码来源:bundle.c
示例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;
}
//.........这里部分代码省略.........
开发者ID:carey94tt,项目名称:git,代码行数:101,代码来源:merge.c
示例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);
}
}
}
//.........这里部分代码省略.........
开发者ID:ThibG,项目名称:differential,代码行数:101,代码来源:get_sha1_basic.v0.c
示例16: create_branch
void create_branch(const char *head,
const char *name, const char *start_name,
int force, int reflog, enum branch_track track)
{
struct ref_lock *lock;
struct commit *commit;
unsigned char sha1[20];
char *real_ref, msg[PATH_MAX + 20];
struct strbuf ref = STRBUF_INIT;
int forcing = 0;
int len;
len = strlen(name);
if (interpret_nth_last_branch(name, &ref) != len) {
strbuf_reset(&ref);
strbuf_add(&ref, name, len);
}
strbuf_splice(&ref, 0, 0, "refs/heads/", 11);
if (check_ref_format(ref.buf))
die("'%s' is not a valid branch name.", name);
if (resolve_ref(ref.buf, sha1, 1, NULL)) {
if (!force)
die("A branch named '%s' already exists.", name);
else if (!is_bare_repository() && !strcmp(head, name))
die("Cannot force update the current branch.");
forcing = 1;
}
real_ref = NULL;
if (get_sha1(start_name, sha1))
die("Not a valid object name: '%s'.", start_name);
switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) {
case 0:
/* Not branching from any existing branch */
if (track == BRANCH_TRACK_EXPLICIT)
die("Cannot setup tracking information; starting point is not a branch.");
break;
case 1:
/* Unique completion -- good, only if it is a real ref */
if (track == BRANCH_TRACK_EXPLICIT && !strcmp(real_ref, "HEAD"))
die("Cannot setup tracking information; starting point is not a branch.");
break;
default:
die("Ambiguous object name: '%s'.", start_name);
break;
}
if ((commit = lookup_commit_reference(sha1)) == NULL)
die("Not a valid branch point: '%s'.", start_name);
hashcpy(sha1, commit->object.sha1);
lock = lock_any_ref_for_update(ref.buf, NULL, 0);
if (!lock)
die("Failed to lock ref for update: %s.", strerror(errno));
if (reflog)
log_all_ref_updates = 1;
if (forcing)
snprintf(msg, sizeof msg, "branch: Reset from %s",
start_name);
else
snprintf(msg, sizeof msg, "branch: Created from %s",
start_name);
if (real_ref && track)
setup_tracking(name, real_ref, track);
if (write_ref_sha1(lock, sha1, msg) < 0)
die("Failed to write ref: %s.", strerror(errno));
strbuf_release(&ref);
free(real_ref);
}
开发者ID:emk,项目名称:git,代码行数:77,代码来源:branch.c
示例17: write_bundle_refs
/*
* Write out bundle refs based on the tips already
* parsed into revs.pending. As a side effect, may
* manipulate revs.pending to include additional
* necessary objects (like tags).
*
* Returns the number of refs written, or negative
* on error.
*/
static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
{
int i;
int ref_count = 0;
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)
goto skip_write_ref;
if (read_ref_full(e->name, RESOLVE_REF_READING, sha1, &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;
goto skip_write_ref;
}
/*
* 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"),
e->name);
goto skip_write_ref;
}
/*
* If you run "git bundle create bndl v1.0..v2.0", the
* name of the positive ref is "v2.0" but that is the
* commit that is referenced by the tag, and not the tag
* itself.
*/
if (hashcmp(sha1, e->item->sha1)) {
/*
* Is this the positive end of a range expressed
* in terms of a tag (e.g. v2.0 from the range
* "v1.0..v2.0")?
*/
struct commit *one = lookup_commit_reference(sha1);
struct object *obj;
if (e->item == &(one->object)) {
/*
* Need to include e->name as an
* independent ref to the pack-objects
* input, so that the tag is included
* in the output; otherwise we would
* end up triggering "empty bundle"
* error.
*/
obj = parse_object_or_die(sha1, e->name);
obj->flags |= SHOWN;
add_pending_object(revs, obj, e->name);
}
goto skip_write_ref;
}
ref_count++;
write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
write_or_die(bundle_fd, " ", 1);
write_or_die(bundle_fd, display_ref, strlen(display_ref));
write_or_die(bundle_fd, "\n", 1);
skip_write_ref:
free(ref);
}
/* end header */
write_or_die(bundle_fd, "\n", 1);
return ref_count;
}
开发者ID:86joca,项目名称:git,代码行数:93,代码来源:bundle.c
示例18: 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 (starts_with(found_ref, "refs/heads/")) {
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
sha1_to_hex(branch_head), remote);
goto cleanup;
}
if (starts_with(found_ref, "refs/tags/")) {
strbuf_addf(msg, "%s\t\ttag '%s' of .\n",
sha1_to_hex(branch_head), remote);
goto cleanup;
}
if (starts_with(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_addf(&truname, "refs/heads/%s", remote);
strbuf_setlen(&truname, truname.len - len);
if (ref_exists(truname.buf)) {
strbuf_addf(msg,
"%s\t\tbranch '%s'%s of .\n",
oid_to_hex(&remote_head->object.oid),
truname.buf + 11,
(early ? " (early part)" : ""));
strbuf_release(&truname);
goto cleanup;
}
strbuf_release(&truname);
}
if (remote_head->util) {
struct merge_remote_desc *desc;
desc = merge_remote_util(remote_head);
if (desc && desc->obj && desc->obj->type == OBJ_TAG) {
strbuf_addf(msg, "%s\t\t%s '%s'\n",
oid_to_hex(&desc->obj->oid),
typename(desc->obj->type),
remote);
goto cleanup;
}
}
开发者ID:1tgr,项目名称:git,代码行数:90,代码来源:merge.c
示例19: get_stash_info
static int get_stash_info(struct stash_info *info, int argc, const char **argv)
{
int ret;
char *end_of_rev;
char *expanded_ref;
const char *revision;
const char *commit = NULL;
struct object_id dummy;
struct strbuf symbolic = STRBUF_INIT;
if (argc > 1) {
int i;
struct strbuf refs_msg = STRBUF_INIT;
for (i = 0; i < argc; i++)
strbuf_addf(&refs_msg, " '%s'", argv[i]);
fprintf_ln(stderr, _("Too many revisions specified:%s"),
refs_msg.buf);
strbuf_release(&refs_msg);
return -1;
}
if (argc == 1)
commit = argv[0];
strbuf_init(&info->revision, 0);
if (!commit) {
if (!ref_exists(ref_stash)) {
free_stash_info(info);
fprintf_ln(stderr, _("No stash entries found."));
return -1;
}
strbuf_addf(&info->revision, "%[email protected]{0}", ref_stash);
} else if (strspn(commit, "0123456789") == strlen(commit)) {
strbuf_addf(&info->revision, "%[email protected]{%s}", ref_stash, commit);
} else {
strbuf_addstr(&info->revision, commit);
}
revision = info->revision.buf;
if (get_oid(revision, &info->w_commit)) {
error(_("%s is not a valid reference"), revision);
free_stash_info(info);
return -1;
}
assert_stash_like(info, revision);
info->has_u = !get_oidf(&info->u_tree, "%s^3:", revision);
end_of_rev = strchrnul(revision, '@');
strbuf_add(&symbolic, revision, end_of_rev - revision);
ret = dwim_ref(symbolic.buf, symbolic.len, &dummy, &expanded_ref);
strbuf_release(&symbolic);
switch (ret) {
case 0: /* Not found, but valid ref */
info->is_stash_ref = 0;
break;
case 1:
info->is_stash_ref = !strcmp(expanded_ref, ref_stash);
break;
default: /* Invalid or ambiguous */
free_stash_info(info);
}
free(expanded_ref);
return !(ret == 0 || ret == 1);
}
开发者ID:PhilipOakley,项目名称:git,代码行数:73,代码来源:stash.c
示例20: cmd_show_branch
//.........这里部分代码省略.........
* make sense. --list is Ok.
*
* Also --all and --remotes do not make sense either.
*/
usage(show_branch_usage_reflog);
}
/* If nothing is specified, show all branches by default */
if (ac + all_heads + all_remotes == 0)
all_heads = 1;
if (reflog) {
unsigned char sha1[20];
char nth_desc[256];
char *ref;
int base = 0;
if (ac == 0) {
static const char *fake_av[2];
const char *refname;
refname = resolve_ref("HEAD", sha1, 1, NULL);
fake_av[0] = xstrdup(refname);
fake_av[1] = NULL;
av = fake_av;
ac = 1;
}
if (ac != 1)
die("--reflog option needs one branch name");
if (MAX_REVS < reflog)
die("Only %d entries can be shown at one time.",
MAX_REVS);
if (!dwim_ref(*av, strlen(*av), sha1, &ref))
die("No such ref %s", *av);
/* Has the base been specified? */
if (reflog_base) {
char *ep;
base = strtoul(reflog_base, &ep, 10);
if (*ep) {
/* Ah, that is a date spec... */
unsigned long at;
at = approxidate(reflog_base);
read_ref_at(ref, at, -1, sha1, NULL,
NULL, NULL, &base);
}
}
for (i = 0; i < reflog; i++) {
char *logmsg, *m;
const char *msg;
unsigned long timestamp;
int tz;
if (read_ref_at(ref, 0, base+i, sha1, &logmsg,
×tamp, &tz, NULL)) {
reflog = i;
break;
}
msg = strchr(logmsg, '\t');
if (!msg)
msg = "(none)";
else
msg++;
m = xmalloc(strlen(msg) + 200);
开发者ID:Jatinpurohit,项目名称:git,代码行数:67,代码来源:builtin-show-branch.c
注:本文中的dwim_ref函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论