本文整理汇总了C++中read_cache函数的典型用法代码示例。如果您正苦于以下问题:C++ read_cache函数的具体用法?C++ read_cache怎么用?C++ read_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_cache函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: prepare_to_commit
//.........这里部分代码省略.........
status_printf_ln(s, GIT_COLOR_NORMAL,
"%s", only_include_assumed);
ai_tmp = cut_ident_timestamp_part(author_ident->buf);
ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
if (strcmp(author_ident->buf, committer_ident.buf))
status_printf_ln(s, GIT_COLOR_NORMAL,
_("%s"
"Author: %s"),
ident_shown++ ? "" : "\n",
author_ident->buf);
if (!committer_ident_sufficiently_given())
status_printf_ln(s, GIT_COLOR_NORMAL,
_("%s"
"Committer: %s"),
ident_shown++ ? "" : "\n",
committer_ident.buf);
if (ident_shown)
status_printf_ln(s, GIT_COLOR_NORMAL, "");
saved_color_setting = s->use_color;
s->use_color = 0;
commitable = run_status(s->fp, index_file, prefix, 1, s);
s->use_color = saved_color_setting;
*ai_tmp = ' ';
*ci_tmp = ' ';
} else {
unsigned char sha1[20];
const char *parent = "HEAD";
if (!active_nr && read_cache() < 0)
die(_("Cannot read index"));
if (amend)
parent = "HEAD^1";
if (get_sha1(parent, sha1))
commitable = !!active_nr;
else
commitable = index_differs_from(parent, 0);
}
strbuf_release(&committer_ident);
fclose(s->fp);
/*
* Reject an attempt to record a non-merge empty commit without
* explicit --allow-empty. In the cherry-pick case, it may be
* empty due to conflict resolution, which the user should okay.
*/
if (!commitable && whence != FROM_MERGE && !allow_empty &&
!(amend && is_a_merge(current_head))) {
s->display_comment_prefix = old_display_comment_prefix;
run_status(stdout, index_file, prefix, 0, s);
if (amend)
fputs(_(empty_amend_advice), stderr);
else if (whence == FROM_CHERRY_PICK) {
fputs(_(empty_cherry_pick_advice), stderr);
if (!sequencer_in_use)
fputs(_(empty_cherry_pick_advice_single), stderr);
else
fputs(_(empty_cherry_pick_advice_multi), stderr);
}
开发者ID:AlanRu,项目名称:git,代码行数:67,代码来源:commit.c
示例2: cmd_update_index
//.........这里部分代码省略.........
(parse_opt_cb *) unresolve_callback},
{OPTION_LOWLEVEL_CALLBACK, 'g', "again", &has_errors, NULL,
N_("only update entries that differ from HEAD"),
PARSE_OPT_NONEG | PARSE_OPT_NOARG,
(parse_opt_cb *) reupdate_callback},
OPT_BIT(0, "ignore-missing", &refresh_args.flags,
N_("ignore files missing from worktree"),
REFRESH_IGNORE_MISSING),
OPT_SET_INT(0, "verbose", &verbose,
N_("report actions to standard output"), 1),
{OPTION_CALLBACK, 0, "clear-resolve-undo", NULL, NULL,
N_("(for porcelains) forget saved unresolved conflicts"),
PARSE_OPT_NOARG | PARSE_OPT_NONEG,
resolve_undo_clear_callback},
OPT_INTEGER(0, "index-version", &preferred_index_format,
N_("write index in this format")),
OPT_BOOL(0, "split-index", &split_index,
N_("enable or disable split index")),
OPT_END()
};
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(update_index_usage, options);
git_config(git_default_config, NULL);
/* 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, 0);
if (newfd < 0)
lock_error = errno;
entries = read_cache();
if (entries < 0)
die("cache corrupted");
/*
* Custom copy of parse_options() because we want to handle
* filename arguments as they come.
*/
parse_options_start(&ctx, argc, argv, prefix,
options, PARSE_OPT_STOP_AT_NON_OPTION);
while (ctx.argc) {
if (parseopt_state != PARSE_OPT_DONE)
parseopt_state = parse_options_step(&ctx, options,
update_index_usage);
if (!ctx.argc)
break;
switch (parseopt_state) {
case PARSE_OPT_HELP:
exit(129);
case PARSE_OPT_NON_OPTION:
case PARSE_OPT_DONE:
{
const char *path = ctx.argv[0];
const char *p;
setup_work_tree();
p = prefix_path(prefix, prefix_length, path);
update_one(p);
if (set_executable_bit)
chmod_path(set_executable_bit, p);
free((char *)p);
ctx.argc--;
ctx.argv++;
开发者ID:asdlei00,项目名称:git-1,代码行数:67,代码来源:update-index.c
示例3: cmd_rm
int cmd_rm(int argc, const char **argv, const char *prefix)
{
int i, newfd;
const char **pathspec;
char *seen;
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();
newfd = hold_locked_index(&lock_file, 1);
if (read_cache() < 0)
die(_("index file corrupt"));
/*
* Drop trailing directory separators from directories so we'll find
* submodules in the index.
*/
for (i = 0; i < argc; i++) {
size_t pathlen = strlen(argv[i]);
if (pathlen && is_dir_sep(argv[i][pathlen - 1]) &&
is_directory(argv[i])) {
do {
pathlen--;
} while (pathlen && is_dir_sep(argv[i][pathlen - 1]));
argv[i] = xmemdupz(argv[i], pathlen);
}
}
pathspec = get_pathspec(prefix, argv);
refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);
seen = NULL;
for (i = 0; pathspec[i] ; i++)
/* nothing */;
seen = xcalloc(i, 1);
for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i];
if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
continue;
ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
list.entry[list.nr].name = ce->name;
list.entry[list.nr++].is_submodule = S_ISGITLINK(ce->ce_mode);
}
if (pathspec) {
const char *match;
int seen_any = 0;
for (i = 0; (match = pathspec[i]) != NULL ; i++) {
if (!seen[i]) {
if (!ignore_unmatch) {
die(_("pathspec '%s' did not match any files"),
match);
}
}
else {
seen_any = 1;
}
if (!recursive && seen[i] == MATCHED_RECURSIVELY)
die(_("not removing '%s' recursively without -r"),
*match ? match : ".");
}
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.
*/
//.........这里部分代码省略.........
开发者ID:00027jang27,项目名称:git,代码行数:101,代码来源:rm.c
示例4: ModuleCmd_Whatis
//.........这里部分代码省略.........
} /** for **/
} else {
/**
** User wants all module ``whatis'' info
**/
/**
** If no MODULEPATH defined, we can not output anything
**/
if( !(modpath = (char *) xgetenv( "MODULEPATH")))
if( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
goto unwind0;
/**
** Check whether a cache file exists then list all the ``whatis'' info
** Otherwise read all module files ...
**/
cache_file = apropos_cache();
if( !sw_create && cache_file && !stat( cache_file, &stats)) {
/**
** Open the cache file
**/
if((FILE *) NULL == (cachefp = fopen( cache_file, "r"))) {
if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
goto unwind1;
} else {
/**
** Read the cache and close the file
**/
result = read_cache( argc, argv, cachefp, WHATIS_ALL);
if( EOF == fclose( cachefp))
if( OK != ErrorLogger( ERR_CLOSE, LOC, cache_file, NULL))
goto unwind1;
done = 1;
}
}
/**
** If we're not done now, we have to scan the files
**/
if( !done) {
/**
** Open the cache file if neccessary
**/
if( sw_create && cache_file)
if((FILE *) NULL == (cachefp = fopen( cache_file, "w")))
if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
goto unwind1;
/**
** Tokenize the module path string and check all dirs
**/
for( dirname = xstrtok( modpath, ":");
dirname;
dirname = xstrtok( NULL, ":") ) {
if( !check_dir( dirname))
continue;
开发者ID:HughMacdonald,项目名称:Environment-Modules,代码行数:66,代码来源:ModuleCmd_Whatis.c
示例5: mydisk_read
int mydisk_read(int start_address, int nbytes, void *buffer) {
//TODO:
//startBlockIdx and endBlockIdx indicate start and end block
//of this writing operation
//pls carefully calculate them
int startBlockIdx = 0;
int endBlockIdx = 0;
int i = 0, j = 0;
int iEndAddress = start_address + nbytes -1;
int iCurrPosition = 0;
int iNumberOfBlocks;
char *cCache = (char *)malloc(BLOCK_SIZE);
int bSeek = 0;
startBlockIdx = start_address / BLOCK_SIZE;
endBlockIdx = (start_address + nbytes - 1) / BLOCK_SIZE;
iNumberOfBlocks = endBlockIdx - startBlockIdx + 1;
// Validating that the parameters are good for the operation.
if (start_address < 0) {
return (1);
} else if (nbytes < 0) {
return (1);
} else if ((start_address + nbytes) >= (diskEntity.max_blocks*BLOCK_SIZE) ) {
return (1);
}
size_t bufferOffset = 0;
for (i = startBlockIdx; i < endBlockIdx + 1; i++) {
int blockInCacheFlag = 0; //0 - no, 1 - yes
if (1 == CACHE_SWITCH) blockInCacheFlag = query_cache(i);
// The time required to move between sector for the first block.
if ((diskEntity.disk_type == 0) && !blockInCacheFlag && !bSeek) {
Disk_Latency += HDD_SEEK;
bSeek = 1;
}
if (0 == blockInCacheFlag) {
//if cache is missed or disabled
//TODO:read data from disk
// Calculation for the disk latency for each block.
if (diskEntity.disk_type == 0) {
Disk_Latency += HDD_READ_LATENCY;
} else if (diskEntity.disk_type == 1) {
Disk_Latency += SSD_READ_LATENCY;
}
for (j = 0 ; j < BLOCK_SIZE; j++) {
iCurrPosition = i*BLOCK_SIZE+j;
if ((iCurrPosition >= start_address) && (iCurrPosition <= iEndAddress)) {
fseek(diskEntity.pBlockStore, iCurrPosition, SEEK_SET);
fread(buffer+bufferOffset, 1, 1, diskEntity.pBlockStore);
// Add the content in "cCache" to have a full block of information.
bufferOffset++;
}
}
if (1 == CACHE_SWITCH) {
// Add the latency for the caching.
if (diskEntity.disk_type == 0) {
Disk_Latency += CACHE_WRITE_LATENCY;
} else if (diskEntity.disk_type == 1) {
Disk_Latency += CACHE_WRITE_LATENCY;
}
// Reading the data on the disk to have the full block in the cache.
for (j = 0 ; j < BLOCK_SIZE; j++) {
iCurrPosition = i*BLOCK_SIZE+j;
if ((iCurrPosition >= start_address) && (iCurrPosition <= iEndAddress)) {
// Add the content in "cCache" to have a full block of information.
fseek (diskEntity.pBlockStore, iCurrPosition, SEEK_SET);
fread(cCache+j, 1, 1, diskEntity.pBlockStore);
} else {
// Will read and store the part of the block which is not in the passed buffer
// to have a complete block in the cache.
fseek (diskEntity.pBlockStore, iCurrPosition, SEEK_SET);
fread(cCache+j, 1, 1, diskEntity.pBlockStore);
}
}
//TODO: if cache is enabled, cache this block
add_cache_entry(i, cCache);
cCache = (char *)malloc(BLOCK_SIZE);
}
} else {
Disk_Latency += CACHE_READ_LATENCY;
//if this block is cached,
//TODO:read this block from cache through read_cache(int)
char *cCachedBlock = read_cache(i);
for (j = 0 ; j < BLOCK_SIZE ; j++) {
iCurrPosition = i*BLOCK_SIZE+j;
if ((iCurrPosition >= start_address) && (iCurrPosition <= iEndAddress)) {
memset(buffer+bufferOffset, cCachedBlock[j], 1);
bufferOffset++;
}
//.........这里部分代码省略.........
开发者ID:jean-sebastien-dery,项目名称:COMP310-Disk-Emulator,代码行数:101,代码来源:mydisk.c
示例6: worker
void
worker(int sock)
{
int fd = -1;
char buf[16];
ssize_t size;
char buf0[BUFSIZE];
char buf1[BUFSIZE];
char ls[LS][WS];
int cnt0;
int cnt1;
const char file_name[] = "list.txt";
int rsz;
int k;
std::ifstream in(file_name, std::ios::in | std::ios::binary);
for (;;) {
size = sock_fd_read(sock, buf, 1, &fd);
if (fd != -1) {
std::cout << "worker_pid = " << getpid() << std::endl;
bzero((char *) &buf0, sizeof(buf0));
bzero((char *) &buf1, sizeof(buf1));
for (int i = 0; i < LS; i++)
bzero((char *) ls[i], sizeof(ls[i]));
rsz = recv(fd, buf0, BUFSIZE, MSG_NOSIGNAL);
k = strlen(buf0) - 1;
while(k >= 0 && (buf0[k] == 10 || buf0[k] == 13)) {
buf0[k] = '\0';
k = strlen(buf0) - 1;
}
sops.sem_op = -1;
semop(semid, &sops, 1);
cnt0 = read_cache(buf0, ls);
sops.sem_op = 1;
semop(semid, &sops, 1);
if (cnt0 < LS) {
cnt1 = read_file(in, buf0, ls, cnt0);
sops.sem_op = -1;
semop(semid, &sops, 1);
write_cache(ls, cnt0, cnt1);
sops.sem_op = 1;
semop(semid, &sops, 1);
} else
cnt1 = cnt0;
for (int i = 0; i < cnt1; i++) {
strcat(buf1, ls[i]);
}
rsz = strlen(buf1);
if (!rsz) {
strcpy(buf1, "\n");
rsz = 1;
}
send(fd, buf1, rsz, MSG_NOSIGNAL);
close(fd);
}
in.seekg(0, std::ios::beg);
sleep(5);
}
in.close();
}
开发者ID:andreykoloskov,项目名称:db-lab1,代码行数:66,代码来源:worker.cpp
示例7: cmd_clean
int cmd_clean(int argc, const char **argv, const char *prefix)
{
int i;
int show_only = 0, remove_directories = 0, quiet = 0, ignored = 0;
int ignored_only = 0, baselen = 0, config_set = 0, errors = 0;
int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT;
struct strbuf directory = STRBUF_INIT;
struct dir_struct dir;
static const char **pathspec;
struct strbuf buf = STRBUF_INIT;
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
const char *qname;
char *seen = NULL;
struct option options[] = {
OPT__QUIET(&quiet),
OPT__DRY_RUN(&show_only),
OPT_BOOLEAN('f', "force", &force, "force"),
OPT_BOOLEAN('d', NULL, &remove_directories,
"remove whole directories"),
{ OPTION_CALLBACK, 'e', "exclude", &exclude_list, "pattern",
"exclude <pattern>", PARSE_OPT_NONEG, exclude_cb },
OPT_BOOLEAN('x', NULL, &ignored, "remove ignored files, too"),
OPT_BOOLEAN('X', NULL, &ignored_only,
"remove only ignored files"),
OPT_END()
};
git_config(git_clean_config, NULL);
if (force < 0)
force = 0;
else
config_set = 1;
argc = parse_options(argc, argv, prefix, options, builtin_clean_usage,
0);
memset(&dir, 0, sizeof(dir));
if (ignored_only)
dir.flags |= DIR_SHOW_IGNORED;
if (ignored && ignored_only)
die("-x and -X cannot be used together");
if (!show_only && !force)
die("clean.requireForce %s to true and neither -n nor -f given; "
"refusing to clean", config_set ? "set" : "defaults");
if (force > 1)
rm_flags = 0;
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
if (read_cache() < 0)
die("index file corrupt");
if (!ignored)
setup_standard_excludes(&dir);
for (i = 0; i < exclude_list.nr; i++)
add_exclude(exclude_list.items[i].string, "", 0, dir.exclude_list);
pathspec = get_pathspec(prefix, argv);
fill_directory(&dir, pathspec);
if (pathspec)
seen = xmalloc(argc > 0 ? argc : 1);
for (i = 0; i < dir.nr; i++) {
struct dir_entry *ent = dir.entries[i];
int len, pos;
int matches = 0;
struct cache_entry *ce;
struct stat st;
/*
* Remove the '/' at the end that directory
* walking adds for directory entries.
*/
len = ent->len;
if (len && ent->name[len-1] == '/')
len--;
pos = cache_name_pos(ent->name, len);
if (0 <= pos)
continue; /* exact match */
pos = -pos - 1;
if (pos < active_nr) {
ce = active_cache[pos];
if (ce_namelen(ce) == len &&
!memcmp(ce->name, ent->name, len))
continue; /* Yup, this one exists unmerged */
}
/*
* we might have removed this as part of earlier
* recursive directory removal, so lstat() here could
* fail with ENOENT.
*/
if (lstat(ent->name, &st))
continue;
//.........这里部分代码省略.........
开发者ID:Jinyan,项目名称:git,代码行数:101,代码来源:clean.c
示例8: cmd_ls_files
//.........这里部分代码省略.........
add_excludes_from_file(&dir, argv[++i]);
continue;
}
if (!prefixcmp(arg, "--exclude-from=")) {
exc_given = 1;
add_excludes_from_file(&dir, arg+15);
continue;
}
if (!prefixcmp(arg, "--exclude-per-directory=")) {
exc_given = 1;
dir.exclude_per_dir = arg + 24;
continue;
}
if (!strcmp(arg, "--exclude-standard")) {
exc_given = 1;
setup_standard_excludes(&dir);
continue;
}
if (!strcmp(arg, "--full-name")) {
prefix_offset = 0;
continue;
}
if (!strcmp(arg, "--error-unmatch")) {
error_unmatch = 1;
continue;
}
if (!prefixcmp(arg, "--with-tree=")) {
with_tree = arg + 12;
continue;
}
if (!prefixcmp(arg, "--abbrev=")) {
abbrev = strtoul(arg+9, NULL, 10);
if (abbrev && abbrev < MINIMUM_ABBREV)
abbrev = MINIMUM_ABBREV;
else if (abbrev > 40)
abbrev = 40;
continue;
}
if (!strcmp(arg, "--abbrev")) {
abbrev = DEFAULT_ABBREV;
continue;
}
if (*arg == '-')
usage(ls_files_usage);
break;
}
if (require_work_tree && !is_inside_work_tree())
setup_work_tree();
pathspec = get_pathspec(prefix, argv + i);
/* Verify that the pathspec matches the prefix */
if (pathspec)
prefix = verify_pathspec(prefix);
/* Treat unmatching pathspec elements as errors */
if (pathspec && error_unmatch) {
int num;
for (num = 0; pathspec[num]; num++)
;
ps_matched = xcalloc(1, num);
}
if (dir.show_ignored && !exc_given) {
fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
argv[0]);
exit(1);
}
/* With no flags, we default to showing the cached files */
if (!(show_stage | show_deleted | show_others | show_unmerged |
show_killed | show_modified))
show_cached = 1;
read_cache();
if (prefix)
prune_cache(prefix);
if (with_tree) {
/*
* Basic sanity check; show-stages and show-unmerged
* would not make any sense with this option.
*/
if (show_stage || show_unmerged)
die("ls-files --with-tree is incompatible with -s or -u");
overlay_tree_on_cache(with_tree, prefix);
}
show_files(&dir, prefix);
if (ps_matched) {
int bad;
bad = report_path_error(ps_matched, pathspec, prefix_offset);
if (bad)
fprintf(stderr, "Did you forget to 'git add'?\n");
return bad ? 1 : 0;
}
return 0;
}
开发者ID:theefer,项目名称:git,代码行数:101,代码来源:builtin-ls-files.c
示例9: cmd_update_index
//.........这里部分代码省略.........
OPT_INTEGER(0, "index-version", &preferred_index_format,
N_("write index in this format")),
OPT_BOOL(0, "split-index", &split_index,
N_("enable or disable split index")),
OPT_BOOL(0, "untracked-cache", &untracked_cache,
N_("enable/disable untracked cache")),
OPT_SET_INT(0, "test-untracked-cache", &untracked_cache,
N_("test if the filesystem supports untracked cache"), UC_TEST),
OPT_SET_INT(0, "force-untracked-cache", &untracked_cache,
N_("enable untracked cache without testing the filesystem"), UC_FORCE),
OPT_SET_INT(0, "force-write-index", &force_write,
N_("write out the index even if is not flagged as changed"), 1),
OPT_BOOL(0, "fsmonitor", &fsmonitor,
N_("enable or disable file system monitor")),
{OPTION_SET_INT, 0, "fsmonitor-valid", &mark_fsmonitor_only, NULL,
N_("mark files as fsmonitor valid"),
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, MARK_FLAG},
{OPTION_SET_INT, 0, "no-fsmonitor-valid", &mark_fsmonitor_only, NULL,
N_("clear fsmonitor valid bit"),
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, UNMARK_FLAG},
OPT_END()
};
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(update_index_usage, options);
git_config(git_default_config, NULL);
/* we will diagnose later if it turns out that we need to update it */
newfd = hold_locked_index(&lock_file, 0);
if (newfd < 0)
lock_error = errno;
entries = read_cache();
if (entries < 0)
die("cache corrupted");
/*
* Custom copy of parse_options() because we want to handle
* filename arguments as they come.
*/
parse_options_start(&ctx, argc, argv, prefix,
options, PARSE_OPT_STOP_AT_NON_OPTION);
while (ctx.argc) {
if (parseopt_state != PARSE_OPT_DONE)
parseopt_state = parse_options_step(&ctx, options,
update_index_usage);
if (!ctx.argc)
break;
switch (parseopt_state) {
case PARSE_OPT_HELP:
case PARSE_OPT_ERROR:
exit(129);
case PARSE_OPT_NON_OPTION:
case PARSE_OPT_DONE:
{
const char *path = ctx.argv[0];
char *p;
setup_work_tree();
p = prefix_path(prefix, prefix_length, path);
update_one(p);
if (set_executable_bit)
chmod_path(set_executable_bit, p);
free(p);
ctx.argc--;
开发者ID:Nowher2,项目名称:git,代码行数:67,代码来源:update-index.c
示例10: cmd_checkout_index
int cmd_checkout_index(int argc, const char **argv, const char *prefix)
{
int i;
struct lock_file lock_file = LOCK_INIT;
int all = 0;
int read_from_stdin = 0;
int prefix_length;
int force = 0, quiet = 0, not_new = 0;
int index_opt = 0;
struct option builtin_checkout_index_options[] = {
OPT_BOOL('a', "all", &all,
N_("check out all files in the index")),
OPT__FORCE(&force, N_("force overwrite of existing files"), 0),
OPT__QUIET(&quiet,
N_("no warning for existing files and files not in index")),
OPT_BOOL('n', "no-create", ¬_new,
N_("don't checkout new files")),
OPT_BOOL('u', "index", &index_opt,
N_("update stat information in the index file")),
OPT_BOOL('z', NULL, &nul_term_line,
N_("paths are separated with NUL character")),
OPT_BOOL(0, "stdin", &read_from_stdin,
N_("read list of paths from the standard input")),
OPT_BOOL(0, "temp", &to_tempfile,
N_("write the content to temporary files")),
OPT_STRING(0, "prefix", &state.base_dir, N_("string"),
N_("when creating files, prepend <string>")),
{ OPTION_CALLBACK, 0, "stage", NULL, "(1|2|3|all)",
N_("copy out the files from named stage"),
PARSE_OPT_NONEG, option_parse_stage },
OPT_END()
};
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(builtin_checkout_index_usage,
builtin_checkout_index_options);
git_config(git_default_config, NULL);
prefix_length = prefix ? strlen(prefix) : 0;
if (read_cache() < 0) {
die("invalid cache");
}
argc = parse_options(argc, argv, prefix, builtin_checkout_index_options,
builtin_checkout_index_usage, 0);
state.istate = &the_index;
state.force = force;
state.quiet = quiet;
state.not_new = not_new;
if (!state.base_dir)
state.base_dir = "";
state.base_dir_len = strlen(state.base_dir);
/*
* when --prefix is specified we do not want to update cache.
*/
if (index_opt && !state.base_dir_len && !to_tempfile) {
state.refresh_cache = 1;
state.istate = &the_index;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
}
/* Check out named files first */
for (i = 0; i < argc; i++) {
const char *arg = argv[i];
char *p;
if (all)
die("git checkout-index: don't mix '--all' and explicit filenames");
if (read_from_stdin)
die("git checkout-index: don't mix '--stdin' and explicit filenames");
p = prefix_path(prefix, prefix_length, arg);
checkout_file(p, prefix);
free(p);
}
if (read_from_stdin) {
struct strbuf buf = STRBUF_INIT;
struct strbuf unquoted = STRBUF_INIT;
strbuf_getline_fn getline_fn;
if (all)
die("git checkout-index: don't mix '--all' and '--stdin'");
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
while (getline_fn(&buf, stdin) != EOF) {
char *p;
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);
}
p = prefix_path(prefix, prefix_length, buf.buf);
checkout_file(p, prefix);
free(p);
}
strbuf_release(&unquoted);
strbuf_release(&buf);
//.........这里部分代码省略.........
开发者ID:MichaelBlume,项目名称:git,代码行数:101,代码来源:checkout-index.c
示例11: merge_recursive
/*
* Merge the commits h1 and h2, return the resulting virtual
* commit object and a flag indicating the cleanness of the merge.
*/
int merge_recursive(struct merge_options *o,
struct commit *h1,
struct commit *h2,
struct commit_list *ca,
struct commit **result)
{
struct commit_list *iter;
struct commit *merged_common_ancestors;
struct tree *mrtree = mrtree;
int clean;
if (show(o, 4)) {
output(o, 4, "Merging:");
output_commit_title(o, h1);
output_commit_title(o, h2);
}
if (!ca) {
ca = get_merge_bases(h1, h2, 1);
ca = reverse_commit_list(ca);
}
if (show(o, 5)) {
output(o, 5, "found %u common ancestor(s):", commit_list_count(ca));
for (iter = ca; iter; iter = iter->next)
output_commit_title(o, iter->item);
}
merged_common_ancestors = pop_commit(&ca);
if (merged_common_ancestors == NULL) {
/* if there is no common ancestor, make an empty tree */
struct tree *tree = xcalloc(1, sizeof(struct tree));
tree->object.parsed = 1;
tree->object.type = OBJ_TREE;
pretend_sha1_file(NULL, 0, OBJ_TREE, tree->object.sha1);
merged_common_ancestors = make_virtual_commit(tree, "ancestor");
}
for (iter = ca; iter; iter = iter->next) {
const char *saved_b1, *saved_b2;
o->call_depth++;
/*
* When the merge fails, the result contains files
* with conflict markers. The cleanness flag is
* ignored, it was never actually used, as result of
* merge_trees has always overwritten it: the committed
* "conflicts" were already resolved.
*/
discard_cache();
saved_b1 = o->branch1;
saved_b2 = o->branch2;
o->branch1 = "Temporary merge branch 1";
o->branch2 = "Temporary merge branch 2";
merge_recursive(o, merged_common_ancestors, iter->item,
NULL, &merged_common_ancestors);
o->branch1 = saved_b1;
o->branch2 = saved_b2;
o->call_depth--;
if (!merged_common_ancestors)
die("merge returned no commit");
}
discard_cache();
if (!o->call_depth)
read_cache();
clean = merge_trees(o, h1->tree, h2->tree, merged_common_ancestors->tree,
&mrtree);
if (o->call_depth) {
*result = make_virtual_commit(mrtree, "merged tree");
commit_list_insert(h1, &(*result)->parents);
commit_list_insert(h2, &(*result)->parents->next);
}
flush_output(o);
return clean;
}
开发者ID:emk,项目名称:git,代码行数:83,代码来源:merge-recursive.c
示例12: 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
示例13: main
//.........这里部分代码省略.........
{
std::cerr << " iter, training file changed " << std::endl;
training_file = "bbe";
}
*/
/*
if ( ii == 1000 )
{
std::cerr << " iter, training file changed " << std::endl;
samu.set_training_file ( "bbe" );
}
else if ( ii == 1000 + 4000 )
{
std::cerr << " iter, training file changed " << std::endl;
training_file = "none";
samu.set_training_file ( training_file );
}
else if ( ii == 1000 + 4000 + 5000 )
{
std::cerr << " iter, training file changed " << std::endl;
samu.set_training_file ( "bbe" );
}
else if ( ii == 1000 + 4000 + 5000 + 4000 )
{
std::cerr << " iter, training file changed " << std::endl;
training_file = "none";
samu.set_training_file ( training_file );
}
*/
#endif
samu.clear_vi();
if ( samu.get_training_file() == training_file )
{
samu.set_N_e ( N_e );
for ( int i {0}; i<test_triplets["introduce myself"].size() && samu.sleep(); ++i )
{
SPOTriplets tv;
tv.push_back ( test_triplets["introduce myself"][i] );
sum += to_samu ( 11, tv );
++cnt;
brel += samu.get_brel();
}
}
else
{
samu.set_N_e ( N_e );
std::string key = samu.get_training_file();
if ( cache.find ( key ) == cache.end() )
{
std::fstream triplet_train ( key+".triplets", std::ios_base::in );
if ( triplet_train )
{
do
{
SPOTriplet t;
triplet_train >> t;
if ( !t.empty() )
cache[key].push_back ( t );
}
while ( !triplet_train.eof() && samu.sleep() );
triplet_train.close();
sum = read_cache ( key, cnt, brel );
}
else
{
std::fstream train ( samu.get_training_file(), std::ios_base::in );
if ( train )
{
std::string file = key+".triplets";
for ( std::string line; std::getline ( train, line ) && samu.sleep(); )
{
#ifndef TRIPLET_CACHE
sum += to_samu ( 12, line );
#else
sum += to_samu ( 12, line, file );
#endif
++cnt;
brel += samu.get_brel();
}
train.close();
}
}
}
else
{
开发者ID:nbatfai,项目名称:hezron,代码行数:101,代码来源:main.cpp
示例14: to_samu
sum += to_samu ( 12, line, file );
#endif
++cnt;
brel += samu.get_brel();
}
train.close();
}
}
}
else
{
sum = read_cache ( key, cnt, brel );
}
}
//std::cerr << "###### " << ++j << "-th iter " << sum << std::endl;
double mbrel = ( double ) brel/ ( double ) cnt;
int bad = ( sum - samu.get_max_reward() * cnt ) / ( samu.get_min_reward() - samu.get_max_reward() );
std::cerr << ++j
<< "-th iter, err: "
<< cnt*samu.get_max_reward() - sum
<< " ("
<< sum
<< ", good: "
开发者ID:nbatfai,项目名称:hezron,代码行数:31,代码来源:main.cpp
示例15: do_apply_stash
static int do_apply_stash(const char *prefix, struct stash_info *info,
int index, int quiet)
{
int ret;
int has_index = index;
struct merge_options o;
struct object_id c_tree;
struct object_id index_tree;
struct commit *result;
const struct object_id *bases[1];
read_cache_preload(NULL);
if (refresh_cache(REFRESH_QUIET))
return -1;
if (write_cache_as_tree(&c_tree, 0, NULL))
return error(_("cannot apply a stash in the middle of a merge"));
if (index) {
if (oideq(&info->b_tree, &info->i_tree) ||
oideq(&c_tree, &info->i_tree)) {
has_index = 0;
} else {
struct strbuf out = STRBUF_INIT;
if (diff_tree_binary(&out, &info->w_commit)) {
strbuf_release(&out);
return error(_("could not generate diff %s^!."),
oid_to_hex(&info->w_commit));
}
ret = apply_cached(&out);
strbuf_release(&out);
if (ret)
return error(_("conflicts in index."
"Try without --index."));
discard_cache();
read_cache();
if (write_cache_as_tree(&index_tree, 0, NULL))
return error(_("could not save index tree"));
reset_head();
}
}
if (info->has_u && restore_untracked(&info->u_tree))
return error(_("could not restore untracked files from stash"));
init_merge_options(&o, the_repository);
o.branch1 = "Updated upstream";
o.branch2 = "Stashed changes";
if (oideq(&info->b_tree, &c_tree))
o.branch1 = "Version stash was based on";
if (quiet)
o.verbosity = 0;
if (o.verbosity >= 3)
printf_ln(_("Merging %s with %s"), o.branch1, o.branch2);
bases[0] = &info->b_tree;
ret = merge_recursive_generic(&o, &c_tree, &info->w_tree, 1, bases,
&result);
if (ret) {
rerere(0);
if (index)
fprintf_ln(stderr, _("Index was not unstashed."));
return ret;
}
if (has_index) {
if (reset_tree(&index_tree, 0, 0))
return -1;
} else {
struct strbuf out = STRBUF_INIT;
if (get_newly_staged(&out, &c_tree)) {
strbuf_release(&out);
return -1;
}
if (reset_tree(&c_tree, 0, 1)) {
strbuf_release(&out);
return -1;
}
ret = update_index(&out);
strbuf_release(&out);
if (ret)
return -1;
discard_cache();
}
//.........这里部分代码省略.........
开发者ID:PhilipOakley,项目名称:git,代码行数:101,代码来源:stash.c
示例16: cmd_check_attr
int cmd_check_attr(int argc, const char **argv, const char *prefix)
{
struct git_attr_check *check;
int cnt, i, doubledash, filei;
argc = parse_options(argc, argv, prefix, check_attr_options,
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
if (read_cache() < 0) {
die("invalid cache");
}
if (cached_attrs)
git_attr_set_direction(GIT_ATTR_INDEX, NULL);
doubledash = -1;
for (i = 0; doubledash < 0 && i < argc; i++) {
if (!strcmp(argv[i], "--"))
doubledash = i;
}
/* Process --all and/or attribute arguments: */
if (all_attrs) {
if (doubledash >= 1)
error_with_usage("Attributes and --all both specified");
cnt = 0;
filei = doubledash + 1;
} else if (doubledash == 0) {
error_with_usage("No attribute specified");
} else if (doubledash < 0) {
if (!argc)
error_with_usage("No attribute specified");
if (stdin_paths) {
/* Treat all arguments as attribute names. */
cnt = argc;
filei = argc;
} else {
/* Treat exactly one argument as an attribute name. */
cnt = 1;
filei = 1;
}
} else {
cnt = doubledash;
filei = doubledash + 1;
}
/* Check file argument(s): */
if (stdin_paths) {
if (filei < argc)
error_with_usage("Can't specify files with --stdin");
} else {
if (filei >= argc)
error_with_usage("No file specified");
}
if (all_attrs) {
check = NULL;
} else {
check = xcalloc(cnt, sizeof(*check));
for (i = 0; i < cnt; i++) {
const char *name;
struct git_attr *a;
name = argv[i];
a = git_attr(name);
if (!a)
return error("%s: not a valid attribute name",
name);
check[i].attr = a;
}
}
if (stdin_paths)
check_attr_stdin_paths(prefix, cnt, check);
else {
for (i = filei; i < argc; i++)
check_attr(prefix, cnt, check, argv[i]);
maybe_flush_or_die(stdout, "attribute to stdout");
}
return 0;
}
开发者ID:nulltoken,项目名称:git,代码行数:82,代码来源:check-attr.c
示例17: LOG
}
template <int dimension, typename float_type>
void verlet_nvt_andersen<dimension, float_type>::set_temperature(double temperature)
{
temperature_ = temperature;
sqrt_temperature_ = std::sqrt(temperature_);
LOG("temperature of heat bath: " << temperature_);
}
template <int dimension, typename float_type>
void verlet_nvt_andersen<dimension, float_type>::integrate()
{
LOG_TRACE("update
|
请发表评论