本文整理汇总了C++中commit_lock_file函数的典型用法代码示例。如果您正苦于以下问题:C++ commit_lock_file函数的具体用法?C++ commit_lock_file怎么用?C++ commit_lock_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commit_lock_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: write_rr
static int write_rr(struct string_list *rr, int out_fd)
{
int i;
for (i = 0; i < rr->nr; i++) {
struct strbuf buf = STRBUF_INIT;
struct rerere_id *id;
assert(rr->items[i].util != RERERE_RESOLVED);
id = rr->items[i].util;
if (!id)
continue;
assert(id->variant >= 0);
if (0 < id->variant)
strbuf_addf(&buf, "%s.%d\t%s%c",
rerere_id_hex(id), id->variant,
rr->items[i].string, 0);
else
strbuf_addf(&buf, "%s\t%s%c",
rerere_id_hex(id),
rr->items[i].string, 0);
if (write_in_full(out_fd, buf.buf, buf.len) < 0)
die(_("unable to write rerere record"));
strbuf_release(&buf);
}
if (commit_lock_file(&write_lock) != 0)
die(_("unable to write rerere record"));
return 0;
}
开发者ID:Noffica,项目名称:git,代码行数:31,代码来源:rerere.c
示例2: pack_refs
int pack_refs(unsigned int flags)
{
int fd;
struct pack_refs_cb_data cbdata;
memset(&cbdata, 0, sizeof(cbdata));
cbdata.flags = flags;
fd = hold_lock_file_for_update(&packed, git_path("packed-refs"),
LOCK_DIE_ON_ERROR);
cbdata.refs_file = fdopen(fd, "w");
if (!cbdata.refs_file)
die("unable to create ref-pack file structure (%s)",
strerror(errno));
/* perhaps other traits later as well */
fprintf(cbdata.refs_file, "# pack-refs with: peeled \n");
for_each_ref(handle_one_ref, &cbdata);
if (ferror(cbdata.refs_file))
die("failed to write ref-pack file");
if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file))
die("failed to write ref-pack file (%s)", strerror(errno));
/*
* Since the lock file was fdopen()'ed and then fclose()'ed above,
* assign -1 to the lock file descriptor so that commit_lock_file()
* won't try to close() it.
*/
packed.fd = -1;
if (commit_lock_file(&packed) < 0)
die("unable to overwrite old ref-pack file (%s)", strerror(errno));
if (cbdata.flags & PACK_REFS_PRUNE)
prune_refs(cbdata.ref_to_prune);
return 0;
}
开发者ID:AndyA,项目名称:git-andya,代码行数:35,代码来源:pack-refs.c
示例3: repack_without_ref
static int repack_without_ref(const char *refname)
{
struct ref_list *list, *packed_ref_list;
int fd;
int found = 0;
packed_ref_list = get_packed_refs();
for (list = packed_ref_list; list; list = list->next) {
if (!strcmp(refname, list->name)) {
found = 1;
break;
}
}
if (!found)
return 0;
fd = hold_lock_file_for_update(&packlock, git_path("packed-refs"), 0);
if (fd < 0)
return error("cannot delete '%s' from packed refs", refname);
for (list = packed_ref_list; list; list = list->next) {
char line[PATH_MAX + 100];
int len;
if (!strcmp(refname, list->name))
continue;
len = snprintf(line, sizeof(line), "%s %s\n",
sha1_to_hex(list->sha1), list->name);
/* this should not happen but just being defensive */
if (len > sizeof(line))
die("too long a refname '%s'", list->name);
write_or_die(fd, line, len);
}
return commit_lock_file(&packlock);
}
开发者ID:girving,项目名称:git,代码行数:34,代码来源:refs.c
示例4: commit_ref
int commit_ref(struct ref_lock *lock)
{
if (commit_lock_file(lock->lk))
return -1;
lock->lock_fd = -1;
return 0;
}
开发者ID:girving,项目名称:git,代码行数:7,代码来源:refs.c
示例5: fetch_pack_setup
struct ref *fetch_pack(struct fetch_pack_args *my_args,
int fd[], struct child_process *conn,
const struct ref *ref,
const char *dest,
int nr_heads,
char **heads,
char **pack_lockfile)
{
struct stat st;
struct ref *ref_cpy;
fetch_pack_setup();
if (&args != my_args)
memcpy(&args, my_args, sizeof(args));
if (args.depth > 0) {
if (stat(git_path("shallow"), &st))
st.st_mtime = 0;
}
if (heads && nr_heads)
nr_heads = remove_duplicates(nr_heads, heads);
if (!ref) {
packet_flush(fd[1]);
die("no matching remote head");
}
ref_cpy = do_fetch_pack(fd, ref, nr_heads, heads, pack_lockfile);
if (args.depth > 0) {
struct cache_time mtime;
struct strbuf sb = STRBUF_INIT;
char *shallow = git_path("shallow");
int fd;
mtime.sec = st.st_mtime;
mtime.nsec = ST_MTIME_NSEC(st);
if (stat(shallow, &st)) {
if (mtime.sec)
die("shallow file was removed during fetch");
} else if (st.st_mtime != mtime.sec
#ifdef USE_NSEC
|| ST_MTIME_NSEC(st) != mtime.nsec
#endif
)
die("shallow file was changed during fetch");
fd = hold_lock_file_for_update(&lock, shallow,
LOCK_DIE_ON_ERROR);
if (!write_shallow_commits(&sb, 0)
|| write_in_full(fd, sb.buf, sb.len) != sb.len) {
unlink_or_warn(shallow);
rollback_lock_file(&lock);
} else {
commit_lock_file(&lock);
}
strbuf_release(&sb);
}
reprepare_packed_git();
return ref_cpy;
}
开发者ID:CinsonChen,项目名称:git,代码行数:60,代码来源:fetch-pack.c
示例6: fetch_pack_setup
struct ref *fetch_pack(struct fetch_pack_args *args,
int fd[], struct child_process *conn,
const struct ref *ref,
const char *dest,
struct ref **sought, int nr_sought,
char **pack_lockfile)
{
struct ref *ref_cpy;
fetch_pack_setup();
if (nr_sought)
nr_sought = remove_duplicates_in_refs(sought, nr_sought);
if (!ref) {
packet_flush(fd[1]);
die("no matching remote head");
}
ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, pack_lockfile);
if (alternate_shallow_file) {
if (*alternate_shallow_file == '\0') { /* --unshallow */
unlink_or_warn(git_path("shallow"));
rollback_lock_file(&shallow_lock);
} else
commit_lock_file(&shallow_lock);
}
reprepare_packed_git();
return ref_cpy;
}
开发者ID:ANKIT-KS,项目名称:git,代码行数:30,代码来源:fetch-pack.c
示例7: process_log_file
static void process_log_file(void)
{
struct stat st;
if (!fstat(get_lock_file_fd(&log_lock), &st) && st.st_size)
commit_lock_file(&log_lock);
else
rollback_lock_file(&log_lock);
}
开发者ID:9b,项目名称:git,代码行数:8,代码来源:gc.c
示例8: write_cache_as_tree
int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
{
int entries, was_valid, newfd;
struct lock_file *lock_file;
/*
* We can't free this memory, it becomes part of a linked list
* parsed atexit()
*/
lock_file = xcalloc(1, sizeof(struct lock_file));
newfd = hold_locked_index(lock_file, 1);
entries = read_cache();
if (entries < 0)
return WRITE_TREE_UNREADABLE_INDEX;
if (flags & WRITE_TREE_IGNORE_CACHE_TREE)
cache_tree_free(&(active_cache_tree));
if (!active_cache_tree)
active_cache_tree = cache_tree();
was_valid = cache_tree_fully_valid(active_cache_tree);
if (!was_valid) {
int missing_ok = flags & WRITE_TREE_MISSING_OK;
if (cache_tree_update(active_cache_tree,
active_cache, active_nr,
missing_ok, 0) < 0)
return WRITE_TREE_UNMERGED_INDEX;
if (0 <= newfd) {
if (!write_cache(newfd, active_cache, active_nr) &&
!commit_lock_file(lock_file))
newfd = -1;
}
/* Not being able to write is fine -- we are only interested
* in updating the cache-tree part, and if the next caller
* ends up using the old index with unupdated cache-tree part
* it misses the work we did here, but that is just a
* performance penalty and not a big deal.
*/
}
if (prefix) {
struct cache_tree *subtree =
cache_tree_find(active_cache_tree, prefix);
if (!subtree)
return WRITE_TREE_PREFIX_ERROR;
hashcpy(sha1, subtree->sha1);
}
else
hashcpy(sha1, active_cache_tree->sha1);
if (0 <= newfd)
rollback_lock_file(lock_file);
return 0;
}
开发者ID:777,项目名称:test-proj,代码行数:58,代码来源:cache-tree.c
示例9: commit_index_files
static int commit_index_files(void)
{
int err = 0;
switch (commit_style) {
case COMMIT_AS_IS:
break; /* nothing to do */
case COMMIT_NORMAL:
err = commit_lock_file(&index_lock);
break;
case COMMIT_PARTIAL:
err = commit_lock_file(&index_lock);
rollback_lock_file(&false_lock);
break;
}
return err;
}
开发者ID:AresDice,项目名称:git,代码行数:18,代码来源:commit.c
示例10: fetch_pack_setup
struct ref *fetch_pack(struct fetch_pack_args *my_args,
int fd[], struct child_process *conn,
const struct ref *ref,
const char *dest,
int nr_heads,
char **heads,
char **pack_lockfile)
{
struct stat st;
struct ref *ref_cpy;
fetch_pack_setup();
memcpy(&args, my_args, sizeof(args));
if (args.depth > 0) {
if (stat(git_path("shallow"), &st))
st.st_mtime = 0;
}
if (heads && nr_heads)
nr_heads = remove_duplicates(nr_heads, heads);
if (!ref) {
packet_flush(fd[1]);
die("no matching remote head");
}
ref_cpy = do_fetch_pack(fd, ref, nr_heads, heads, pack_lockfile);
if (args.depth > 0) {
struct cache_time mtime;
char *shallow = git_path("shallow");
int fd;
mtime.sec = st.st_mtime;
#ifdef USE_NSEC
mtime.usec = st.st_mtim.usec;
#endif
if (stat(shallow, &st)) {
if (mtime.sec)
die("shallow file was removed during fetch");
} else if (st.st_mtime != mtime.sec
#ifdef USE_NSEC
|| st.st_mtim.usec != mtime.usec
#endif
)
die("shallow file was changed during fetch");
fd = hold_lock_file_for_update(&lock, shallow, 1);
if (!write_shallow_commits(fd, 0)) {
unlink(shallow);
rollback_lock_file(&lock);
} else {
commit_lock_file(&lock);
}
}
reprepare_packed_git();
return ref_cpy;
}
开发者ID:Pistos,项目名称:git,代码行数:57,代码来源:builtin-fetch-pack.c
示例11: rewrite_credential_file
static void rewrite_credential_file(const char *fn, struct credential *c,
struct strbuf *extra)
{
if (hold_lock_file_for_update(&credential_lock, fn, 0) < 0)
die_errno("unable to get credential storage lock");
if (extra)
print_line(extra);
parse_credential_file(fn, c, NULL, print_line);
if (commit_lock_file(&credential_lock) < 0)
die_errno("unable to commit credential store");
}
开发者ID:4rch17,项目名称:git,代码行数:11,代码来源:credential-store.c
示例12: write_message
static void write_message(struct strbuf *msgbuf, const char *filename)
{
static struct lock_file msg_file;
int msg_fd = hold_lock_file_for_update(&msg_file, filename,
LOCK_DIE_ON_ERROR);
if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0)
die_errno(_("Could not write to %s"), filename);
strbuf_release(msgbuf);
if (commit_lock_file(&msg_file) < 0)
die(_("Error wrapping up %s."), filename);
}
开发者ID:64octets,项目名称:git,代码行数:12,代码来源:sequencer.c
示例13: save_head
static void save_head(const char *head)
{
static struct lock_file head_lock;
struct strbuf buf = STRBUF_INIT;
int fd;
fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), LOCK_DIE_ON_ERROR);
strbuf_addf(&buf, "%s\n", head);
if (write_in_full(fd, buf.buf, buf.len) < 0)
die_errno(_("Could not write to %s"), git_path_head_file());
if (commit_lock_file(&head_lock) < 0)
die(_("Error wrapping up %s."), git_path_head_file());
}
开发者ID:64octets,项目名称:git,代码行数:13,代码来源:sequencer.c
示例14: commit_locked_index
int commit_locked_index(struct lock_file *lk)
{
if (alternate_index_output) {
if (lk->fd >= 0 && close_lock_file(lk))
return -1;
if (rename(lk->filename, alternate_index_output))
return -1;
lk->filename[0] = 0;
return 0;
}
else
return commit_lock_file(lk);
}
开发者ID:Pistos,项目名称:git,代码行数:13,代码来源:lockfile.c
示例15: 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;
int ref_count = 0;
struct rev_info revs;
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 */
if (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv))
return -1;
argc = setup_revisions(argc, argv, &revs, NULL);
if (argc > 1)
return error(_("unrecognized argument: %s"), argv[1]);
object_array_remove_duplicates(&revs.pending);
ref_count = write_bundle_refs(bundle_fd, &revs);
if (!ref_count)
die(_("Refusing to create empty bundle."));
else if (ref_count < 0)
return -1;
/* write pack */
if (write_pack_data(bundle_fd, &lock, &revs))
return -1;
if (!bundle_to_stdout) {
if (commit_lock_file(&lock))
die_errno(_("cannot create '%s'"), path);
}
return 0;
}
开发者ID:86joca,项目名称:git,代码行数:50,代码来源:bundle.c
示例16: save_todo
static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
{
static struct lock_file todo_lock;
const char *todo_path = get_todo_path(opts);
int next = todo_list->current, offset, fd;
fd = hold_lock_file_for_update(&todo_lock, todo_path, 0);
if (fd < 0)
return error_errno(_("could not lock '%s'"), todo_path);
offset = next < todo_list->nr ?
todo_list->items[next].offset_in_buf : todo_list->buf.len;
if (write_in_full(fd, todo_list->buf.buf + offset,
todo_list->buf.len - offset) < 0)
return error_errno(_("could not write to '%s'"), todo_path);
if (commit_lock_file(&todo_lock) < 0)
return error(_("failed to finalize '%s'."), todo_path);
return 0;
}
开发者ID:dindinw,项目名称:git,代码行数:18,代码来源:sequencer.c
示例17: 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
示例18: save_todo
static void save_todo(struct commit_list *todo_list, struct replay_opts *opts)
{
static struct lock_file todo_lock;
struct strbuf buf = STRBUF_INIT;
int fd;
fd = hold_lock_file_for_update(&todo_lock, git_path_todo_file(), LOCK_DIE_ON_ERROR);
if (format_todo(&buf, todo_list, opts) < 0)
die(_("Could not format %s."), git_path_todo_file());
if (write_in_full(fd, buf.buf, buf.len) < 0) {
strbuf_release(&buf);
die_errno(_("Could not write to %s"), git_path_todo_file());
}
if (commit_lock_file(&todo_lock) < 0) {
strbuf_release(&buf);
die(_("Error wrapping up %s."), git_path_todo_file());
}
strbuf_release(&buf);
}
开发者ID:64octets,项目名称:git,代码行数:19,代码来源:sequencer.c
示例19: write_rr
static int write_rr(struct string_list *rr, int out_fd)
{
int i;
for (i = 0; i < rr->nr; i++) {
const char *path;
int length;
if (!rr->items[i].util)
continue;
path = rr->items[i].string;
length = strlen(path) + 1;
if (write_in_full(out_fd, rr->items[i].util, 40) != 40 ||
write_str_in_full(out_fd, "\t") != 1 ||
write_in_full(out_fd, path, length) != length)
die("unable to write rerere record");
}
if (commit_lock_file(&write_lock) != 0)
die("unable to write rerere record");
return 0;
}
开发者ID:AViscatanius,项目名称:git,代码行数:19,代码来源:rerere.c
示例20: save_head
static int save_head(const char *head)
{
static struct lock_file head_lock;
struct strbuf buf = STRBUF_INIT;
int fd;
fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), 0);
if (fd < 0) {
rollback_lock_file(&head_lock);
return error_errno(_("could not lock HEAD"));
}
strbuf_addf(&buf, "%s\n", head);
if (write_in_full(fd, buf.buf, buf.len) < 0) {
rollback_lock_file(&head_lock);
return error_errno(_("could not write to '%s'"),
git_path_head_file());
}
if (commit_lock_file(&head_lock) < 0) {
rollback_lock_file(&head_lock);
return error(_("failed to finalize '%s'."), git_path_head_file());
}
return 0;
}
开发者ID:dindinw,项目名称:git,代码行数:23,代码来源:sequencer.c
注:本文中的commit_lock_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论