本文整理汇总了C++中read_ref函数的典型用法代码示例。如果您正苦于以下问题:C++ read_ref函数的具体用法?C++ read_ref怎么用?C++ read_ref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_ref函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: read_head_pointers
static void read_head_pointers(void)
{
if (read_ref("HEAD", head_sha1))
die("No HEAD -- no initial commit yet?");
if (read_ref("MERGE_HEAD", merge_head_sha1)) {
fprintf(stderr, "Not in the middle of a merge.\n");
exit(0);
}
}
开发者ID:asdlei00,项目名称:git-1,代码行数:9,代码来源:update-index.c
示例2: for_each_replace_name
static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
{
const char **p, *full_hex;
struct strbuf ref = STRBUF_INIT;
size_t base_len;
int had_error = 0;
struct object_id oid;
strbuf_addstr(&ref, git_replace_ref_base);
base_len = ref.len;
for (p = argv; *p; p++) {
if (get_oid(*p, &oid)) {
error("Failed to resolve '%s' as a valid ref.", *p);
had_error = 1;
continue;
}
strbuf_setlen(&ref, base_len);
strbuf_addstr(&ref, oid_to_hex(&oid));
full_hex = ref.buf + base_len;
if (read_ref(ref.buf, &oid)) {
error("replace ref '%s' not found.", full_hex);
had_error = 1;
continue;
}
if (fn(full_hex, ref.buf, &oid))
had_error = 1;
}
strbuf_release(&ref);
return had_error;
}
开发者ID:PEPE-coin,项目名称:git,代码行数:33,代码来源:replace.c
示例3: sequencer_continue
static int sequencer_continue(struct replay_opts *opts, int skip)
{
struct commit_list *todo_list = NULL;
if (!file_exists(git_path(SEQ_TODO_FILE)))
return continue_single_pick();
read_populate_opts(&opts);
read_populate_todo(&todo_list, opts);
if (opts->action == REPLAY_PICK)
load_rewritten(&rewritten, git_path(SEQ_REWR_FILE));
/* Verify that the conflict has been resolved */
if (file_exists(git_path("CHERRY_PICK_HEAD")) ||
file_exists(git_path("REVERT_HEAD"))) {
int ret = continue_single_pick();
if (ret)
return ret;
}
if (index_differs_from("HEAD", 0))
return error_dirty_index(opts);
if (opts->action == REPLAY_PICK && !skip) {
unsigned char to[20];
if (!read_ref("HEAD", to))
add_rewritten(&rewritten, todo_list->item->object.sha1, to);
}
todo_list = todo_list->next;
return pick_commits(todo_list, opts);
}
开发者ID:holgerschroeder,项目名称:git,代码行数:28,代码来源:sequencer.c
示例4: get_sha1_basic
static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
{
static const char *prefix[] = {
"",
"refs",
"refs/tags",
"refs/heads",
NULL
};
const char **p;
if (len == 40 && !get_sha1_hex(str, sha1))
return 0;
/* Accept only unambiguous ref paths. */
if (ambiguous_path(str, len))
return -1;
for (p = prefix; *p; p++) {
char *pathname = git_path("%s/%.*s", *p, len, str);
if (!read_ref(pathname, sha1))
return 0;
}
return -1;
}
开发者ID:4ker,项目名称:annotated-git-1.0,代码行数:25,代码来源:sha1_name.c
示例5: create_notes_commit
void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
const char *msg, unsigned char *result_sha1)
{
unsigned char tree_sha1[20];
assert(t->initialized);
if (write_notes_tree(t, tree_sha1))
die("Failed to write notes tree to database");
if (!parents) {
/* Deduce parent commit from t->ref */
unsigned char parent_sha1[20];
if (!read_ref(t->ref, parent_sha1)) {
struct commit *parent = lookup_commit(parent_sha1);
if (!parent || parse_commit(parent))
die("Failed to find/parse commit %s", t->ref);
commit_list_insert(parent, &parents);
}
/* else: t->ref points to nothing, assume root/orphan commit */
}
if (commit_tree(msg, tree_sha1, parents, result_sha1, NULL))
die("Failed to commit notes tree to database");
}
开发者ID:CinsonChen,项目名称:git,代码行数:25,代码来源:notes-merge.c
示例6: bibl_read
int
bibl_read( bibl *b, FILE *fp, char *filename, param *p )
{
convert_rules r;
param lp;
bibl bin;
if ( !b ) return BIBL_ERR_BADINPUT;
if ( !fp ) return BIBL_ERR_BADINPUT;
if ( !p ) return BIBL_ERR_BADINPUT;
if ( bibl_illegalinmode( p->readformat ) ) return BIBL_ERR_BADINPUT;
bibl_setreadparams( &lp, p );
bibl_init( &bin );
rules_init( &r, p->readformat );
read_ref( fp, &bin, filename, &r, &lp );
if ( !lp.output_raw || ( lp.output_raw & BIBL_RAW_WITHCHARCONVERT ) )
bibl_fixcharsets( &bin, &lp );
if ( !lp.output_raw )
convert_ref( &bin, filename, b, &r, &lp );
else {
if ( p->verbose > 1 ) bibl_verbose0( &bin );
bibl_copy( b, &bin );
}
if ( !lp.output_raw || ( lp.output_raw & BIBL_RAW_WITHMAKEREFID ) )
bibl_checkrefid( b, &lp );
bibl_free( &bin );
return BIBL_OK;
}
开发者ID:andytwoods,项目名称:xPapers,代码行数:30,代码来源:bibutils.c
示例7: notes_cache_match_validity
static int notes_cache_match_validity(struct repository *r,
const char *ref,
const char *validity)
{
struct object_id oid;
struct commit *commit;
struct pretty_print_context pretty_ctx;
struct strbuf msg = STRBUF_INIT;
int ret;
if (read_ref(ref, &oid) < 0)
return 0;
commit = lookup_commit_reference_gently(r, &oid, 1);
if (!commit)
return 0;
memset(&pretty_ctx, 0, sizeof(pretty_ctx));
format_commit_message(commit, "%s", &msg, &pretty_ctx);
strbuf_trim(&msg);
ret = !strcmp(msg.buf, validity);
strbuf_release(&msg);
return ret;
}
开发者ID:Noffica,项目名称:git,代码行数:26,代码来源:notes-cache.c
示例8: delete_pseudoref
static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1)
{
static struct lock_file lock;
const char *filename;
filename = git_path("%s", pseudoref);
if (old_sha1 && !is_null_sha1(old_sha1)) {
int fd;
unsigned char actual_old_sha1[20];
fd = hold_lock_file_for_update(&lock, filename,
LOCK_DIE_ON_ERROR);
if (fd < 0)
die_errno(_("Could not open '%s' for writing"), filename);
if (read_ref(pseudoref, actual_old_sha1))
die("could not read ref '%s'", pseudoref);
if (hashcmp(actual_old_sha1, old_sha1)) {
warning("Unexpected sha1 when deleting %s", pseudoref);
rollback_lock_file(&lock);
return -1;
}
unlink(filename);
rollback_lock_file(&lock);
} else {
unlink(filename);
}
return 0;
}
开发者ID:chidveer,项目名称:git,代码行数:31,代码来源:refs.c
示例9: do_fetch
static int do_fetch(struct transport *transport,
struct refspec *refs, int ref_count)
{
struct ref *ref_map;
struct ref *rm;
int autotags = (transport->remote->fetch_tags == 1);
if (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET)
tags = TAGS_SET;
if (transport->remote->fetch_tags == -1)
tags = TAGS_UNSET;
if (!transport->get_refs_list || !transport->fetch)
die("Don't know how to fetch from %s", transport->url);
/* if not appending, truncate FETCH_HEAD */
if (!append) {
char *filename = git_path("FETCH_HEAD");
FILE *fp = fopen(filename, "w");
if (!fp)
return error("cannot open %s: %s\n", filename, strerror(errno));
fclose(fp);
}
ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags);
if (!update_head_ok)
check_not_current_branch(ref_map);
for (rm = ref_map; rm; rm = rm->next) {
if (rm->peer_ref)
read_ref(rm->peer_ref->name, rm->peer_ref->old_sha1);
}
if (tags == TAGS_DEFAULT && autotags)
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
if (fetch_refs(transport, ref_map)) {
free_refs(ref_map);
return 1;
}
free_refs(ref_map);
/* if neither --no-tags nor --tags was specified, do automated tag
* following ... */
if (tags == TAGS_DEFAULT && autotags) {
struct ref **tail = &ref_map;
ref_map = NULL;
find_non_local_tags(transport, &ref_map, &tail);
if (ref_map) {
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
fetch_refs(transport, ref_map);
}
free_refs(ref_map);
}
return 0;
}
开发者ID:Fabiano-lr,项目名称:git,代码行数:56,代码来源:builtin-fetch.c
示例10: do_reupdate
static int do_reupdate(int ac, const char **av,
const char *prefix, int prefix_length)
{
/* Read HEAD and run update-index on paths that are
* merged and already different between index and HEAD.
*/
int pos;
int has_head = 1;
struct pathspec pathspec;
parse_pathspec(&pathspec, 0,
PATHSPEC_PREFER_CWD,
prefix, av + 1);
if (read_ref("HEAD", &head_oid))
/* If there is no HEAD, that means it is an initial
* commit. Update everything in the index.
*/
has_head = 0;
redo:
for (pos = 0; pos < active_nr; pos++) {
const struct cache_entry *ce = active_cache[pos];
struct cache_entry *old = NULL;
int save_nr;
char *path;
if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))
continue;
if (has_head)
old = read_one_ent(NULL, &head_oid,
ce->name, ce_namelen(ce), 0);
if (old && ce->ce_mode == old->ce_mode &&
!oidcmp(&ce->oid, &old->oid)) {
discard_cache_entry(old);
continue; /* unchanged */
}
/* Be careful. The working tree may not have the
* path anymore, in which case, under 'allow_remove',
* or worse yet 'allow_replace', active_nr may decrease.
*/
save_nr = active_nr;
path = xstrdup(ce->name);
update_one(path);
free(path);
discard_cache_entry(old);
if (save_nr != active_nr)
goto redo;
}
clear_pathspec(&pathspec);
return 0;
}
开发者ID:Nowher2,项目名称:git,代码行数:51,代码来源:update-index.c
示例11: check_ref_valid
static int check_ref_valid(struct object_id *object,
struct object_id *prev,
struct strbuf *ref,
int force)
{
strbuf_reset(ref);
strbuf_addf(ref, "%s%s", git_replace_ref_base, oid_to_hex(object));
if (check_refname_format(ref->buf, 0))
return error("'%s' is not a valid ref name.", ref->buf);
if (read_ref(ref->buf, prev))
oidclr(prev);
else if (!force)
return error("replace ref '%s' already exists", ref->buf);
return 0;
}
开发者ID:PEPE-coin,项目名称:git,代码行数:16,代码来源:replace.c
示例12: do_reupdate
static int do_reupdate(int ac, const char **av,
const char *prefix, int prefix_length)
{
/* Read HEAD and run update-index on paths that are
* merged and already different between index and HEAD.
*/
int pos;
int has_head = 1;
const char **paths = get_pathspec(prefix, av + 1);
struct pathspec pathspec;
init_pathspec(&pathspec, paths);
if (read_ref("HEAD", head_sha1))
/* If there is no HEAD, that means it is an initial
* commit. Update everything in the index.
*/
has_head = 0;
redo:
for (pos = 0; pos < active_nr; pos++) {
struct cache_entry *ce = active_cache[pos];
struct cache_entry *old = NULL;
int save_nr;
if (ce_stage(ce) || !ce_path_match(ce, &pathspec))
continue;
if (has_head)
old = read_one_ent(NULL, head_sha1,
ce->name, ce_namelen(ce), 0);
if (old && ce->ce_mode == old->ce_mode &&
!hashcmp(ce->sha1, old->sha1)) {
free(old);
continue; /* unchanged */
}
/* Be careful. The working tree may not have the
* path anymore, in which case, under 'allow_remove',
* or worse yet 'allow_replace', active_nr may decrease.
*/
save_nr = active_nr;
update_one(ce->name + prefix_length, prefix, prefix_length);
if (save_nr != active_nr)
goto redo;
}
free_pathspec(&pathspec);
return 0;
}
开发者ID:Barklad,项目名称:first_app,代码行数:46,代码来源:update-index.c
示例13: cmd_show_ref
int cmd_show_ref(int argc, const char **argv, const char *prefix)
{
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(show_ref_usage, show_ref_options);
argc = parse_options(argc, argv, prefix, show_ref_options,
show_ref_usage, PARSE_OPT_NO_INTERNAL_HELP);
if (exclude_arg)
return exclude_existing(exclude_existing_arg);
pattern = argv;
if (!*pattern)
pattern = NULL;
if (verify) {
if (!pattern)
die("--verify requires a reference");
while (*pattern) {
unsigned char sha1[20];
if (!prefixcmp(*pattern, "refs/") &&
!read_ref(*pattern, sha1)) {
if (!quiet)
show_one(*pattern, sha1);
}
else if (!quiet)
die("'%s' - not a valid ref", *pattern);
else
return 1;
pattern++;
}
return 0;
}
if (show_head)
head_ref(show_ref, NULL);
for_each_ref(show_ref, NULL);
if (!found_match) {
if (verify && !quiet)
die("No match");
return 1;
}
return 0;
}
开发者ID:13leaf,项目名称:git,代码行数:45,代码来源:show-ref.c
示例14: write_pseudoref
static int write_pseudoref(const char *pseudoref, const unsigned char *sha1,
const unsigned char *old_sha1, struct strbuf *err)
{
const char *filename;
int fd;
static struct lock_file lock;
struct strbuf buf = STRBUF_INIT;
int ret = -1;
strbuf_addf(&buf, "%s\n", sha1_to_hex(sha1));
filename = git_path("%s", pseudoref);
fd = hold_lock_file_for_update(&lock, filename, LOCK_DIE_ON_ERROR);
if (fd < 0) {
strbuf_addf(err, "could not open '%s' for writing: %s",
filename, strerror(errno));
return -1;
}
if (old_sha1) {
unsigned char actual_old_sha1[20];
if (read_ref(pseudoref, actual_old_sha1))
die("could not read ref '%s'", pseudoref);
if (hashcmp(actual_old_sha1, old_sha1)) {
strbuf_addf(err, "unexpected sha1 when writing '%s'", pseudoref);
rollback_lock_file(&lock);
goto done;
}
}
if (write_in_full(fd, buf.buf, buf.len) != buf.len) {
strbuf_addf(err, "could not write to '%s'", filename);
rollback_lock_file(&lock);
goto done;
}
commit_lock_file(&lock);
ret = 0;
done:
strbuf_release(&buf);
return ret;
}
开发者ID:chidveer,项目名称:git,代码行数:43,代码来源:refs.c
示例15: cmd_show_ref
int cmd_show_ref(int argc, const char **argv, const char *prefix)
{
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, show_ref_options,
show_ref_usage, 0);
if (exclude_arg)
return exclude_existing(exclude_existing_arg);
pattern = argv;
if (!*pattern)
pattern = NULL;
if (verify) {
if (!pattern)
die("--verify requires a reference");
while (*pattern) {
struct object_id oid;
if ((starts_with(*pattern, "refs/") || !strcmp(*pattern, "HEAD")) &&
!read_ref(*pattern, &oid)) {
show_one(*pattern, &oid);
}
else if (!quiet)
die("'%s' - not a valid ref", *pattern);
else
return 1;
pattern++;
}
return 0;
}
if (show_head)
head_ref(show_ref, NULL);
for_each_ref(show_ref, NULL);
if (!found_match) {
if (verify && !quiet)
die("No match");
return 1;
}
return 0;
}
开发者ID:guban,项目名称:git,代码行数:42,代码来源:show-ref.c
示例16: commit_notes
int commit_notes(struct notes_tree *t, const char *msg)
{
struct commit_list *parent;
unsigned char tree_sha1[20], prev_commit[20], new_commit[20];
struct strbuf buf = STRBUF_INIT;
if (!t)
t = &default_notes_tree;
if (!t->initialized || !t->ref || !*t->ref)
die("Cannot commit uninitialized/unreferenced notes tree");
if (!t->dirty)
return 0; /* don't have to commit an unchanged tree */
/* Prepare commit message and reflog message */
strbuf_addstr(&buf, "notes: "); /* commit message starts at index 7 */
strbuf_addstr(&buf, msg);
if (buf.buf[buf.len - 1] != '\n')
strbuf_addch(&buf, '\n'); /* Make sure msg ends with newline */
/* Convert notes tree to tree object */
if (write_notes_tree(t, tree_sha1))
die("Failed to write current notes tree to database");
/* Create new commit for the tree object */
if (!read_ref(t->ref, prev_commit)) { /* retrieve parent commit */
parent = xmalloc(sizeof(*parent));
parent->item = lookup_commit(prev_commit);
parent->next = NULL;
} else {
hashclr(prev_commit);
parent = NULL;
}
if (commit_tree(buf.buf + 7, tree_sha1, parent, new_commit, NULL))
die("Failed to commit notes tree to database");
/* Update notes ref with new commit */
update_ref(buf.buf, t->ref, new_commit, prev_commit, 0, DIE_ON_ERR);
strbuf_release(&buf);
return 0;
}
开发者ID:flichtenheld,项目名称:git,代码行数:41,代码来源:notes.c
示例17: init_notes
void init_notes(struct notes_tree *t, const char *notes_ref,
combine_notes_fn combine_notes, int flags)
{
unsigned char sha1[20], object_sha1[20];
unsigned mode;
struct leaf_node root_tree;
if (!t)
t = &default_notes_tree;
assert(!t->initialized);
if (!notes_ref)
notes_ref = getenv(GIT_NOTES_REF_ENVIRONMENT);
if (!notes_ref)
notes_ref = notes_ref_name; /* value of core.notesRef config */
if (!notes_ref)
notes_ref = GIT_NOTES_DEFAULT_REF;
if (!combine_notes)
combine_notes = combine_notes_concatenate;
t->root = (struct int_node *) xcalloc(sizeof(struct int_node), 1);
t->first_non_note = NULL;
t->prev_non_note = NULL;
t->ref = notes_ref ? xstrdup(notes_ref) : NULL;
t->combine_notes = combine_notes;
t->initialized = 1;
if (flags & NOTES_INIT_EMPTY || !notes_ref ||
read_ref(notes_ref, object_sha1))
return;
if (get_tree_entry(object_sha1, "", sha1, &mode))
die("Failed to read notes tree referenced by %s (%s)",
notes_ref, object_sha1);
hashclr(root_tree.key_sha1);
hashcpy(root_tree.val_sha1, sha1);
load_subtree(t, &root_tree, t->root, 0);
}
开发者ID:sanj,项目名称:git,代码行数:39,代码来源:notes.c
示例18: init_notes
void init_notes(struct notes_tree *t, const char *notes_ref,
combine_notes_fn combine_notes, int flags)
{
struct object_id oid, object_oid;
unsigned mode;
struct leaf_node root_tree;
if (!t)
t = &default_notes_tree;
assert(!t->initialized);
if (!notes_ref)
notes_ref = default_notes_ref();
if (!combine_notes)
combine_notes = combine_notes_concatenate;
t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
t->first_non_note = NULL;
t->prev_non_note = NULL;
t->ref = xstrdup_or_null(notes_ref);
t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL;
t->combine_notes = combine_notes;
t->initialized = 1;
t->dirty = 0;
if (flags & NOTES_INIT_EMPTY || !notes_ref ||
get_oid_treeish(notes_ref, &object_oid))
return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
die("Cannot use notes ref %s", notes_ref);
if (get_tree_entry(&object_oid, "", &oid, &mode))
die("Failed to read notes tree referenced by %s (%s)",
notes_ref, oid_to_hex(&object_oid));
oidclr(&root_tree.key_oid);
oidcpy(&root_tree.val_oid, &oid);
load_subtree(t, &root_tree, t->root, 0);
}
开发者ID:Noffica,项目名称:git,代码行数:39,代码来源:notes.c
示例19: init_notes
void init_notes(struct notes_tree *t, const char *notes_ref,
combine_notes_fn combine_notes, int flags)
{
unsigned char sha1[20], object_sha1[20];
unsigned mode;
struct leaf_node root_tree;
if (!t)
t = &default_notes_tree;
assert(!t->initialized);
if (!notes_ref)
notes_ref = default_notes_ref();
if (!combine_notes)
combine_notes = combine_notes_concatenate;
t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
t->first_non_note = NULL;
t->prev_non_note = NULL;
t->ref = xstrdup_or_null(notes_ref);
t->combine_notes = combine_notes;
t->initialized = 1;
t->dirty = 0;
if (flags & NOTES_INIT_EMPTY || !notes_ref ||
read_ref(notes_ref, object_sha1))
return;
if (get_tree_entry(object_sha1, "", sha1, &mode))
die("Failed to read notes tree referenced by %s (%s)",
notes_ref, sha1_to_hex(object_sha1));
hashclr(root_tree.key_sha1);
hashcpy(root_tree.val_sha1, sha1);
load_subtree(t, &root_tree, t->root, 0);
}
开发者ID:578723746,项目名称:git,代码行数:36,代码来源:notes.c
示例20: notes_cache_match_validity
static int notes_cache_match_validity(const char *ref, const char *validity)
{
unsigned char sha1[20];
struct commit *commit;
struct pretty_print_context pretty_ctx;
struct strbuf msg = STRBUF_INIT;
int ret;
if (read_ref(ref, sha1) < 0)
return 0;
commit = lookup_commit_reference_gently(sha1, 1);
if (!commit)
return 0;
memset(&pretty_ctx, 0, sizeof(pretty_ctx));
format_commit_message(commit, "%s", &msg, &pretty_ctx);
strbuf_trim(&msg);
ret = !strcmp(msg.buf, validity);
strbuf_release(&msg);
return ret;
}
开发者ID:00027jang27,项目名称:git,代码行数:24,代码来源:notes-cache.c
注:本文中的read_ref函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论