本文整理汇总了C++中parse_pathspec函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_pathspec函数的具体用法?C++ parse_pathspec怎么用?C++ parse_pathspec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_pathspec函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parse_args
static void parse_args(struct pathspec *pathspec,
const char **argv, const char *prefix,
int patch_mode,
const char **rev_ret)
{
const char *rev = "HEAD";
struct object_id unused;
/*
* Possible arguments are:
*
* git reset [-opts] [<rev>]
* git reset [-opts] <tree> [<paths>...]
* git reset [-opts] <tree> -- [<paths>...]
* git reset [-opts] -- [<paths>...]
* git reset [-opts] <paths>...
*
* At this point, argv points immediately after [-opts].
*/
if (argv[0]) {
if (!strcmp(argv[0], "--")) {
argv++; /* reset to HEAD, possibly with paths */
} else if (argv[1] && !strcmp(argv[1], "--")) {
rev = argv[0];
argv += 2;
}
/*
* Otherwise, argv[0] could be either <rev> or <paths> and
* has to be unambiguous. If there is a single argument, it
* can not be a tree
*/
else if ((!argv[1] && !get_oid_committish(argv[0], &unused)) ||
(argv[1] && !get_oid_treeish(argv[0], &unused))) {
/*
* Ok, argv[0] looks like a commit/tree; it should not
* be a filename.
*/
verify_non_filename(prefix, argv[0]);
rev = *argv++;
} else {
/* Otherwise we treat this as a filename */
verify_filename(prefix, argv[0], 1);
}
}
*rev_ret = rev;
if (read_cache() < 0)
die(_("index file corrupt"));
parse_pathspec(pathspec, 0,
PATHSPEC_PREFER_FULL |
(patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
prefix, argv);
}
开发者ID:guban,项目名称:git,代码行数:54,代码来源:reset.c
示例2: path_exists
static int path_exists(struct tree *tree, const char *path)
{
const char *paths[] = { path, NULL };
struct pathspec pathspec;
int ret;
parse_pathspec(&pathspec, 0, 0, "", paths);
pathspec.recursive = 1;
ret = read_tree_recursive(tree, "", 0, 0, &pathspec,
reject_entry, &pathspec);
free_pathspec(&pathspec);
return ret != 0;
}
开发者ID:AbelTian,项目名称:git,代码行数:13,代码来源:archive.c
示例3: 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
示例4: path_exists
static int path_exists(struct archiver_args *args, const char *path)
{
const char *paths[] = { path, NULL };
struct path_exists_context ctx;
int ret;
ctx.args = args;
parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
ctx.pathspec.recursive = 1;
ret = read_tree_recursive(args->tree, "", 0, 0, &ctx.pathspec,
reject_entry, &ctx);
clear_pathspec(&ctx.pathspec);
return ret != 0;
}
开发者ID:fcharlie,项目名称:git,代码行数:14,代码来源:archive.c
示例5: interactive_add
int interactive_add(int argc, const char **argv, const char *prefix, int patch)
{
struct pathspec pathspec;
parse_pathspec(&pathspec, 0,
PATHSPEC_PREFER_FULL |
PATHSPEC_SYMLINK_LEADING_PATH |
PATHSPEC_PREFIX_ORIGIN,
prefix, argv);
return run_add_interactive(NULL,
patch ? "--patch" : NULL,
&pathspec);
}
开发者ID:Noffica,项目名称:git,代码行数:14,代码来源:add.c
示例6: git_checkout_file
int git_checkout_file(const char *ref, const char *path, const char *outputpath)
{
struct cache_entry *ce;
int ret;
GIT_HASH sha1;
struct tree * root;
struct checkout state;
struct pathspec pathspec;
const char *matchbuf[1];
ret = get_sha1(ref, sha1);
if(ret)
return ret;
reprepare_packed_git();
root = parse_tree_indirect(sha1);
if(!root)
{
free_all_pack();
return -1;
}
ce = xcalloc(1, cache_entry_size(strlen(path)));
matchbuf[0] = NULL;
parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC, PATHSPEC_PREFER_CWD, path, matchbuf);
pathspec.items[0].nowildcard_len = pathspec.items[0].len;
ret = read_tree_recursive(root, "", 0, 0, &pathspec, update_some, ce);
free_pathspec(&pathspec);
if(ret)
{
free_all_pack();
free(ce);
return ret;
}
memset(&state, 0, sizeof(state));
state.force = 1;
state.refresh_cache = 0;
ret = write_entry(ce, outputpath, &state, 0);
free_all_pack();
free(ce);
return ret;
}
开发者ID:DinaraRigon,项目名称:TortoiseGit,代码行数:45,代码来源:gitdll.c
示例7: phoenixfs_open
static int phoenixfs_open(const char *path, struct fuse_file_info *fi)
{
int rev, fd;
FILE *infile, *fsfile;
char fspath[PATH_MAX];
struct file_record *fr;
char sha1_digest[40];
rev = parse_pathspec(xpath, path);
build_xpath(fspath, xpath, 0);
/* Skip zinflate for entries not in fstree */
if (!(fr = find_fr(xpath, rev)))
goto END;
/* Build openpath by hand */
print_sha1(sha1_digest, fr->sha1);
sprintf(openpath, "%s/.git/loose/%s", ROOTENV->fsback, sha1_digest);
if (access(openpath, F_OK) < 0) {
/* Try extracting from packfile */
sprintf(xpath, "%s/.git/loose", ROOTENV->fsback);
if (unpack_entry(fr->sha1, xpath) < 0)
return -ENOENT;
else
PHOENIXFS_DBG("open:: pack %s", sha1_digest);
}
else
PHOENIXFS_DBG("open:: loose %s", sha1_digest);
/* zinflate openpath onto fspath */
PHOENIXFS_DBG("open:: zinflate %s onto %s", sha1_digest, fspath);
if (!(infile = fopen(openpath, "rb")) ||
!(fsfile = fopen(fspath, "wb+")))
return -errno;
if (zinflate(infile, fsfile) != Z_OK)
PHOENIXFS_DBG("open:: zinflate issue");
fclose(infile);
fclose(fsfile);
END:
if ((fd = open(fspath, fi->flags)) < 0)
return -errno;
fi->fh = fd;
return 0;
}
开发者ID:artagnon,项目名称:phoenixfs,代码行数:44,代码来源:fuse.c
示例8: module_list_compute
static int module_list_compute(int argc, const char **argv,
const char *prefix,
struct pathspec *pathspec,
struct module_list *list)
{
int i, result = 0;
char *ps_matched = NULL;
parse_pathspec(pathspec, 0,
PATHSPEC_PREFER_FULL |
PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
prefix, argv);
if (pathspec->nr)
ps_matched = xcalloc(pathspec->nr, 1);
if (read_cache() < 0)
die(_("index file corrupt"));
for (i = 0; i < active_nr; i++) {
const struct cache_entry *ce = active_cache[i];
if (!S_ISGITLINK(ce->ce_mode) ||
!match_pathspec(pathspec, ce->name, ce_namelen(ce),
0, ps_matched, 1))
continue;
ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
list->entries[list->nr++] = ce;
while (i + 1 < active_nr &&
!strcmp(ce->name, active_cache[i + 1]->name))
/*
* Skip entries with the same name in different stages
* to make sure an entry is returned only once.
*/
i++;
}
if (ps_matched && report_path_error(ps_matched, pathspec, prefix))
result = -1;
free(ps_matched);
return result;
}
开发者ID:2572,项目名称:git,代码行数:44,代码来源:submodule--helper.c
示例9: parse_pathspec_arg
static void parse_pathspec_arg(const char **pathspec,
struct archiver_args *ar_args)
{
/*
* must be consistent with parse_pathspec in path_exists()
* Also if pathspec patterns are dependent, we're in big
* trouble as we test each one separately
*/
parse_pathspec(&ar_args->pathspec, 0,
PATHSPEC_PREFER_FULL,
"", pathspec);
if (pathspec) {
while (*pathspec) {
if (**pathspec && !path_exists(ar_args->tree, *pathspec))
die(_("pathspec '%s' did not match any files"), *pathspec);
pathspec++;
}
}
}
开发者ID:B-Rich,项目名称:git,代码行数:19,代码来源:archive.c
示例10: cmd_reset
int cmd_reset(int argc, const char **argv, const char *prefix)
{
int reset_type = NONE, update_ref_status = 0, quiet = 0;
int patch_mode = 0, nul_term_line = 0, read_from_stdin = 0, unborn;
char **stdin_paths = NULL;
int stdin_nr = 0, stdin_alloc = 0;
const char *rev;
struct object_id oid;
struct pathspec pathspec;
int intent_to_add = 0;
const struct option options[] = {
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
OPT_SET_INT(0, "mixed", &reset_type,
N_("reset HEAD and index"), MIXED),
OPT_SET_INT(0, "soft", &reset_type, N_("reset only HEAD"), SOFT),
OPT_SET_INT(0, "hard", &reset_type,
N_("reset HEAD, index and working tree"), HARD),
OPT_SET_INT(0, "merge", &reset_type,
N_("reset HEAD, index and working tree"), MERGE),
OPT_SET_INT(0, "keep", &reset_type,
N_("reset HEAD but keep local changes"), KEEP),
{ OPTION_CALLBACK, 0, "recurse-submodules", NULL,
"reset", "control recursive updating of submodules",
PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
OPT_BOOL('N', "intent-to-add", &intent_to_add,
N_("record only the fact that removed paths will be added later")),
OPT_BOOL('z', NULL, &nul_term_line,
N_("EXPERIMENTAL: paths are separated with NUL character")),
OPT_BOOL(0, "stdin", &read_from_stdin,
N_("EXPERIMENTAL: read paths from <stdin>")),
OPT_END()
};
git_config(git_reset_config, NULL);
argc = parse_options(argc, argv, prefix, options, git_reset_usage,
PARSE_OPT_KEEP_DASHDASH);
parse_args(&pathspec, argv, prefix, patch_mode, &rev);
if (read_from_stdin) {
strbuf_getline_fn getline_fn = nul_term_line ?
strbuf_getline_nul : strbuf_getline_lf;
int flags = PATHSPEC_PREFER_FULL;
struct strbuf buf = STRBUF_INIT;
struct strbuf unquoted = STRBUF_INIT;
if (patch_mode)
die(_("--stdin is incompatible with --patch"));
if (pathspec.nr)
die(_("--stdin is incompatible with path arguments"));
while (getline_fn(&buf, stdin) != EOF) {
if (!nul_term_line && buf.buf[0] == '"') {
strbuf_reset(&unquoted);
if (unquote_c_style(&unquoted, buf.buf, NULL))
die(_("line is badly quoted"));
strbuf_swap(&buf, &unquoted);
}
ALLOC_GROW(stdin_paths, stdin_nr + 1, stdin_alloc);
stdin_paths[stdin_nr++] = xstrdup(buf.buf);
strbuf_reset(&buf);
}
strbuf_release(&unquoted);
strbuf_release(&buf);
ALLOC_GROW(stdin_paths, stdin_nr + 1, stdin_alloc);
stdin_paths[stdin_nr++] = NULL;
flags |= PATHSPEC_LITERAL_PATH;
parse_pathspec(&pathspec, 0, flags, prefix,
(const char **)stdin_paths);
} else if (nul_term_line)
die(_("-z requires --stdin"));
unborn = !strcmp(rev, "HEAD") && get_oid("HEAD", &oid);
if (unborn) {
/* reset on unborn branch: treat as reset to empty tree */
hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
} else if (!pathspec.nr) {
struct commit *commit;
if (get_oid_committish(rev, &oid))
die(_("Failed to resolve '%s' as a valid revision."), rev);
commit = lookup_commit_reference(&oid);
if (!commit)
die(_("Could not parse object '%s'."), rev);
oidcpy(&oid, &commit->object.oid);
} else {
struct tree *tree;
if (get_oid_treeish(rev, &oid))
die(_("Failed to resolve '%s' as a valid tree."), rev);
tree = parse_tree_indirect(&oid);
if (!tree)
die(_("Could not parse object '%s'."), rev);
oidcpy(&oid, &tree->object.oid);
}
if (patch_mode) {
if (reset_type != NONE)
//.........这里部分代码省略.........
开发者ID:guban,项目名称:git,代码行数:101,代码来源:reset.c
示例11: cmd_add
int cmd_add(int argc, const char **argv, const char *prefix)
{
int exit_status = 0;
struct pathspec pathspec;
struct dir_struct dir;
int flags;
int add_new_files;
int require_pathspec;
char *seen = NULL;
struct lock_file lock_file = LOCK_INIT;
git_config(add_config, NULL);
argc = parse_options(argc, argv, prefix, builtin_add_options,
builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
if (patch_interactive)
add_interactive = 1;
if (add_interactive)
exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));
if (edit_interactive)
return(edit_patch(argc, argv, prefix));
argc--;
argv++;
if (0 <= addremove_explicit)
addremove = addremove_explicit;
else if (take_worktree_changes && ADDREMOVE_DEFAULT)
addremove = 0; /* "-u" was given but not "-A" */
if (addremove && take_worktree_changes)
die(_("-A and -u are mutually incompatible"));
if (!take_worktree_changes && addremove_explicit < 0 && argc)
/* Turn "git add pathspec..." to "git add -A pathspec..." */
addremove = 1;
if (!show_only && ignore_missing)
die(_("Option --ignore-missing can only be used together with --dry-run"));
if (chmod_arg && ((chmod_arg[0] != '-' && chmod_arg[0] != '+') ||
chmod_arg[1] != 'x' || chmod_arg[2]))
die(_("--chmod param '%s' must be either -x or +x"), chmod_arg);
add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize;
require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
(show_only ? ADD_CACHE_PRETEND : 0) |
(intent_to_add ? ADD_CACHE_INTENT : 0) |
(ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) |
(!(addremove || take_worktree_changes)
? ADD_CACHE_IGNORE_REMOVAL : 0));
if (require_pathspec && argc == 0) {
fprintf(stderr, _("Nothing specified, nothing added.\n"));
fprintf(stderr, _("Maybe you wanted to say 'git add .'?\n"));
return 0;
}
/*
* Check the "pathspec '%s' did not match any files" block
* below before enabling new magic.
*/
parse_pathspec(&pathspec, PATHSPEC_ATTR,
PATHSPEC_PREFER_FULL |
PATHSPEC_SYMLINK_LEADING_PATH,
prefix, argv);
if (read_cache_preload(&pathspec) < 0)
die(_("index file corrupt"));
die_in_unpopulated_submodule(&the_index, prefix);
die_path_inside_submodule(&the_index, &pathspec);
if (add_new_files) {
int baselen;
/* Set up the default git porcelain excludes */
memset(&dir, 0, sizeof(dir));
if (!ignored_too) {
dir.flags |= DIR_COLLECT_IGNORED;
setup_standard_excludes(&dir);
}
/* This picks up the paths that are not tracked */
baselen = fill_directory(&dir, &the_index, &pathspec);
if (pathspec.nr)
seen = prune_directory(&dir, &pathspec, baselen);
}
if (refresh_only) {
refresh(verbose, &pathspec);
goto finish;
}
if (pathspec.nr) {
int i;
//.........这里部分代码省略.........
开发者ID:Noffica,项目名称:git,代码行数:101,代码来源:add.c
示例12: cmd_ls_tree
int cmd_ls_tree(int argc, const char **argv, const char *prefix)
{
unsigned char sha1[20];
struct tree *tree;
int i, full_tree = 0;
const struct option ls_tree_options[] = {
OPT_BIT('d', NULL, &ls_options, N_("only show trees"),
LS_TREE_ONLY),
OPT_BIT('r', NULL, &ls_options, N_("recurse into subtrees"),
LS_RECURSIVE),
OPT_BIT('t', NULL, &ls_options, N_("show trees when recursing"),
LS_SHOW_TREES),
OPT_SET_INT('z', NULL, &line_termination,
N_("terminate entries with NUL byte"), 0),
OPT_BIT('l', "long", &ls_options, N_("include object size"),
LS_SHOW_SIZE),
OPT_BIT(0, "name-only", &ls_options, N_("list only filenames"),
LS_NAME_ONLY),
OPT_BIT(0, "name-status", &ls_options, N_("list only filenames"),
LS_NAME_ONLY),
OPT_SET_INT(0, "full-name", &chomp_prefix,
N_("use full path names"), 0),
OPT_BOOL(0, "full-tree", &full_tree,
N_("list entire tree; not just current directory "
"(implies --full-name)")),
OPT__ABBREV(&abbrev),
OPT_END()
};
git_config(git_default_config, NULL);
ls_tree_prefix = prefix;
if (prefix && *prefix)
chomp_prefix = strlen(prefix);
argc = parse_options(argc, argv, prefix, ls_tree_options,
ls_tree_usage, 0);
if (full_tree) {
ls_tree_prefix = prefix = NULL;
chomp_prefix = 0;
}
/* -d -r should imply -t, but -d by itself should not have to. */
if ( (LS_TREE_ONLY|LS_RECURSIVE) ==
((LS_TREE_ONLY|LS_RECURSIVE) & ls_options))
ls_options |= LS_SHOW_TREES;
if (argc < 1)
usage_with_options(ls_tree_usage, ls_tree_options);
if (get_sha1(argv[0], sha1))
die("Not a valid object name %s", argv[0]);
/*
* show_recursive() rolls its own matching code and is
* generally ignorant of 'struct pathspec'. The magic mask
* cannot be lifted until it is converted to use
* match_pathspec() or tree_entry_interesting()
*/
parse_pathspec(&pathspec, PATHSPEC_GLOB | PATHSPEC_ICASE |
PATHSPEC_EXCLUDE,
PATHSPEC_PREFER_CWD,
prefix, argv + 1);
for (i = 0; i < pathspec.nr; i++)
pathspec.items[i].nowildcard_len = pathspec.items[i].len;
pathspec.has_wildcard = 0;
tree = parse_tree_indirect(sha1);
if (!tree)
die("not a tree object");
return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
}
开发者ID:0369,项目名称:git,代码行数:68,代码来源:ls-tree.c
示例13: phoenixfs_release
static int phoenixfs_release(const char *path, struct fuse_file_info *fi)
{
struct file_record *fr;
FILE *infile, *outfile;
struct stat st;
unsigned char sha1[20];
char sha1_digest[40];
char outfilename[40];
char inpath[PATH_MAX];
char outpath[PATH_MAX];
int rev, ret;
pthread_mutex_lock(&phoenixfs_mutexlock);
/* Don't recursively backup history */
if ((rev = parse_pathspec(xpath, path))) {
PHOENIXFS_DBG("release:: history: %s", path);
/* Inflate the original version back onto the filesystem */
if (!(fr = find_fr(xpath, 0))) {
PHOENIXFS_DBG("release:: Can't find revision 0!");
pthread_mutex_unlock(&phoenixfs_mutexlock);
return 0;
}
print_sha1(sha1_digest, fr->sha1);
sprintf(inpath, "%s/.git/loose/%s", ROOTENV->fsback, sha1_digest);
build_xpath(outpath, xpath, 0);
if (!(infile = fopen(inpath, "rb")) ||
!(outfile = fopen(outpath, "wb+"))) {
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
PHOENIXFS_DBG("release:: history: zinflate %s onto %s",
sha1_digest, outpath);
rewind(infile);
rewind(outfile);
if (zinflate(infile, outfile) != Z_OK)
PHOENIXFS_DBG("release:: zinflate issue");
fflush(outfile);
fclose(infile);
fclose(outfile);
if (close(fi->fh) < 0) {
PHOENIXFS_DBG("release:: can't really close");
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
pthread_mutex_unlock(&phoenixfs_mutexlock);
return 0;
}
/* Attempt to create a backup */
build_xpath(xpath, path, 0);
if (!(infile = fopen(xpath, "rb")) ||
(lstat(xpath, &st) < 0)) {
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
if ((ret = sha1_file(infile, st.st_size, sha1)) < 0) {
fclose(infile);
pthread_mutex_unlock(&phoenixfs_mutexlock);
return ret;
}
print_sha1(outfilename, sha1);
sprintf(outpath, "%s/.git/loose/%s", ROOTENV->fsback, outfilename);
if (!access(outpath, F_OK)) {
/* SHA1 match; don't overwrite file as an optimization */
PHOENIXFS_DBG("release:: not overwriting: %s", outpath);
goto END;
}
if (!(outfile = fopen(outpath, "wb"))) {
fclose(infile);
pthread_mutex_unlock(&phoenixfs_mutexlock);
return -errno;
}
/* Rewind and seek back */
rewind(infile);
PHOENIXFS_DBG("release:: zdeflate %s onto %s", xpath, outfilename);
if (zdeflate(infile, outfile, -1) != Z_OK)
PHOENIXFS_DBG("release:: zdeflate issue");
mark_for_packing(sha1, st.st_size);
fclose(outfile);
END:
fclose(infile);
if (close(fi->fh) < 0) {
PHOENIXFS_DBG("release:: can't really close");
return -errno;
}
/* Update the fstree */
fstree_insert_update_file(path, NULL);
pthread_mutex_unlock(&phoenixfs_mutexlock);
return 0;
}
开发者ID:artagnon,项目名称:phoenixfs,代码行数:97,代码来源:fuse.c
示例14: blame_origin_incref
/*
* We have an origin -- check if the same path exists in the
* parent and return an origin structure to represent it.
*/
static struct blame_origin *find_origin(struct commit *parent,
struct blame_origin *origin)
{
struct blame_origin *porigin;
struct diff_options diff_opts;
const char *paths[2];
/* First check any existing origins */
for (porigin = parent->util; porigin; porigin = porigin->next)
if (!strcmp(porigin->path, origin->path)) {
/*
* The same path between origin and its parent
* without renaming -- the most common case.
*/
return blame_origin_incref (porigin);
}
/* See if the origin->path is different between parent
* and origin first. Most of the time they are the
* same and diff-tree is fairly efficient about this.
*/
diff_setup(&diff_opts);
DIFF_OPT_SET(&diff_opts, RECURSIVE);
diff_opts.detect_rename = 0;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
paths[0] = origin->path;
paths[1] = NULL;
parse_pathspec(&diff_opts.pathspec,
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
PATHSPEC_LITERAL_PATH, "", paths);
diff_setup_done(&diff_opts);
if (is_null_oid(&origin->commit->object.oid))
do_diff_cache(&parent->tree->object.oid, &diff_opts);
else
diff_tree_oid(&parent->tree->object.oid,
&origin->commit->tree->object.oid,
"", &diff_opts);
diffcore_std(&diff_opts);
if (!diff_queued_diff.nr) {
/* The path is the same as parent */
porigin = get_origin(parent, origin->path);
oidcpy(&porigin->blob_oid, &origin->blob_oid);
porigin->mode = origin->mode;
} else {
/*
* Since origin->path is a pathspec, if the parent
* commit had it as a directory, we will see a whole
* bunch of deletion of files in the directory that we
* do not care about.
*/
int i;
struct diff_filepair *p = NULL;
for (i = 0; i < diff_queued_diff.nr; i++) {
const char *name;
p = diff_queued_diff.queue[i];
name = p->one->path ? p->one->path : p->two->path;
if (!strcmp(name, origin->path))
break;
}
if (!p)
die("internal error in blame::find_origin");
switch (p->status) {
default:
die("internal error in blame::find_origin (%c)",
p->status);
case 'M':
porigin = get_origin(parent, origin->path);
oidcpy(&porigin->blob_oid, &p->one->oid);
porigin->mode = p->one->mode;
break;
case 'A':
case 'T':
/* Did not exist in parent, or type changed */
break;
}
}
diff_flush(&diff_opts);
clear_pathspec(&diff_opts.pathspec);
return porigin;
}
开发者ID:basilgor,项目名称:git,代码行数:87,代码来源:blame.c
示例15: try_to_follow_renames
static void try_to_follow_renames(const struct object_id *old_oid,
const struct object_id *new_oid,
struct strbuf *base, struct diff_options *opt)
{
struct diff_options diff_opts;
struct diff_queue_struct *q = &diff_queued_diff;
struct diff_filepair *choice;
int i;
/*
* follow-rename code is very specific, we need exactly one
* path. Magic that matches more than one path is not
* supported.
*/
GUARD_PATHSPEC(&opt->pathspec, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
#if 0
/*
* We should reject wildcards as well. Unfortunately we
* haven't got a reliable way to detect that 'foo\*bar' in
* fact has no wildcards. nowildcard_len is merely a hint for
* optimization. Let it slip for now until wildmatch is taught
* about dry-run mode and returns wildcard info.
*/
if (opt->pathspec.has_wildcard)
die("BUG:%s:%d: wildcards are not supported",
__FILE__, __LINE__);
#endif
/* Remove the file creation entry from the diff queue, and remember it */
choice = q->queue[0];
q->nr = 0;
diff_setup(&diff_opts);
diff_opts.flags.recursive = 1;
diff_opts.flags.find_copies_harder = 1;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_opts.single_follow = opt->pathspec.items[0].match;
diff_opts.break_opt = opt->break_opt;
diff_opts.rename_score = opt->rename_score;
diff_setup_done(&diff_opts);
ll_diff_tree_oid(old_oid, new_oid, base, &diff_opts);
diffcore_std(&diff_opts);
clear_pathspec(&diff_opts.pathspec);
/* Go through the new set of filepairing, and see if we find a more interesting one */
opt->found_follow = 0;
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
/*
* Found a source? Not only do we use that for the new
* diff_queued_diff, we will also use that as the path in
* the future!
*/
if ((p->status == 'R' || p->status == 'C') &&
!strcmp(p->two->path, opt->pathspec.items[0].match)) {
const char *path[2];
/* Switch the file-pairs around */
q->queue[i] = choice;
choice = p;
/* Update the path we use from now on.. */
path[0] = p->one->path;
path[1] = NULL;
clear_pathspec(&opt->pathspec);
parse_pathspec(&opt->pathspec,
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
PATHSPEC_LITERAL_PATH, "", path);
/*
* The caller expects us to return a set of vanilla
* filepairs to let a later call to diffcore_std()
* it makes to sort the renames out (among other
* things), but we already have found renames
* ourselves; signal diffcore_std() not to muck with
* rename information.
*/
opt->found_follow = 1;
break;
}
}
/*
* Then, discard all the non-relevant file pairs...
*/
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
diff_free_filepair(p);
}
/*
* .. and re-instate the one we want (which might be either the
* original one, or the rename/copy we found)
*/
q->queue[0] = choice;
q->nr = 1;
}
开发者ID:DoWonJin,项目名称:git,代码行数:98,代码来源:tree-diff.c
示例16: cmd_checkout
//.........这里部分代码省略.........
/* --track without -b/-B/--orphan should DWIM */
if (opts.track != BRANCH_TRACK_UNSPECIFIED && !opts.new_branch) {
const char *argv0 = argv[0];
if (!argc || !strcmp(argv0, "--"))
die(_("--track needs a branch name"));
skip_prefix(argv0, "refs/", &argv0);
skip_prefix(argv0, "remotes/", &argv0);
argv0 = strchr(argv0, '/');
if (!argv0 || !argv0[1])
die(_("missing branch name; try -b"));
opts.new_branch = argv0 + 1;
}
/*
* Extract branch name from command line arguments, so
* all that is left is pathspecs.
*
* Handle
*
* 1) git checkout <tree> -- [<paths>]
* 2) git checkout -- [<paths>]
* 3) git checkout <something> [<paths>]
*
* including "last branch" syntax and DWIM-ery for names of
* remote branches, erroring out for invalid or ambiguous cases.
*/
if (argc) {
struct object_id rev;
int dwim_ok =
!opts.patch_mode &&
dwim_new_local_branch &&
opts.track == BRANCH_TRACK_UNSPECIFIED &&
!opts.new_branch;
int n = parse_branchname_arg(argc, argv, dwim_ok,
&new_branch_info, &opts, &rev,
&dwim_remotes_matched);
argv += n;
argc -= n;
}
if (argc) {
parse_pathspec(&opts.pathspec, 0,
opts.patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0,
prefix, argv);
if (!opts.pathspec.nr)
die(_("invalid path specification"));
/*
* Try to give more helpful suggestion.
* new_branch && argc > 1 will be caught later.
*/
if (opts.new_branch && argc == 1)
die(_("'%s' is not a commit and a branch '%s' cannot be created from it"),
argv[0], opts.new_branch);
if (opts.force_detach)
die(_("git checkout: --detach does not take a path argument '%s'"),
argv[0]);
if (1 < !!opts.writeout_stage + !!opts.force + !!opts.merge)
die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\n"
"checking out of the index."));
}
if (opts.new_branch) {
struct strbuf buf = STRBUF_INIT;
if (opts.new_branch_force)
opts.branch_exists = validate_branchname(opts.new_branch, &buf);
else
opts.branch_exists =
validate_new_branchname(opts.new_branch, &buf, 0);
strbuf_release(&buf);
}
UNLEAK(opts);
if (opts.patch_mode || opts.pathspec.nr) {
int ret = checkout_paths(&opts, new_branch_info.name);
if (ret && dwim_remotes_matched > 1 &&
advice_checkout_ambiguous_remote_branch_name)
advise(_("'%s' matched more than one remote tracking branch.\n"
"We found %d remotes with a reference that matched. So we fell back\n"
"on trying to resolve the argument as a path, but failed there too!\n"
"\n"
"If you meant to check out a remote tracking branch on, e.g. 'origin',\n"
"you can do so by fully qualifying the name with the --track option:\n"
"\n"
" git checkout --track origin/<name>\n"
"\n"
"If you'd like to always have checkouts of an ambiguous <name> prefer\n"
"one remote, e.g. the 'origin' remote, consider setting\n"
"checkout.defaultRemote=origin in your config."),
argv[0],
dwim_remotes_matched);
return ret;
} else {
return checkout_branch(&opts, &new_branch_info);
}
}
开发者ID:Noffica,项目名称:git,代码行数:101,代码来源:checkout.c
示例17: cmd_rerere
int cmd_rerere(int argc, const char **argv, const char *prefix)
{
struct string_list merge_rr = STRING_LIST_INIT_DUP;
int i, fd, autoupdate = -1, flags = 0;
struct option options[] = {
OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
N_("register clean resolutions in index"), 1),
OPT_END(),
};
argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
git_config(git_xmerge_config, NULL);
if (autoupdate == 1)
flags = RERERE_AUTOUPDATE;
if (autoupdate == 0)
flags = RERERE_NOAUTOUPDATE;
if (argc < 1)
return rerere(flags);
if (!strcmp(argv[0], "forget")) {
struct pathspec pathspec;
if (argc < 2)
warning("'git rerere forget' without paths is deprecated");
parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD,
prefix, argv + 1);
return rerere_forget(&pathspec);
}
fd = setup_rerere(&merge_rr, flags);
if (fd < 0)
return 0;
if (!strcmp(argv[0], "clear")) {
rerere_clear(&merge_rr);
} else if (!strcmp(argv[0], "gc"))
rerere_gc(&merge_rr);
else if (!strcmp(argv[0], "status"))
for (i = 0; i < merge_rr.nr; i++)
printf("%s\n", merge_rr.items[i].string);
else if (!strcmp(argv[0], "remaining")) {
rerere_remaining(&merge_rr);
for (i = 0; i < merge_rr.nr; i++) {
if (merge_rr.items[i].util != RERERE_RESOLVED)
printf("%s\n", merge_rr.items[i].string);
else
/* prepare for later call to
* string_list_clear() */
merge_rr.items[i].util = NULL;
}
} else if (!strcmp(argv[0], "diff"))
for (i = 0; i < merge_rr.nr; i++) {
const char *path = merge_rr.items[i].string;
const char *name = (const char *)merge_rr.items[i].util;
diff_two(rerere_path(name, "preimage"), path, path, path);
}
else
usage_with_options(rerere_usage, options);
string_list_clear(&merge_rr, 1);
return 0;
}
开发者ID:120011676,项目名称:git,代码行数:65,代码来源:rerere.c
示例18: cmd_status
int cmd_status(int argc, const char **argv, const char *prefix)
{
static struct wt_status s;
int fd;
unsigned char sha1[20];
static struct option builtin_status_options[] = {
OPT__VERBOSE(&verbose, N_("be verbose")),
OPT_SET_INT('s', "short", &status_format,
N_("show status concisely"), STATUS_FORMAT_SHORT),
OPT_BOOL('b', "branch", &s.show_branch,
N_("show branch information")),
OPT_SET_INT(0, "porcelain", &status_format,
N_("machine-readable output"),
STATUS_FORMAT_PORCELAIN),
OPT_SET_INT(0, "long", &status_format,
N_("show status in long format (default)"),
STATUS_FORMAT_LONG),
OPT_BOOL('z', "null", &s.null_termination,
N_("terminate entries with NUL")),
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
N_("mode"),
N_("show untracked files, optional modes: all, normal, no. (Default: all)"),
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
OPT_BOOL(0, "ignored", &show_ignored_in_status,
N_("show ignored files")),
{ OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, N_("when"),
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
OPT_END(),
};
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_status_usage, builtin_status_options);
status_init_config(&s, git_status_config);
argc = parse_options(argc, argv, prefix,
builtin_status_options,
builtin_status_usage, 0);
finalize_colopts(&s.colopts, -1);
finalize_deferred_config(&s);
handle_untracked_files_arg(&s);
if (show_ignored_in_status)
s.show_ignored_files = 1;
parse_pathspec(&s.pathspec, 0,
PATHSPEC_PREFER_FULL,
prefix, argv);
read_cache_preload(&s.pathspec);
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
fd = hold_locked_index(&index_lock, 0);
if (0 <= fd)
update_index_if_able(&the_index, &index_lock);
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
s.ignore_submodule_arg = ignore_submodule_arg;
wt_status_collect(&s);
if (s.relative_paths)
s.prefix = prefix;
switch (status_format) {
case STATUS_FORMAT_SHORT:
wt_shortstatus_print(&s);
break;
case STATUS_FORMAT_PORCELAIN:
wt_porcelain_print(&s);
break;
case STATUS_FORMAT_UNSPECIFIED:
die("BUG: finalize_deferred_config() should have been called");
break;
case STATUS_FORMAT_NONE:
case STATUS_FORMAT_LONG:
s.verbose = verbose;
s.ignore_submodule_arg = ignore_submodule_arg;
wt_status_print(&s);
break;
}
return 0;
}
开发者ID:AresDice,项目名称:git,代码行数:82,代码来源:commit.c
示例19: cmd_rm
int cmd_rm(int argc, const char **argv, const char *prefix)
{
int i;
struct pathspec pathspec;
char *seen;
gitmodules_config();
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, builtin_rm_options,
builtin_rm_usage, 0);
if (!argc)
usage_with_options(builtin_rm_usage, builtin_rm_options);
if (!index_only)
setup_work_tree();
hold_locked_index(&lock_file, 1);
if (read_cache() < 0)
die(_("index file corrupt"));
parse_pathspec(&pathspec, 0,
PATHSPEC_PREFER_CWD |
PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
prefix, argv);
refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
seen = xcalloc(pathspec.nr, 1);
for (i = 0; i < active_nr; i++) {
const struct cache_entry *ce = active_cache[i];
if (!ce_path_match(ce, &pathspec, seen))
continue;
ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
list.entry[list.nr].name = xstrdup(ce->name);
list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);
if (list.entry[list.nr++].is_submodule &&
!is_staging_gitmodules_ok())
die (_("Please stage your changes to .gitmodules or stash them to proceed"));
}
if (pathspec.nr) {
const char *original;
int seen_any = 0;
for (i = 0; i < pathspec.nr; i++) {
original = pathspec.items[i].original;
if (!seen[i]) {
if (!ignore_unmatch) {
die(_("pathspec '%s' did not match any files"),
original);
}
}
else {
seen_any = 1;
}
if (!recursive && seen[i] == MATCHED_RECURSIVELY)
die(_("not removing '%s' recursively without -r"),
*original ? original : ".");
}
if (!seen_any)
exit(0);
}
/*
* If not forced, the file, the index and the HEAD (if exists)
* must match; but the file can already been removed, since
* this sequence is a natural "novice" way:
*
* rm F; git rm F
*
* Further, if HEAD commit exists, "diff-index --cached" must
* report no changes unless forced.
*/
if (!force) {
unsigned char sha1[20];
if (get_sha1("HEAD", sha1))
hashclr(sha1);
if (check_local_mod(sha1, index_only))
exit(1);
} else if (!index_only) {
if (check_submodules_use_gitfiles())
exit(1);
}
/*
* First remove the names from the index: we won't commit
* the index unless all of them succeed.
*/
for (i = 0; i < list.nr; i++) {
const char *path = list.entry[i].name;
if (!quiet)
printf("rm '%s'\n", path);
if (remove_file_from_cache(path))
die(_("git rm: unable to remove %s"), path);
}
if (show_only)
//.........这里部分代码省略.........
开发者ID:136357477,项目名称:git,代码行数:101,代码来源:rm.c
|
请发表评论