这篇教程C++ strbuf_read_file函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中strbuf_read_file函数的典型用法代码示例。如果您正苦于以下问题:C++ strbuf_read_file函数的具体用法?C++ strbuf_read_file怎么用?C++ strbuf_read_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了strbuf_read_file函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: strbuf_addfstatic char *find_linked_symref(const char *symref, const char *branch, const char *id){ struct strbuf sb = STRBUF_INIT; struct strbuf path = STRBUF_INIT; struct strbuf gitdir = STRBUF_INIT; char *existing = NULL; /* * $GIT_COMMON_DIR/$symref (e.g. HEAD) is practically outside * $GIT_DIR so resolve_ref_unsafe() won't work (it uses * git_path). Parse the ref ourselves. */ if (id) strbuf_addf(&path, "%s/worktrees/%s/%s", get_git_common_dir(), id, symref); else strbuf_addf(&path, "%s/%s", get_git_common_dir(), symref); if (!strbuf_readlink(&sb, path.buf, 0)) { if (!starts_with(sb.buf, "refs/") || check_refname_format(sb.buf, 0)) goto done; } else if (strbuf_read_file(&sb, path.buf, 0) >= 0 && starts_with(sb.buf, "ref:")) { strbuf_remove(&sb, 0, strlen("ref:")); strbuf_trim(&sb); } else goto done; if (strcmp(sb.buf, branch)) goto done; if (id) { strbuf_reset(&path); strbuf_addf(&path, "%s/worktrees/%s/gitdir", get_git_common_dir(), id); if (strbuf_read_file(&gitdir, path.buf, 0) <= 0) goto done; strbuf_rtrim(&gitdir); } else strbuf_addstr(&gitdir, get_git_common_dir()); strbuf_strip_suffix(&gitdir, ".git"); existing = strbuf_detach(&gitdir, NULL);done: strbuf_release(&path); strbuf_release(&sb); strbuf_release(&gitdir); return existing;}
开发者ID:2quala,项目名称:git,代码行数:48,
示例2: diestatic struct worktree *get_linked_worktree(const char *id){ struct worktree *worktree = NULL; struct strbuf path = STRBUF_INIT; struct strbuf worktree_path = STRBUF_INIT; if (!id) die("Missing linked worktree name"); strbuf_git_common_path(&path, the_repository, "worktrees/%s/gitdir", id); if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0) /* invalid gitdir file */ goto done; strbuf_rtrim(&worktree_path); if (!strbuf_strip_suffix(&worktree_path, "/.git")) { strbuf_reset(&worktree_path); strbuf_add_absolute_path(&worktree_path, "."); strbuf_strip_suffix(&worktree_path, "/."); } strbuf_reset(&path); strbuf_addf(&path, "%s/worktrees/%s/HEAD", get_git_common_dir(), id); worktree = xcalloc(1, sizeof(*worktree)); worktree->path = strbuf_detach(&worktree_path, NULL); worktree->id = xstrdup(id); add_head_info(worktree);done: strbuf_release(&path); strbuf_release(&worktree_path); return worktree;}
开发者ID:PhilipOakley,项目名称:git,代码行数:34,
示例3: read_and_strip_branch/* * Extract branch information from rebase/bisect */static void read_and_strip_branch(struct strbuf *sb, const char **branch, const char *path){ unsigned char sha1[20]; strbuf_reset(sb); if (strbuf_read_file(sb, git_path("%s", path), 0) <= 0) return; while (sb->len && sb->buf[sb->len - 1] == '/n') strbuf_setlen(sb, sb->len - 1); if (!sb->len) return; if (!prefixcmp(sb->buf, "refs/heads/")) *branch = sb->buf + strlen("refs/heads/"); else if (!prefixcmp(sb->buf, "refs/")) *branch = sb->buf; else if (!get_sha1_hex(sb->buf, sha1)) { const char *abbrev; abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV); strbuf_reset(sb); strbuf_addstr(sb, abbrev); *branch = sb->buf; } else if (!strcmp(sb->buf, "detached HEAD")) /* rebase */ ; else /* bisect */ *branch = sb->buf;}
开发者ID:CoerWatt,项目名称:git,代码行数:32,
示例4: if/* * Extract branch information from rebase/bisect */static char *read_and_strip_branch(const char *path){ struct strbuf sb = STRBUF_INIT; unsigned char sha1[20]; if (strbuf_read_file(&sb, git_path("%s", path), 0) <= 0) goto got_nothing; while (&sb.len && sb.buf[sb.len - 1] == '/n') strbuf_setlen(&sb, sb.len - 1); if (!sb.len) goto got_nothing; if (!prefixcmp(sb.buf, "refs/heads/")) strbuf_remove(&sb,0, strlen("refs/heads/")); else if (!prefixcmp(sb.buf, "refs/")) ; else if (!get_sha1_hex(sb.buf, sha1)) { const char *abbrev; abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV); strbuf_reset(&sb); strbuf_addstr(&sb, abbrev); } else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */ goto got_nothing; else /* bisect */ ; return strbuf_detach(&sb, NULL);got_nothing: strbuf_release(&sb); return NULL;}
开发者ID:ANKIT-KS,项目名称:git,代码行数:34,
示例5: get_common_dir_noenvint get_common_dir_noenv(struct strbuf *sb, const char *gitdir){ struct strbuf data = STRBUF_INIT; struct strbuf path = STRBUF_INIT; int ret = 0; strbuf_addf(&path, "%s/commondir", gitdir); if (file_exists(path.buf)) { if (strbuf_read_file(&data, path.buf, 0) <= 0) die_errno(_("failed to read %s"), path.buf); while (data.len && (data.buf[data.len - 1] == '/n' || data.buf[data.len - 1] == '/r')) data.len--; data.buf[data.len] = '/0'; strbuf_reset(&path); if (!is_absolute_path(data.buf)) strbuf_addf(&path, "%s/", gitdir); strbuf_addbuf(&path, &data); strbuf_addstr(sb, real_path(path.buf)); ret = 1; } else strbuf_addstr(sb, gitdir); strbuf_release(&data); strbuf_release(&path); return ret;}
开发者ID:jiangxilong,项目名称:git,代码行数:26,
示例6: read_merge_msgstatic void read_merge_msg(struct strbuf *msg){ const char *filename = git_path("MERGE_MSG"); strbuf_reset(msg); if (strbuf_read_file(msg, filename, 0) < 0) die_errno(_("Could not read from '%s'"), filename);}
开发者ID:carey94tt,项目名称:git,代码行数:7,
示例7: stage_updated_gitmodulesvoid stage_updated_gitmodules(void){ struct strbuf buf = STRBUF_INIT; struct stat st; int pos; struct cache_entry *ce; int namelen = strlen(".gitmodules"); pos = cache_name_pos(".gitmodules", namelen); if (pos < 0) { warning(_("could not find .gitmodules in index")); return; } ce = active_cache[pos]; ce->ce_flags = namelen; if (strbuf_read_file(&buf, ".gitmodules", 0) < 0) die(_("reading updated .gitmodules failed")); if (lstat(".gitmodules", &st) < 0) die_errno(_("unable to stat updated .gitmodules")); fill_stat_cache_info(ce, &st); ce->ce_mode = ce_mode_from_stat(ce, st.st_mode); if (remove_cache_entry_at(pos) < 0) die(_("unable to remove .gitmodules from index")); if (write_sha1_file(buf.buf, buf.len, blob_type, ce->sha1)) die(_("adding updated .gitmodules failed")); if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE)) die(_("staging updated .gitmodules failed"));}
开发者ID:7sOddities,项目名称:git,代码行数:28,
示例8: launch_specified_editorstatic int launch_specified_editor(const char *editor, const char *path, struct strbuf *buffer, const char *const *env){ if (!editor) return error("Terminal is dumb, but EDITOR unset"); if (strcmp(editor, ":")) { const char *args[] = { editor, real_path(path), NULL }; struct child_process p = CHILD_PROCESS_INIT; int ret, sig; int print_waiting_for_editor = advice_waiting_for_editor && isatty(2); if (print_waiting_for_editor) { /* * A dumb terminal cannot erase the line later on. Add a * newline to separate the hint from subsequent output. * * Make sure that our message is separated with a whitespace * from further cruft that may be written by the editor. */ const char term = is_terminal_dumb() ? '/n' : ' '; fprintf(stderr, _("hint: Waiting for your editor to close the file...%c"), term); fflush(stderr); } p.argv = args; p.env = env; p.use_shell = 1; if (start_command(&p) < 0) return error("unable to start editor '%s'", editor); sigchain_push(SIGINT, SIG_IGN); sigchain_push(SIGQUIT, SIG_IGN); ret = finish_command(&p); sig = ret - 128; sigchain_pop(SIGINT); sigchain_pop(SIGQUIT); if (sig == SIGINT || sig == SIGQUIT) raise(sig); if (ret) return error("There was a problem with the editor '%s'.", editor); if (print_waiting_for_editor && !is_terminal_dumb()) /* * Go back to the beginning and erase the entire line to * avoid wasting the vertical space. */ fputs("/r/033[K", stderr); } if (!buffer) return 0; if (strbuf_read_file(buffer, path, 0) < 0) return error_errno("could not read file '%s'", path); return 0;}
开发者ID:PhilipOakley,项目名称:git,代码行数:60,
示例9: bisect_resetstatic int bisect_reset(const char *commit){ struct strbuf branch = STRBUF_INIT; if (!commit) { if (strbuf_read_file(&branch, git_path_bisect_start(), 0) < 1) { printf(_("We are not bisecting./n")); return 0; } strbuf_rtrim(&branch); } else { struct object_id oid; if (get_oid_commit(commit, &oid)) return error(_("'%s' is not a valid commit"), commit); strbuf_addstr(&branch, commit); } if (!file_exists(git_path_bisect_head())) { struct argv_array argv = ARGV_ARRAY_INIT; argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL); if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { strbuf_release(&branch); argv_array_clear(&argv); return error(_("could not check out original" " HEAD '%s'. Try 'git bisect" "reset <commit>'."), branch.buf); } argv_array_clear(&argv); } strbuf_release(&branch); return bisect_clean_state();}
开发者ID:bk2204,项目名称:git,代码行数:35,
示例10: is_expected_revstatic int is_expected_rev(const char *expected_hex){ struct strbuf actual_hex = STRBUF_INIT; int res = 0; if (strbuf_read_file(&actual_hex, git_path_bisect_expected_rev(), 0) >= 40) { strbuf_trim(&actual_hex); res = !strcmp(actual_hex.buf, expected_hex); } strbuf_release(&actual_hex); return res;}
开发者ID:bk2204,项目名称:git,代码行数:11,
示例11: parse_file_argstatic int parse_file_arg(const struct option *opt, const char *arg, int unset){ struct msg_arg *msg = opt->value; if (msg->buf.len) strbuf_addch(&(msg->buf), '/n'); if (!strcmp(arg, "-")) { if (strbuf_read(&(msg->buf), 0, 1024) < 0) die_errno("cannot read '%s'", arg); } else if (strbuf_read_file(&(msg->buf), arg, 1024) < 0) die_errno("could not open or read '%s'", arg); stripspace(&(msg->buf), 0); msg->given = 1; return 0;}
开发者ID:flichtenheld,项目名称:git,代码行数:16,
示例12: parse_file_argstatic int parse_file_arg(const struct option *opt, const char *arg, int unset){ struct note_data *d = opt->value; if (d->buf.len) strbuf_addch(&d->buf, '/n'); if (!strcmp(arg, "-")) { if (strbuf_read(&d->buf, 0, 1024) < 0) die_errno(_("cannot read '%s'"), arg); } else if (strbuf_read_file(&d->buf, arg, 1024) < 0) die_errno(_("could not open or read '%s'"), arg); strbuf_stripspace(&d->buf, 0); d->given = 1; return 0;}
开发者ID:ruester,项目名称:git,代码行数:16,
示例13: report_last_gc_errorstatic int report_last_gc_error(void){ struct strbuf sb = STRBUF_INIT; int ret; ret = strbuf_read_file(&sb, git_path("gc.log"), 0); if (ret > 0) return error(_("The last gc run reported the following. " "Please correct the root cause/n" "and remove %s./n" "Automatic cleanup will not be performed " "until the file is removed./n/n" "%s"), git_path("gc.log"), sb.buf); strbuf_release(&sb); return 0;}
开发者ID:9b,项目名称:git,代码行数:17,
示例14: diestatic struct worktree *get_linked_worktree(const char *id){ struct worktree *worktree = NULL; struct strbuf path = STRBUF_INIT; struct strbuf worktree_path = STRBUF_INIT; struct strbuf head_ref = STRBUF_INIT; int is_detached = 0; if (!id) die("Missing linked worktree name"); strbuf_git_common_path(&path, "worktrees/%s/gitdir", id); if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0) /* invalid gitdir file */ goto done; strbuf_rtrim(&worktree_path); if (!strbuf_strip_suffix(&worktree_path, "/.git")) { strbuf_reset(&worktree_path); strbuf_add_absolute_path(&worktree_path, "."); strbuf_strip_suffix(&worktree_path, "/."); } strbuf_reset(&path); strbuf_addf(&path, "%s/worktrees/%s/HEAD", get_git_common_dir(), id); if (parse_ref(path.buf, &head_ref, &is_detached) < 0) goto done; worktree = xmalloc(sizeof(struct worktree)); worktree->path = strbuf_detach(&worktree_path, NULL); worktree->id = xstrdup(id); worktree->is_bare = 0; worktree->head_ref = NULL; worktree->is_detached = is_detached; worktree->is_current = 0; add_head_info(&head_ref, worktree); worktree->lock_reason = NULL; worktree->lock_reason_valid = 0;done: strbuf_release(&path); strbuf_release(&worktree_path); strbuf_release(&head_ref); return worktree;}
开发者ID:9b,项目名称:git,代码行数:46,
示例15: template_untouched/* * See if the user edited the message in the editor or left what * was in the template intact */static int template_untouched(struct strbuf *sb){ struct strbuf tmpl = STRBUF_INIT; char *start; if (cleanup_mode == CLEANUP_NONE && sb->len) return 0; if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0) return 0; stripspace(&tmpl, cleanup_mode == CLEANUP_ALL); start = (char *)skip_prefix(sb->buf, tmpl.buf); if (!start) start = sb->buf; strbuf_release(&tmpl); return rest_is_empty(sb, start - sb->buf);}
开发者ID:AresDice,项目名称:git,代码行数:22,
示例16: report_last_gc_error/* * Returns 0 if there was no previous error and gc can proceed, 1 if * gc should not proceed due to an error in the last run. Prints a * message and returns -1 if an error occured while reading gc.log */static int report_last_gc_error(void){ struct strbuf sb = STRBUF_INIT; int ret = 0; ssize_t len; struct stat st; char *gc_log_path = git_pathdup("gc.log"); if (stat(gc_log_path, &st)) { if (errno == ENOENT) goto done; ret = error_errno(_("cannot stat '%s'"), gc_log_path); goto done; } if (st.st_mtime < gc_log_expire_time) goto done; len = strbuf_read_file(&sb, gc_log_path, 0); if (len < 0) ret = error_errno(_("cannot read '%s'"), gc_log_path); else if (len > 0) { /* * A previous gc failed. Report the error, and don't * bother with an automatic gc run since it is likely * to fail in the same way. */ warning(_("The last gc run reported the following. " "Please correct the root cause/n" "and remove %s./n" "Automatic cleanup will not be performed " "until the file is removed./n/n" "%s"), gc_log_path, sb.buf); ret = 1; } strbuf_release(&sb);done: free(gc_log_path); return ret;}
开发者ID:MichaelBlume,项目名称:git,代码行数:47,
示例17: launch_editorint launch_editor(const char *path, struct strbuf *buffer, const char *const *env){ const char *editor = git_editor(); if (!editor) return error("Terminal is dumb, but EDITOR unset"); if (strcmp(editor, ":")) { const char *args[] = { editor, path, NULL }; struct child_process p; int ret, sig; memset(&p, 0, sizeof(p)); p.argv = args; p.env = env; p.use_shell = 1; if (start_command(&p) < 0) return error("unable to start editor '%s'", editor); sigchain_push(SIGINT, SIG_IGN); sigchain_push(SIGQUIT, SIG_IGN); ret = finish_command(&p); sig = ret + 128; sigchain_pop(SIGINT); sigchain_pop(SIGQUIT); if (sig == SIGINT || sig == SIGQUIT) raise(sig); if (ret) return error("There was a problem with the editor '%s'.", editor); } if (!buffer) return 0; if (strbuf_read_file(buffer, path, 0) < 0) return error("could not read file '%s': %s", path, strerror(errno)); return 0;}
开发者ID:andersonvaz,项目名称:git,代码行数:39,
示例18: message_is_empty/* * Find out if the message starting at position 'start' in the strbuf * contains only whitespace and Signed-off-by lines. */static int message_is_empty(struct strbuf *sb, int start){ struct strbuf tmpl; const char *nl; int eol, i; if (cleanup_mode == CLEANUP_NONE && sb->len) return 0; /* See if the template is just a prefix of the message. */ strbuf_init(&tmpl, 0); if (template_file && strbuf_read_file(&tmpl, template_file, 0) > 0) { stripspace(&tmpl, cleanup_mode == CLEANUP_ALL); if (start + tmpl.len <= sb->len && memcmp(tmpl.buf, sb->buf + start, tmpl.len) == 0) start += tmpl.len; } strbuf_release(&tmpl); /* Check if the rest is just whitespace and Signed-of-by's. */ for (i = start; i < sb->len; i++) { nl = memchr(sb->buf + i, '/n', sb->len - i); if (nl) eol = nl - sb->buf; else eol = sb->len; if (strlen(sign_off_header) <= eol - i && !prefixcmp(sb->buf + i, sign_off_header)) { i = eol; continue; } while (i < eol) if (!isspace(sb->buf[i++])) return 0; } return 1;}
开发者ID:Jatinpurohit,项目名称:git,代码行数:43,
示例19: assertconst char *worktree_lock_reason(struct worktree *wt){ assert(!is_main_worktree(wt)); if (!wt->lock_reason_valid) { struct strbuf path = STRBUF_INIT; strbuf_addstr(&path, worktree_git_path(wt, "locked")); if (file_exists(path.buf)) { struct strbuf lock_reason = STRBUF_INIT; if (strbuf_read_file(&lock_reason, path.buf, 0) < 0) die_errno(_("failed to read '%s'"), path.buf); strbuf_trim(&lock_reason); wt->lock_reason = strbuf_detach(&lock_reason, NULL); } else wt->lock_reason = NULL; wt->lock_reason_valid = 1; strbuf_release(&path); } return wt->lock_reason;}
开发者ID:PhilipOakley,项目名称:git,代码行数:22,
示例20: rollback_is_safestatic int rollback_is_safe(void){ struct strbuf sb = STRBUF_INIT; struct object_id expected_head, actual_head; if (strbuf_read_file(&sb, git_path_abort_safety_file(), 0) >= 0) { strbuf_trim(&sb); if (get_oid_hex(sb.buf, &expected_head)) { strbuf_release(&sb); die(_("could not parse %s"), git_path_abort_safety_file()); } strbuf_release(&sb); } else if (errno == ENOENT) oidclr(&expected_head); else die_errno(_("could not read '%s'"), git_path_abort_safety_file()); if (get_oid("HEAD", &actual_head)) oidclr(&actual_head); return !oidcmp(&actual_head, &expected_head);}
开发者ID:dindinw,项目名称:git,代码行数:23,
示例21: parse_ref/* * read 'path_to_ref' into 'ref'. Also if is_detached is not NULL, * set is_detached to 1 (0) if the ref is detached (is not detached). * * $GIT_COMMON_DIR/$symref (e.g. HEAD) is practically outside $GIT_DIR so * for linked worktrees, `resolve_ref_unsafe()` won't work (it uses * git_path). Parse the ref ourselves. * * return -1 if the ref is not a proper ref, 0 otherwise (success) */static int parse_ref(char *path_to_ref, struct strbuf *ref, int *is_detached){ if (is_detached) *is_detached = 0; if (!strbuf_readlink(ref, path_to_ref, 0)) { /* HEAD is symbolic link */ if (!starts_with(ref->buf, "refs/") || check_refname_format(ref->buf, 0)) return -1; } else if (strbuf_read_file(ref, path_to_ref, 0) >= 0) { /* textual symref or detached */ if (!starts_with(ref->buf, "ref:")) { if (is_detached) *is_detached = 1; } else { strbuf_remove(ref, 0, strlen("ref:")); strbuf_trim(ref); if (check_refname_format(ref->buf, 0)) return -1; } } else return -1; return 0;}
开发者ID:9b,项目名称:git,代码行数:34,
示例22: read_oneliner/* * Reads a file that was presumably written by a shell script, i.e. with an * end-of-line marker that needs to be stripped. * * Note that only the last end-of-line marker is stripped, consistent with the * behavior of "$(cat path)" in a shell script. * * Returns 1 if the file was read, 0 if it could not be read or does not exist. */static int read_oneliner(struct strbuf *buf, const char *path, int skip_if_empty){ int orig_len = buf->len; if (!file_exists(path)) return 0; if (strbuf_read_file(buf, path, 0) < 0) { warning_errno(_("could not read '%s'"), path); return 0; } if (buf->len > orig_len && buf->buf[buf->len - 1] == '/n') { if (--buf->len > orig_len && buf->buf[buf->len - 1] == '/r') --buf->len; buf->buf[buf->len] = '/0'; } if (skip_if_empty && buf->len == orig_len) return 0; return 1;}
开发者ID:dindinw,项目名称:git,代码行数:33,
示例23: die/* * Unconditional writing of a plain regular file is what * "git difftool --dir-diff" wants to do for symlinks. We are preparing two * temporary directories to be fed to a Git-unaware tool that knows how to * show a diff of two directories (e.g. "diff -r A B"). * * Because the tool is Git-unaware, if a symbolic link appears in either of * these temporary directories, it will try to dereference and show the * difference of the target of the symbolic link, which is not what we want, * as the goal of the dir-diff mode is to produce an output that is logically * equivalent to what "git diff" produces. * * Most importantly, we want to get textual comparison of the result of the * readlink(2). get_symlink() provides that---it returns the contents of * the symlink that gets written to a regular file to force the external tool * to compare the readlink(2) result as text, even on a filesystem that is * capable of doing a symbolic link. */static char *get_symlink(const struct object_id *oid, const char *path){ char *data; if (is_null_oid(oid)) { /* The symlink is unknown to Git so read from the filesystem */ struct strbuf link = STRBUF_INIT; if (has_symlinks) { if (strbuf_readlink(&link, path, strlen(path))) die(_("could not read symlink %s"), path); } else if (strbuf_read_file(&link, path, 128)) die(_("could not read symlink file %s"), path); data = strbuf_detach(&link, NULL); } else { enum object_type type; unsigned long size; data = read_sha1_file(oid->hash, &type, &size); if (!data) die(_("could not read object %s for symlink %s"), oid_to_hex(oid), path); } return data;}
开发者ID:Litttle-butterfly,项目名称:git,代码行数:42,
示例24: read_cache/* * Prepare a dummy commit that represents the work tree (or staged) item. * Note that annotating work tree item never works in the reverse. */static struct commit *fake_working_tree_commit(struct diff_options *opt, const char *path, const char *contents_from){ struct commit *commit; struct blame_origin *origin; struct commit_list **parent_tail, *parent; struct object_id head_oid; struct strbuf buf = STRBUF_INIT; const char *ident; time_t now; int size, len; struct cache_entry *ce; unsigned mode; struct strbuf msg = STRBUF_INIT; read_cache(); time(&now); commit = alloc_commit_node(); commit->object.parsed = 1; commit->date = now; parent_tail = &commit->parents; if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL)) die("no such ref: HEAD"); parent_tail = append_parent(parent_tail, &head_oid); append_merge_parents(parent_tail); verify_working_tree_path(commit, path); origin = make_origin(commit, path); ident = fmt_ident("Not Committed Yet", "not.committed.yet", NULL, 0); strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000/n"); for (parent = commit->parents; parent; parent = parent->next) strbuf_addf(&msg, "parent %s/n", oid_to_hex(&parent->item->object.oid)); strbuf_addf(&msg, "author %s/n" "committer %s/n/n" "Version of %s from %s/n", ident, ident, path, (!contents_from ? path : (!strcmp(contents_from, "-") ? "standard input" : contents_from))); set_commit_buffer_from_strbuf(commit, &msg); if (!contents_from || strcmp("-", contents_from)) { struct stat st; const char *read_from; char *buf_ptr; unsigned long buf_len; if (contents_from) { if (stat(contents_from, &st) < 0) die_errno("Cannot stat '%s'", contents_from); read_from = contents_from; } else { if (lstat(path, &st) < 0) die_errno("Cannot lstat '%s'", path); read_from = path; } mode = canon_mode(st.st_mode); switch (st.st_mode & S_IFMT) { case S_IFREG: if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) && textconv_object(read_from, mode, &null_oid, 0, &buf_ptr, &buf_len)) strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1); else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size) die_errno("cannot open or read '%s'", read_from); break; case S_IFLNK: if (strbuf_readlink(&buf, read_from, st.st_size) < 0) die_errno("cannot readlink '%s'", read_from); break; default: die("unsupported file type %s", read_from); } } else { /* Reading from stdin */ mode = 0; if (strbuf_read(&buf, 0, 0) < 0) die_errno("failed to read from stdin"); } convert_to_git(path, buf.buf, buf.len, &buf, 0); origin->file.ptr = buf.buf; origin->file.size = buf.len; pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash); /* * Read the current index, replace the path entry with * origin->blob_sha1 without mucking with its mode or type * bits; we are not going to write this index out -- we just * want to run "diff-index --cached".//.........这里部分代码省略.........
开发者ID:basilgor,项目名称:git,代码行数:101,
示例25: prepare_to_commitstatic int prepare_to_commit(const char *index_file, const char *prefix, struct commit *current_head, struct wt_status *s, struct strbuf *author_ident){ struct stat statbuf; struct strbuf committer_ident = STRBUF_INIT; int commitable; struct strbuf sb = STRBUF_INIT; const char *hook_arg1 = NULL; const char *hook_arg2 = NULL; int clean_message_contents = (cleanup_mode != CLEANUP_NONE); int old_display_comment_prefix; /* This checks and barfs if author is badly specified */ determine_author_info(author_ident); if (!no_verify && run_hook(index_file, "pre-commit", NULL)) return 0; if (squash_message) { /* * Insert the proper subject line before other commit * message options add their content. */ if (use_message && !strcmp(use_message, squash_message)) strbuf_addstr(&sb, "squash! "); else { struct pretty_print_context ctx = {0}; struct commit *c; c = lookup_commit_reference_by_name(squash_message); if (!c) die(_("could not lookup commit %s"), squash_message); ctx.output_encoding = get_commit_output_encoding(); format_commit_message(c, "squash! %s/n/n", &sb, &ctx); } } if (message.len) { strbuf_addbuf(&sb, &message); hook_arg1 = "message"; } else if (logfile && !strcmp(logfile, "-")) { if (isatty(0)) fprintf(stderr, _("(reading log message from standard input)/n")); if (strbuf_read(&sb, 0, 0) < 0) die_errno(_("could not read log from standard input")); hook_arg1 = "message"; } else if (logfile) { if (strbuf_read_file(&sb, logfile, 0) < 0) die_errno(_("could not read log file '%s'"), logfile); hook_arg1 = "message"; } else if (use_message) { char *buffer; buffer = strstr(use_message_buffer, "/n/n"); if (!use_editor && (!buffer || buffer[2] == '/0')) die(_("commit has empty message")); strbuf_add(&sb, buffer + 2, strlen(buffer + 2)); hook_arg1 = "commit"; hook_arg2 = use_message; } else if (fixup_message) { struct pretty_print_context ctx = {0}; struct commit *commit; commit = lookup_commit_reference_by_name(fixup_message); if (!commit) die(_("could not lookup commit %s"), fixup_message); ctx.output_encoding = get_commit_output_encoding(); format_commit_message(commit, "fixup! %s/n/n", &sb, &ctx); hook_arg1 = "message"; } else if (!stat(git_path("MERGE_MSG"), &statbuf)) { if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0) die_errno(_("could not read MERGE_MSG")); hook_arg1 = "merge"; } else if (!stat(git_path("SQUASH_MSG"), &statbuf)) { if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0) die_errno(_("could not read SQUASH_MSG")); hook_arg1 = "squash"; } else if (template_file) { if (strbuf_read_file(&sb, template_file, 0) < 0) die_errno(_("could not read '%s'"), template_file); hook_arg1 = "template"; clean_message_contents = 0; } /* * The remaining cases don't modify the template message, but * just set the argument(s) to the prepare-commit-msg hook. */ else if (whence == FROM_MERGE) hook_arg1 = "merge"; else if (whence == FROM_CHERRY_PICK) { hook_arg1 = "commit"; hook_arg2 = "CHERRY_PICK_HEAD"; } if (squash_message) { /* * If squash_commit was used for the commit subject,//.........这里部分代码省略.........
开发者ID:AresDice,项目名称:git,代码行数:101,
示例26: cmd_commit//.........这里部分代码省略......... if (!current_head) { if (!reflog_msg) reflog_msg = "commit (initial)"; } else if (amend) { struct commit_list *c; if (!reflog_msg) reflog_msg = "commit (amend)"; for (c = current_head->parents; c; c = c->next) pptr = &commit_list_insert(c->item, pptr)->next; } else if (whence == FROM_MERGE) { struct strbuf m = STRBUF_INIT; FILE *fp; int allow_fast_forward = 1; if (!reflog_msg) reflog_msg = "commit (merge)"; pptr = &commit_list_insert(current_head, pptr)->next; fp = fopen(git_path("MERGE_HEAD"), "r"); if (fp == NULL) die_errno(_("could not open '%s' for reading"), git_path("MERGE_HEAD")); while (strbuf_getline(&m, fp, '/n') != EOF) { struct commit *parent; parent = get_merge_parent(m.buf); if (!parent) die(_("Corrupt MERGE_HEAD file (%s)"), m.buf); pptr = &commit_list_insert(parent, pptr)->next; } fclose(fp); strbuf_release(&m); if (!stat(git_path("MERGE_MODE"), &statbuf)) { if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0) die_errno(_("could not read MERGE_MODE")); if (!strcmp(sb.buf, "no-ff")) allow_fast_forward = 0; } if (allow_fast_forward) parents = reduce_heads(parents); } else { if (!reflog_msg) reflog_msg = (whence == FROM_CHERRY_PICK) ? "commit (cherry-pick)" : "commit"; pptr = &commit_list_insert(current_head, pptr)->next; } /* Finally, get the commit message */ strbuf_reset(&sb); if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) { int saved_errno = errno; rollback_index_files(); die(_("could not read commit message: %s"), strerror(saved_errno)); } /* Truncate the message just before the diff, if any. */ if (verbose) wt_status_truncate_message_at_cut_line(&sb); if (cleanup_mode != CLEANUP_NONE) stripspace(&sb, cleanup_mode == CLEANUP_ALL); if (template_untouched(&sb) && !allow_empty_message) { rollback_index_files(); fprintf(stderr, _("Aborting commit; you did not edit the message./n")); exit(1);
开发者ID:AresDice,项目名称:git,代码行数:67,
示例27: bisect_startstatic int bisect_start(struct bisect_terms *terms, int no_checkout, const char **argv, int argc){ int i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0; int flags, pathspec_pos, retval = 0; struct string_list revs = STRING_LIST_INIT_DUP; struct string_list states = STRING_LIST_INIT_DUP; struct strbuf start_head = STRBUF_INIT; struct strbuf bisect_names = STRBUF_INIT; struct object_id head_oid; struct object_id oid; const char *head; if (is_bare_repository()) no_checkout = 1; /* * Check for one bad and then some good revisions */ for (i = 0; i < argc; i++) { if (!strcmp(argv[i], "--")) { has_double_dash = 1; break; } } for (i = 0; i < argc; i++) { const char *arg = argv[i]; if (!strcmp(argv[i], "--")) { break; } else if (!strcmp(arg, "--no-checkout")) { no_checkout = 1; } else if (!strcmp(arg, "--term-good") || !strcmp(arg, "--term-old")) { must_write_terms = 1; free((void *) terms->term_good); terms->term_good = xstrdup(argv[++i]); } else if (skip_prefix(arg, "--term-good=", &arg) || skip_prefix(arg, "--term-old=", &arg)) { must_write_terms = 1; free((void *) terms->term_good); terms->term_good = xstrdup(arg); } else if (!strcmp(arg, "--term-bad") || !strcmp(arg, "--term-new")) { must_write_terms = 1; free((void *) terms->term_bad); terms->term_bad = xstrdup(argv[++i]); } else if (skip_prefix(arg, "--term-bad=", &arg) || skip_prefix(arg, "--term-new=", &arg)) { must_write_terms = 1; free((void *) terms->term_bad); terms->term_bad = xstrdup(arg); } else if (starts_with(arg, "--") && !one_of(arg, "--term-good", "--term-bad", NULL)) { return error(_("unrecognized option: '%s'"), arg); } else { char *commit_id = xstrfmt("%s^{commit}", arg); if (get_oid(commit_id, &oid) && has_double_dash) die(_("'%s' does not appear to be a valid " "revision"), arg); string_list_append(&revs, oid_to_hex(&oid)); free(commit_id); } } pathspec_pos = i; /* * The user ran "git bisect start <sha1> <sha1>", hence did not * explicitly specify the terms, but we are already starting to * set references named with the default terms, and won't be able * to change afterwards. */ if (revs.nr) must_write_terms = 1; for (i = 0; i < revs.nr; i++) { if (bad_seen) { string_list_append(&states, terms->term_good); } else { bad_seen = 1; string_list_append(&states, terms->term_bad); } } /* * Verify HEAD */ head = resolve_ref_unsafe("HEAD", 0, &head_oid, &flags); if (!head) if (get_oid("HEAD", &head_oid)) return error(_("bad HEAD - I need a HEAD")); /* * Check if we are bisecting */ if (!is_empty_or_missing_file(git_path_bisect_start())) { /* Reset to the rev from where we started */ strbuf_read_file(&start_head, git_path_bisect_start(), 0); strbuf_trim(&start_head); if (!no_checkout) {//.........这里部分代码省略.........
开发者ID:bk2204,项目名称:git,代码行数:101,
示例28: cmd_format_patch//.........这里部分代码省略......... continue; } if (ignore_if_in_upstream && has_commit_patch_id(commit, &ids)) continue; nr++; REALLOC_ARRAY(list, nr); list[nr - 1] = commit; } if (nr == 0) /* nothing to do */ return 0; total = nr; if (!keep_subject && auto_number && total > 1) numbered = 1; if (numbered) rev.total = total + start_number - 1; if (cover_letter == -1) { if (config_cover_letter == COVER_AUTO) cover_letter = (total > 1); else cover_letter = (config_cover_letter == COVER_ON); } if (!signature) { ; /* --no-signature inhibits all signatures */ } else if (signature && signature != git_version_string) { ; /* non-default signature already set */ } else if (signature_file) { struct strbuf buf = STRBUF_INIT; if (strbuf_read_file(&buf, signature_file, 128) < 0) die_errno(_("unable to read signature file '%s'"), signature_file); signature = strbuf_detach(&buf, NULL); } if (in_reply_to || thread || cover_letter) rev.ref_message_ids = xcalloc(1, sizeof(struct string_list)); if (in_reply_to) { const char *msgid = clean_message_id(in_reply_to); string_list_append(rev.ref_message_ids, msgid); } rev.numbered_files = just_numbers; rev.patch_suffix = fmt_patch_suffix; if (cover_letter) { if (thread) gen_message_id(&rev, "cover"); make_cover_letter(&rev, use_stdout, origin, nr, list, branch_name, quiet); total++; start_number--; } rev.add_signoff = do_signoff; while (0 <= --nr) { int shown; commit = list[nr]; rev.nr = total - nr + (start_number - 1); /* Make the second and subsequent mails replies to the first */ if (thread) { /* Have we already had a message ID? */ if (rev.message_id) { /* * For deep threading: make every mail * a reply to the previous one, no
开发者ID:AbelTian,项目名称:git,代码行数:67,
示例29: run_commitintrun_commit(int argc, char const* const* argv){ int result; char tmp_file_path[PATH_MAX]; struct strbuf buffer; struct string_list files; struct strbuf message; int fd; FILE* tmp_file; printf("commit!/n"); strcpy(tmp_file_path, "/tmp/commit.XXXXXX.fut"); fd = mkstemps(tmp_file_path, 4); if (fd == -1) { fprintf(stderr, "Error opening temp file: %s./n", tmp_file_path); return 1; } tmp_file = fdopen(fd, "w"); fprintf(tmp_file, "# Remove any files you don't want to commit, and enter a/n" "# commit message. To cancel, leave an empty commit message./n" "/n"); fprintf(tmp_file, "Files:/n"); write_file_status(tmp_file); fprintf(tmp_file, "/n"); fprintf(tmp_file, "Commit Message:/n/n"); fclose(tmp_file); result = launch_editor(tmp_file_path, NULL, NULL); printf("editor returned %d/n", result); if (result != 0) { fprintf(stderr, "result=%d/n", result); return 1; } strbuf_init(&buffer, 0); strbuf_init(&message, 0); memset(&files, 0, sizeof(struct string_list)); files.strdup_strings = 1; if (strbuf_read_file(&buffer, tmp_file_path, 0) < 0) { result = 1; fprintf(stderr, "Error reading temp file. %s/n", strerror(errno)); goto done; } printf("They wrote --[%s]--/n", buffer.buf); result = parse_commit(&buffer, &files, &message); if (result != 0) { fprintf(stderr, "Error parsing commit message./n"); result = 1; goto done; } if (message.len == 0 || files.nr == 0) { fprintf(stderr, "Commit aborted./n"); result = 1; goto done; } printf("file count %d/n", files.nr); print_string_list("files--", &files); printf("/nMessage --[[%s]]--/n", message.buf);done: strbuf_release(&buffer); strbuf_release(&message); string_list_clear(&files, 0); unlink(tmp_file_path); return result;}
开发者ID:joeo,项目名称:fut,代码行数:78,
示例30: read_merge_msgstatic void read_merge_msg(void){ strbuf_reset(&merge_msg); if (strbuf_read_file(&merge_msg, git_path("MERGE_MSG"), 0) < 0) die_errno("Could not read from '%s'", git_path("MERGE_MSG"));}
开发者ID:helloandre,项目名称:cr48,代码行数:6,
注:本文中的strbuf_read_file函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ strbuf_release函数代码示例 C++ strbuf_read函数代码示例 |