您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ strbuf_setlen函数代码示例

51自学网 2021-06-03 08:27:38
  C++
这篇教程C++ strbuf_setlen函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中strbuf_setlen函数的典型用法代码示例。如果您正苦于以下问题:C++ strbuf_setlen函数的具体用法?C++ strbuf_setlen怎么用?C++ strbuf_setlen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了strbuf_setlen函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: notes_merge_commit

int notes_merge_commit(struct notes_merge_options *o,		       struct notes_tree *partial_tree,		       struct commit *partial_commit,		       struct object_id *result_oid){	/*	 * Iterate through files in .git/NOTES_MERGE_WORKTREE and add all	 * found notes to 'partial_tree'. Write the updated notes tree to	 * the DB, and commit the resulting tree object while reusing the	 * commit message and parents from 'partial_commit'.	 * Finally store the new commit object OID into 'result_oid'.	 */	DIR *dir;	struct dirent *e;	struct strbuf path = STRBUF_INIT;	const char *buffer = get_commit_buffer(partial_commit, NULL);	const char *msg = strstr(buffer, "/n/n");	int baselen;	git_path_buf(&path, NOTES_MERGE_WORKTREE);	if (o->verbosity >= 3)		printf("Committing notes in notes merge worktree at %s/n",			path.buf);	if (!msg || msg[2] == '/0')		die("partial notes commit has empty message");	msg += 2;	dir = opendir(path.buf);	if (!dir)		die_errno("could not open %s", path.buf);	strbuf_addch(&path, '/');	baselen = path.len;	while ((e = readdir(dir)) != NULL) {		struct stat st;		struct object_id obj_oid, blob_oid;		if (is_dot_or_dotdot(e->d_name))			continue;		if (get_oid_hex(e->d_name, &obj_oid)) {			if (o->verbosity >= 3)				printf("Skipping non-SHA1 entry '%s%s'/n",					path.buf, e->d_name);			continue;		}		strbuf_addstr(&path, e->d_name);		/* write file as blob, and add to partial_tree */		if (stat(path.buf, &st))			die_errno("Failed to stat '%s'", path.buf);		if (index_path(&blob_oid, path.buf, &st, HASH_WRITE_OBJECT))			die("Failed to write blob object from '%s'", path.buf);		if (add_note(partial_tree, &obj_oid, &blob_oid, NULL))			die("Failed to add resolved note '%s' to notes tree",			    path.buf);		if (o->verbosity >= 4)			printf("Added resolved note for object %s: %s/n",				oid_to_hex(&obj_oid), oid_to_hex(&blob_oid));		strbuf_setlen(&path, baselen);	}	create_notes_commit(partial_tree, partial_commit->parents,			    msg, strlen(msg), result_oid->hash);	unuse_commit_buffer(partial_commit, buffer);	if (o->verbosity >= 4)		printf("Finalized notes merge commit: %s/n",			oid_to_hex(result_oid));	strbuf_release(&path);	closedir(dir);	return 0;}
开发者ID:LinTeX9527,项目名称:git,代码行数:73,


示例2: print_commit

void print_commit(struct commit *commit, struct rev_info *revs){	struct commitinfo *info;	int cols = revs->graph ? 3 : 2;	struct strbuf graphbuf = STRBUF_INIT;	struct strbuf msgbuf = STRBUF_INIT;	if (ctx.repo->enable_log_filecount)		cols++;	if (ctx.repo->enable_log_linecount)		cols++;	if (revs->graph) {		/* Advance graph until current commit */		while (!graph_next_line(revs->graph, &graphbuf)) {			/* Print graph segment in otherwise empty table row */			html("<tr class='nohover'><td class='commitgraph'>");			html(graphbuf.buf);			htmlf("</td><td colspan='%d' /></tr>/n", cols);			strbuf_setlen(&graphbuf, 0);		}		/* Current commit's graph segment is now ready in graphbuf */	}	info = cgit_parse_commit(commit);	htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");	if (revs->graph) {		/* Print graph segment for current commit */		html("<td class='commitgraph'>");		html(graphbuf.buf);		html("</td>");		strbuf_setlen(&graphbuf, 0);	}	else {		html("<td>");		cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);		html("</td>");	}	htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : "");	if (ctx.qry.showmsg) {		/* line-wrap long commit subjects instead of truncating them */		size_t subject_len = strlen(info->subject);		if (subject_len > ctx.cfg.max_msg_len &&		    ctx.cfg.max_msg_len >= 15) {			/* symbol for signaling line-wrap (in PAGE_ENCODING) */			const char wrap_symbol[] = { ' ', 0xE2, 0x86, 0xB5, 0 };			int i = ctx.cfg.max_msg_len - strlen(wrap_symbol);			/* Rewind i to preceding space character */			while (i > 0 && !isspace(info->subject[i]))				--i;			if (!i) /* Oops, zero spaces. Reset i */				i = ctx.cfg.max_msg_len - strlen(wrap_symbol);			/* add remainder starting at i to msgbuf */			strbuf_add(&msgbuf, info->subject + i, subject_len - i);			strbuf_trim(&msgbuf);			strbuf_add(&msgbuf, "/n/n", 2);			/* Place wrap_symbol at position i in info->subject */			strcpy(info->subject + i, wrap_symbol);		}	}	cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,			 sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);	show_commit_decorations(commit);	html("</td><td>");	html_txt(info->author);	if (revs->graph) {		html("</td><td>");		cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);	}	if (ctx.repo->enable_log_filecount || ctx.repo->enable_log_linecount) {		files = 0;		add_lines = 0;		rem_lines = 0;		cgit_diff_commit(commit, inspect_files, ctx.qry.vpath);	}	if (ctx.repo->enable_log_filecount)		htmlf("</td><td>%d", files);	if (ctx.repo->enable_log_linecount)		htmlf("</td><td>-%d/+%d", rem_lines, add_lines);	html("</td></tr>/n");	if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */		html("<tr class='nohover'>");		if (ctx.qry.showmsg) {			/* Concatenate commit message + notes in msgbuf */			if (info->msg && *(info->msg)) {				strbuf_addstr(&msgbuf, info->msg);				strbuf_addch(&msgbuf, '/n');			}//.........这里部分代码省略.........
开发者ID:Turbo87,项目名称:cgit,代码行数:101,


示例3: strbuf_addbuf

void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2){	strbuf_grow(sb, sb2->len);	memcpy(sb->buf + sb->len, sb2->buf, sb2->len);	strbuf_setlen(sb, sb->len + sb2->len);}
开发者ID:KarthikNayak,项目名称:git,代码行数:6,


示例4: remove_dir_recurse

static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up){	DIR *dir;	struct dirent *e;	int ret = 0, original_len = path->len, len, kept_down = 0;	int only_empty = (flag & REMOVE_DIR_EMPTY_ONLY);	int keep_toplevel = (flag & REMOVE_DIR_KEEP_TOPLEVEL);	unsigned char submodule_head[20];	if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) &&	    !resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) {		/* Do not descend and nuke a nested git work tree. */		if (kept_up)			*kept_up = 1;		return 0;	}	flag &= ~REMOVE_DIR_KEEP_TOPLEVEL;	dir = opendir(path->buf);	if (!dir) {		if (errno == ENOENT)			return keep_toplevel ? -1 : 0;		else if (errno == EACCES && !keep_toplevel)			/*			 * An empty dir could be removable even if it			 * is unreadable:			 */			return rmdir(path->buf);		else			return -1;	}	if (path->buf[original_len - 1] != '/')		strbuf_addch(path, '/');	len = path->len;	while ((e = readdir(dir)) != NULL) {		struct stat st;		if (is_dot_or_dotdot(e->d_name))			continue;		strbuf_setlen(path, len);		strbuf_addstr(path, e->d_name);		if (lstat(path->buf, &st)) {			if (errno == ENOENT)				/*				 * file disappeared, which is what we				 * wanted anyway				 */				continue;			/* fall thru */		} else if (S_ISDIR(st.st_mode)) {			if (!remove_dir_recurse(path, flag, &kept_down))				continue; /* happy */		} else if (!only_empty &&			   (!unlink(path->buf) || errno == ENOENT)) {			continue; /* happy, too */		}		/* path too long, stat fails, or non-directory still exists */		ret = -1;		break;	}	closedir(dir);	strbuf_setlen(path, original_len);	if (!ret && !keep_toplevel && !kept_down)		ret = (!rmdir(path->buf) || errno == ENOENT) ? 0 : -1;	else if (kept_up)		/*		 * report the uplevel that it is not an error that we		 * did not rmdir() our directory.		 */		*kept_up = !ret;	return ret;}
开发者ID:B-Rich,项目名称:git,代码行数:75,


示例5: merge_name

/* Get the name for the merge commit's message. */static void merge_name(const char *remote, struct strbuf *msg){	struct commit *remote_head;	unsigned char branch_head[20];	struct strbuf buf = STRBUF_INIT;	struct strbuf bname = STRBUF_INIT;	const char *ptr;	char *found_ref;	int len, early;	strbuf_branchname(&bname, remote);	remote = bname.buf;	memset(branch_head, 0, sizeof(branch_head));	remote_head = get_merge_parent(remote);	if (!remote_head)		die(_("'%s' does not point to a commit"), remote);	if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) {		if (starts_with(found_ref, "refs/heads/")) {			strbuf_addf(msg, "%s/t/tbranch '%s' of ./n",				    sha1_to_hex(branch_head), remote);			goto cleanup;		}		if (starts_with(found_ref, "refs/tags/")) {			strbuf_addf(msg, "%s/t/ttag '%s' of ./n",				    sha1_to_hex(branch_head), remote);			goto cleanup;		}		if (starts_with(found_ref, "refs/remotes/")) {			strbuf_addf(msg, "%s/t/tremote-tracking branch '%s' of ./n",				    sha1_to_hex(branch_head), remote);			goto cleanup;		}	}	/* See if remote matches <name>^^^.. or <name>~<number> */	for (len = 0, ptr = remote + strlen(remote);	     remote < ptr && ptr[-1] == '^';	     ptr--)		len++;	if (len)		early = 1;	else {		early = 0;		ptr = strrchr(remote, '~');		if (ptr) {			int seen_nonzero = 0;			len++; /* count ~ */			while (*++ptr && isdigit(*ptr)) {				seen_nonzero |= (*ptr != '0');				len++;			}			if (*ptr)				len = 0; /* not ...~<number> */			else if (seen_nonzero)				early = 1;			else if (len == 1)				early = 1; /* "name~" is "name~1"! */		}	}	if (len) {		struct strbuf truname = STRBUF_INIT;		strbuf_addf(&truname, "refs/heads/%s", remote);		strbuf_setlen(&truname, truname.len - len);		if (ref_exists(truname.buf)) {			strbuf_addf(msg,				    "%s/t/tbranch '%s'%s of ./n",				    oid_to_hex(&remote_head->object.oid),				    truname.buf + 11,				    (early ? " (early part)" : ""));			strbuf_release(&truname);			goto cleanup;		}		strbuf_release(&truname);	}	if (remote_head->util) {		struct merge_remote_desc *desc;		desc = merge_remote_util(remote_head);		if (desc && desc->obj && desc->obj->type == OBJ_TAG) {			strbuf_addf(msg, "%s/t/t%s '%s'/n",				    oid_to_hex(&desc->obj->oid),				    typename(desc->obj->type),				    remote);			goto cleanup;		}	}
开发者ID:1tgr,项目名称:git,代码行数:90,


示例6: add_worktree

static int add_worktree(const char *path, const char *refname,			const struct add_opts *opts){	struct strbuf sb_git = STRBUF_INIT, sb_repo = STRBUF_INIT;	struct strbuf sb = STRBUF_INIT;	const char *name;	struct stat st;	struct child_process cp = CHILD_PROCESS_INIT;	struct argv_array child_env = ARGV_ARRAY_INIT;	int counter = 0, len, ret;	struct strbuf symref = STRBUF_INIT;	struct commit *commit = NULL;	int is_branch = 0;	if (file_exists(path) && !is_empty_dir(path))		die(_("'%s' already exists"), path);	/* is 'refname' a branch or commit? */	if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) &&	    ref_exists(symref.buf)) {		is_branch = 1;		if (!opts->force)			die_if_checked_out(symref.buf, 0);	}	commit = lookup_commit_reference_by_name(refname);	if (!commit)		die(_("invalid reference: %s"), refname);	name = worktree_basename(path, &len);	git_path_buf(&sb_repo, "worktrees/%.*s", (int)(path + len - name), name);	len = sb_repo.len;	if (safe_create_leading_directories_const(sb_repo.buf))		die_errno(_("could not create leading directories of '%s'"),			  sb_repo.buf);	while (!stat(sb_repo.buf, &st)) {		counter++;		strbuf_setlen(&sb_repo, len);		strbuf_addf(&sb_repo, "%d", counter);	}	name = strrchr(sb_repo.buf, '/') + 1;	junk_pid = getpid();	atexit(remove_junk);	sigchain_push_common(remove_junk_on_signal);	if (mkdir(sb_repo.buf, 0777))		die_errno(_("could not create directory of '%s'"), sb_repo.buf);	junk_git_dir = xstrdup(sb_repo.buf);	is_junk = 1;	/*	 * lock the incomplete repo so prune won't delete it, unlock	 * after the preparation is over.	 */	strbuf_addf(&sb, "%s/locked", sb_repo.buf);	if (!opts->keep_locked)		write_file(sb.buf, "initializing");	else		write_file(sb.buf, "added with --lock");	strbuf_addf(&sb_git, "%s/.git", path);	if (safe_create_leading_directories_const(sb_git.buf))		die_errno(_("could not create leading directories of '%s'"),			  sb_git.buf);	junk_work_tree = xstrdup(path);	strbuf_reset(&sb);	strbuf_addf(&sb, "%s/gitdir", sb_repo.buf);	write_file(sb.buf, "%s", real_path(sb_git.buf));	write_file(sb_git.buf, "gitdir: %s/worktrees/%s",		   real_path(get_git_common_dir()), name);	/*	 * This is to keep resolve_ref() happy. We need a valid HEAD	 * or is_git_directory() will reject the directory. Any value which	 * looks like an object ID will do since it will be immediately	 * replaced by the symbolic-ref or update-ref invocation in the new	 * worktree.	 */	strbuf_reset(&sb);	strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);	write_file(sb.buf, "%s", sha1_to_hex(null_sha1));	strbuf_reset(&sb);	strbuf_addf(&sb, "%s/commondir", sb_repo.buf);	write_file(sb.buf, "../..");	fprintf_ln(stderr, _("Preparing %s (identifier %s)"), path, name);	argv_array_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf);	argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);	cp.git_cmd = 1;	if (!is_branch)		argv_array_pushl(&cp.args, "update-ref", "HEAD",				 oid_to_hex(&commit->object.oid), NULL);	else		argv_array_pushl(&cp.args, "symbolic-ref", "HEAD",				 symref.buf, NULL);	cp.env = child_env.argv;	ret = run_command(&cp);	if (ret)//.........这里部分代码省略.........
开发者ID:ayanmw,项目名称:git,代码行数:101,


示例7: copy_or_link_directory

static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,				   const char *src_repo, int src_baselen){	struct dirent *de;	struct stat buf;	int src_len, dest_len;	DIR *dir;	dir = opendir(src->buf);	if (!dir)		die_errno(_("failed to open '%s'"), src->buf);	if (mkdir(dest->buf, 0777)) {		if (errno != EEXIST)			die_errno(_("failed to create directory '%s'"), dest->buf);		else if (stat(dest->buf, &buf))			die_errno(_("failed to stat '%s'"), dest->buf);		else if (!S_ISDIR(buf.st_mode))			die(_("%s exists and is not a directory"), dest->buf);	}	strbuf_addch(src, '/');	src_len = src->len;	strbuf_addch(dest, '/');	dest_len = dest->len;	while ((de = readdir(dir)) != NULL) {		strbuf_setlen(src, src_len);		strbuf_addstr(src, de->d_name);		strbuf_setlen(dest, dest_len);		strbuf_addstr(dest, de->d_name);		if (stat(src->buf, &buf)) {			warning (_("failed to stat %s/n"), src->buf);			continue;		}		if (S_ISDIR(buf.st_mode)) {			if (de->d_name[0] != '.')				copy_or_link_directory(src, dest,						       src_repo, src_baselen);			continue;		}		/* Files that cannot be copied bit-for-bit... */		if (!strcmp(src->buf + src_baselen, "/info/alternates")) {			copy_alternates(src, dest, src_repo);			continue;		}		if (unlink(dest->buf) && errno != ENOENT)			die_errno(_("failed to unlink '%s'"), dest->buf);		if (!option_no_hardlinks) {			if (!link(src->buf, dest->buf))				continue;			if (option_local > 0)				die_errno(_("failed to create link '%s'"), dest->buf);			option_no_hardlinks = 1;		}		if (copy_file_with_time(dest->buf, src->buf, 0666))			die_errno(_("failed to copy file to '%s'"), dest->buf);	}	closedir(dir);}
开发者ID:00027jang27,项目名称:git,代码行数:62,


示例8: cmd_merge

//.........这里部分代码省略.........			    "an empty head"));		remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);		remote_head = remoteheads->item;		if (!remote_head)			die(_("%s - not something we can merge"), argv[0]);		read_empty(remote_head->object.sha1, 0);		update_ref("initial pull", "HEAD", remote_head->object.sha1,			   NULL, 0, UPDATE_REFS_DIE_ON_ERR);		goto done;	} else {		struct strbuf merge_names = STRBUF_INIT;		/* We are invoked directly as the first-class UI. */		head_arg = "HEAD";		/*		 * All the rest are the commits being merged; prepare		 * the standard merge summary message to be appended		 * to the given message.		 */		remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);		for (p = remoteheads; p; p = p->next)			merge_name(merge_remote_util(p->item)->name, &merge_names);		if (!have_message || shortlog_len) {			struct fmt_merge_msg_opts opts;			memset(&opts, 0, sizeof(opts));			opts.add_title = !have_message;			opts.shortlog_len = shortlog_len;			opts.credit_people = (0 < option_edit);			fmt_merge_msg(&merge_names, &merge_msg, &opts);			if (merge_msg.len)				strbuf_setlen(&merge_msg, merge_msg.len - 1);		}	}	if (!head_commit || !argc)		usage_with_options(builtin_merge_usage,			builtin_merge_options);	if (verify_signatures) {		for (p = remoteheads; p; p = p->next) {			struct commit *commit = p->item;			char hex[41];			struct signature_check signature_check;			memset(&signature_check, 0, sizeof(signature_check));			check_commit_signature(commit, &signature_check);			strcpy(hex, find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));			switch (signature_check.result) {			case 'G':				break;			case 'U':				die(_("Commit %s has an untrusted GPG signature, "				      "allegedly by %s."), hex, signature_check.signer);			case 'B':				die(_("Commit %s has a bad GPG signature "				      "allegedly by %s."), hex, signature_check.signer);			default: /* 'N' */				die(_("Commit %s does not have a GPG signature."), hex);			}			if (verbosity >= 0 && signature_check.result == 'G')				printf(_("Commit %s has a good GPG signature by %s/n"),				       hex, signature_check.signer);
开发者ID:bmpvieira,项目名称:git,代码行数:67,


示例9: merge_name

/* Get the name for the merge commit's message. */static void merge_name(const char *remote, struct strbuf *msg){	struct commit *remote_head;	unsigned char branch_head[20];	struct strbuf buf = STRBUF_INIT;	struct strbuf bname = STRBUF_INIT;	const char *ptr;	char *found_ref;	int len, early;	strbuf_branchname(&bname, remote);	remote = bname.buf;	memset(branch_head, 0, sizeof(branch_head));	remote_head = get_merge_parent(remote);	if (!remote_head)		die(_("'%s' does not point to a commit"), remote);	if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) {		if (starts_with(found_ref, "refs/heads/")) {			strbuf_addf(msg, "%s/t/tbranch '%s' of ./n",				    sha1_to_hex(branch_head), remote);			goto cleanup;		}		if (starts_with(found_ref, "refs/tags/")) {			strbuf_addf(msg, "%s/t/ttag '%s' of ./n",				    sha1_to_hex(branch_head), remote);			goto cleanup;		}		if (starts_with(found_ref, "refs/remotes/")) {			strbuf_addf(msg, "%s/t/tremote-tracking branch '%s' of ./n",				    sha1_to_hex(branch_head), remote);			goto cleanup;		}	}	/* See if remote matches <name>^^^.. or <name>~<number> */	for (len = 0, ptr = remote + strlen(remote);	     remote < ptr && ptr[-1] == '^';	     ptr--)		len++;	if (len)		early = 1;	else {		early = 0;		ptr = strrchr(remote, '~');		if (ptr) {			int seen_nonzero = 0;			len++; /* count ~ */			while (*++ptr && isdigit(*ptr)) {				seen_nonzero |= (*ptr != '0');				len++;			}			if (*ptr)				len = 0; /* not ...~<number> */			else if (seen_nonzero)				early = 1;			else if (len == 1)				early = 1; /* "name~" is "name~1"! */		}	}	if (len) {		struct strbuf truname = STRBUF_INIT;		strbuf_addstr(&truname, "refs/heads/");		strbuf_addstr(&truname, remote);		strbuf_setlen(&truname, truname.len - len);		if (ref_exists(truname.buf)) {			strbuf_addf(msg,				    "%s/t/tbranch '%s'%s of ./n",				    sha1_to_hex(remote_head->object.sha1),				    truname.buf + 11,				    (early ? " (early part)" : ""));			strbuf_release(&truname);			goto cleanup;		}	}	if (!strcmp(remote, "FETCH_HEAD") &&			!access(git_path("FETCH_HEAD"), R_OK)) {		const char *filename;		FILE *fp;		struct strbuf line = STRBUF_INIT;		char *ptr;		filename = git_path("FETCH_HEAD");		fp = fopen(filename, "r");		if (!fp)			die_errno(_("could not open '%s' for reading"),				  filename);		strbuf_getline(&line, fp, '/n');		fclose(fp);		ptr = strstr(line.buf, "/tnot-for-merge/t");		if (ptr)			strbuf_remove(&line, ptr-line.buf+1, 13);		strbuf_addbuf(msg, &line);		strbuf_release(&line);		goto cleanup;	}//.........这里部分代码省略.........
开发者ID:bmpvieira,项目名称:git,代码行数:101,


示例10: dir_iterator_advance

int dir_iterator_advance(struct dir_iterator *dir_iterator){	struct dir_iterator_int *iter =		(struct dir_iterator_int *)dir_iterator;	while (1) {		struct dir_iterator_level *level =			&iter->levels[iter->levels_nr - 1];		struct dirent *de;		if (!level->initialized) {			/*			 * Note: dir_iterator_begin() ensures that			 * path is not the empty string.			 */			if (!is_dir_sep(iter->base.path.buf[iter->base.path.len - 1]))				strbuf_addch(&iter->base.path, '/');			level->prefix_len = iter->base.path.len;			level->dir = opendir(iter->base.path.buf);			if (!level->dir && errno != ENOENT) {				warning("error opening directory %s: %s",					iter->base.path.buf, strerror(errno));				/* Popping the level is handled below */			}			level->initialized = 1;		} else if (S_ISDIR(iter->base.st.st_mode)) {			if (level->dir_state == DIR_STATE_ITER) {				/*				 * The directory was just iterated				 * over; now prepare to iterate into				 * it.				 */				level->dir_state = DIR_STATE_RECURSE;				ALLOC_GROW(iter->levels, iter->levels_nr + 1,					   iter->levels_alloc);				level = &iter->levels[iter->levels_nr++];				level->initialized = 0;				continue;			} else {				/*				 * The directory has already been				 * iterated over and iterated into;				 * we're done with it.				 */			}		}		if (!level->dir) {			/*			 * This level is exhausted (or wasn't opened			 * successfully); pop up a level.			 */			if (--iter->levels_nr == 0)				return dir_iterator_abort(dir_iterator);			continue;		}		/*		 * Loop until we find an entry that we can give back		 * to the caller:		 */		while (1) {			strbuf_setlen(&iter->base.path, level->prefix_len);			errno = 0;			de = readdir(level->dir);			if (!de) {				/* This level is exhausted; pop up a level. */				if (errno) {					warning("error reading directory %s: %s",						iter->base.path.buf, strerror(errno));				} else if (closedir(level->dir))					warning("error closing directory %s: %s",						iter->base.path.buf, strerror(errno));				level->dir = NULL;				if (--iter->levels_nr == 0)					return dir_iterator_abort(dir_iterator);				break;			}			if (is_dot_or_dotdot(de->d_name))				continue;			strbuf_addstr(&iter->base.path, de->d_name);			if (lstat(iter->base.path.buf, &iter->base.st) < 0) {				if (errno != ENOENT)					warning("error reading path '%s': %s",						iter->base.path.buf,						strerror(errno));				continue;			}			/*			 * We have to set these each time because			 * the path strbuf might have been realloc()ed.			 *///.........这里部分代码省略.........
开发者ID:1tgr,项目名称:git,代码行数:101,


示例11: find_common

//.........这里部分代码省略.........		char *line;		const char *arg;		struct object_id oid;		send_request(args, fd[1], &req_buf);		while ((line = packet_read_line(fd[0], NULL))) {			if (skip_prefix(line, "shallow ", &arg)) {				if (get_oid_hex(arg, &oid))					die(_("invalid shallow line: %s"), line);				register_shallow(the_repository, &oid);				continue;			}			if (skip_prefix(line, "unshallow ", &arg)) {				if (get_oid_hex(arg, &oid))					die(_("invalid unshallow line: %s"), line);				if (!lookup_object(the_repository, oid.hash))					die(_("object not found: %s"), line);				/* make sure that it is parsed as shallow */				if (!parse_object(the_repository, &oid))					die(_("error in object: %s"), line);				if (unregister_shallow(&oid))					die(_("no shallow found: %s"), line);				continue;			}			die(_("expected shallow/unshallow, got %s"), line);		}	} else if (!args->stateless_rpc)		send_request(args, fd[1], &req_buf);	if (!args->stateless_rpc) {		/* If we aren't using the stateless-rpc interface		 * we don't need to retain the headers.		 */		strbuf_setlen(&req_buf, 0);		state_len = 0;	}	flushes = 0;	retval = -1;	if (args->no_dependents)		goto done;	while ((oid = negotiator->next(negotiator))) {		packet_buf_write(&req_buf, "have %s/n", oid_to_hex(oid));		print_verbose(args, "have %s", oid_to_hex(oid));		in_vain++;		if (flush_at <= ++count) {			int ack;			packet_buf_flush(&req_buf);			send_request(args, fd[1], &req_buf);			strbuf_setlen(&req_buf, state_len);			flushes++;			flush_at = next_flush(args->stateless_rpc, count);			/*			 * We keep one window "ahead" of the other side, and			 * will wait for an ACK only on the next one			 */			if (!args->stateless_rpc && count == INITIAL_FLUSH)				continue;			consume_shallow_list(args, fd[0]);			do {				ack = get_ack(fd[0], result_oid);				if (ack)					print_verbose(args, _("got %s %d %s"), "ack",
开发者ID:hashpling,项目名称:git,代码行数:67,


示例12: do_match

//.........这里部分代码省略.........			entry_interesting : entry_not_interesting;	}	pathlen = tree_entry_len(entry);	for (i = ps->nr - 1; i >= 0; i--) {		const struct pathspec_item *item = ps->items+i;		const char *match = item->match;		const char *base_str = base->buf + base_offset;		int matchlen = item->len, matched = 0;		if ((!exclude &&   item->magic & PATHSPEC_EXCLUDE) ||		    ( exclude && !(item->magic & PATHSPEC_EXCLUDE)))			continue;		if (baselen >= matchlen) {			/* If it doesn't match, move along... */			if (!match_dir_prefix(item, base_str, match, matchlen))				goto match_wildcards;			if (!ps->recursive ||			    !(ps->magic & PATHSPEC_MAXDEPTH) ||			    ps->max_depth == -1)				return all_entries_interesting;			return within_depth(base_str + matchlen + 1,					    baselen - matchlen - 1,					    !!S_ISDIR(entry->mode),					    ps->max_depth) ?				entry_interesting : entry_not_interesting;		}		/* Either there must be no base, or the base must match. */		if (baselen == 0 || !basecmp(item, base_str, match, baselen)) {			if (match_entry(item, entry, pathlen,					match + baselen, matchlen - baselen,					&never_interesting))				return entry_interesting;			if (item->nowildcard_len < item->len) {				if (!git_fnmatch(item, match + baselen, entry->path,						 item->nowildcard_len - baselen))					return entry_interesting;				/*				 * Match all directories. We'll try to				 * match files later on.				 */				if (ps->recursive && S_ISDIR(entry->mode))					return entry_interesting;			}			continue;		}match_wildcards:		if (item->nowildcard_len == item->len)			continue;		if (item->nowildcard_len &&		    !match_wildcard_base(item, base_str, baselen, &matched))			continue;		/*		 * Concatenate base and entry->path into one and do		 * fnmatch() on it.		 *		 * While we could avoid concatenation in certain cases		 * [1], which saves a memcpy and potentially a		 * realloc, it turns out not worth it. Measurement on		 * linux-2.6 does not show any clear improvements,		 * partly because of the nowildcard_len optimization		 * in git_fnmatch(). Avoid micro-optimizations here.		 *		 * [1] if match_wildcard_base() says the base		 * directory is already matched, we only need to match		 * the rest, which is shorter so _in theory_ faster.		 */		strbuf_add(base, entry->path, pathlen);		if (!git_fnmatch(item, match, base->buf + base_offset,				 item->nowildcard_len)) {			strbuf_setlen(base, base_offset + baselen);			return entry_interesting;		}		strbuf_setlen(base, base_offset + baselen);		/*		 * Match all directories. We'll try to match files		 * later on.		 * max_depth is ignored but we may consider support it		 * in future, see		 * http://thread.gmane.org/gmane.comp.version-control.git/163757/focus=163840		 */		if (ps->recursive && S_ISDIR(entry->mode))			return entry_interesting;	}	return never_interesting; /* No matches */}
开发者ID:7sOddities,项目名称:git,代码行数:101,


示例13: traverse_trees

int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info){	int error = 0;	struct name_entry *entry = xmalloc(n*sizeof(*entry));	int i;	struct tree_desc_x *tx = xcalloc(n, sizeof(*tx));	struct strbuf base = STRBUF_INIT;	int interesting = 1;	for (i = 0; i < n; i++)		tx[i].d = t[i];	if (info->prev) {		strbuf_grow(&base, info->pathlen);		make_traverse_path(base.buf, info->prev, &info->name);		base.buf[info->pathlen-1] = '/';		strbuf_setlen(&base, info->pathlen);	}	for (;;) {		int trees_used;		unsigned long mask, dirmask;		const char *first = NULL;		int first_len = 0;		struct name_entry *e = NULL;		int len;		for (i = 0; i < n; i++) {			e = entry + i;			extended_entry_extract(tx + i, e, NULL, 0);		}		/*		 * A tree may have "t-2" at the current location even		 * though it may have "t" that is a subtree behind it,		 * and another tree may return "t".  We want to grab		 * all "t" from all trees to match in such a case.		 */		for (i = 0; i < n; i++) {			e = entry + i;			if (!e->path)				continue;			len = tree_entry_len(e);			if (!first) {				first = e->path;				first_len = len;				continue;			}			if (name_compare(e->path, len, first, first_len) < 0) {				first = e->path;				first_len = len;			}		}		if (first) {			for (i = 0; i < n; i++) {				e = entry + i;				extended_entry_extract(tx + i, e, first, first_len);				/* Cull the ones that are not the earliest */				if (!e->path)					continue;				len = tree_entry_len(e);				if (name_compare(e->path, len, first, first_len))					entry_clear(e);			}		}		/* Now we have in entry[i] the earliest name from the trees */		mask = 0;		dirmask = 0;		for (i = 0; i < n; i++) {			if (!entry[i].path)				continue;			mask |= 1ul << i;			if (S_ISDIR(entry[i].mode))				dirmask |= 1ul << i;			e = &entry[i];		}		if (!mask)			break;		interesting = prune_traversal(e, info, &base, interesting);		if (interesting < 0)			break;		if (interesting) {			trees_used = info->fn(n, mask, dirmask, entry, info);			if (trees_used < 0) {				error = trees_used;				if (!info->show_all_errors)					break;			}			mask &= trees_used;		}		for (i = 0; i < n; i++)			if (mask & (1ul << i))				update_extended_entry(tx + i, entry + i);	}	free(entry);	for (i = 0; i < n; i++)		free_extended_entry(tx + i);	free(tx);	strbuf_release(&base);//.........这里部分代码省略.........
开发者ID:7sOddities,项目名称:git,代码行数:101,


示例14: copy_templates_1

static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,			     DIR *dir){	size_t path_baselen = path->len;	size_t template_baselen = template_path->len;	struct dirent *de;	/* Note: if ".git/hooks" file exists in the repository being	 * re-initialized, /etc/core-git/templates/hooks/update would	 * cause "git init" to fail here.  I think this is sane but	 * it means that the set of templates we ship by default, along	 * with the way the namespace under .git/ is organized, should	 * be really carefully chosen.	 */	safe_create_dir(path->buf, 1);	while ((de = readdir(dir)) != NULL) {		struct stat st_git, st_template;		int exists = 0;		strbuf_setlen(path, path_baselen);		strbuf_setlen(template_path, template_baselen);		if (de->d_name[0] == '.')			continue;		strbuf_addstr(path, de->d_name);		strbuf_addstr(template_path, de->d_name);		if (lstat(path->buf, &st_git)) {			if (errno != ENOENT)				die_errno(_("cannot stat '%s'"), path->buf);		}		else			exists = 1;		if (lstat(template_path->buf, &st_template))			die_errno(_("cannot stat template '%s'"), template_path->buf);		if (S_ISDIR(st_template.st_mode)) {			DIR *subdir = opendir(template_path->buf);			if (!subdir)				die_errno(_("cannot opendir '%s'"), template_path->buf);			strbuf_addch(path, '/');			strbuf_addch(template_path, '/');			copy_templates_1(path, template_path, subdir);			closedir(subdir);		}		else if (exists)			continue;		else if (S_ISLNK(st_template.st_mode)) {			struct strbuf lnk = STRBUF_INIT;			if (strbuf_readlink(&lnk, template_path->buf,					    st_template.st_size) < 0)				die_errno(_("cannot readlink '%s'"), template_path->buf);			if (create_symlink(NULL, lnk.buf, path->buf))				die_errno(_("cannot symlink '%s' '%s'"),					  lnk.buf, path->buf);			strbuf_release(&lnk);		}		else if (S_ISREG(st_template.st_mode)) {			if (copy_file(path->buf, template_path->buf, st_template.st_mode))				die_errno(_("cannot copy '%s' to '%s'"),					  template_path->buf, path->buf);		}		else			error(_("ignoring template %s"), template_path->buf);	}}
开发者ID:PhilipOakley,项目名称:git,代码行数:66,


示例15: queue_diff

static int queue_diff(struct diff_options *o,		      const char *name1, const char *name2){	int mode1 = 0, mode2 = 0;	if (get_mode(name1, &mode1) || get_mode(name2, &mode2))		return -1;	if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2))		return error("file/directory conflict: %s, %s", name1, name2);	if (S_ISDIR(mode1) || S_ISDIR(mode2)) {		struct strbuf buffer1 = STRBUF_INIT;		struct strbuf buffer2 = STRBUF_INIT;		struct string_list p1 = STRING_LIST_INIT_DUP;		struct string_list p2 = STRING_LIST_INIT_DUP;		int i1, i2, ret = 0;		size_t len1 = 0, len2 = 0;		if (name1 && read_directory_contents(name1, &p1))			return -1;		if (name2 && read_directory_contents(name2, &p2)) {			string_list_clear(&p1, 0);			return -1;		}		if (name1) {			strbuf_addstr(&buffer1, name1);			if (buffer1.len && buffer1.buf[buffer1.len - 1] != '/')				strbuf_addch(&buffer1, '/');			len1 = buffer1.len;		}		if (name2) {			strbuf_addstr(&buffer2, name2);			if (buffer2.len && buffer2.buf[buffer2.len - 1] != '/')				strbuf_addch(&buffer2, '/');			len2 = buffer2.len;		}		for (i1 = i2 = 0; !ret && (i1 < p1.nr || i2 < p2.nr); ) {			const char *n1, *n2;			int comp;			strbuf_setlen(&buffer1, len1);			strbuf_setlen(&buffer2, len2);			if (i1 == p1.nr)				comp = 1;			else if (i2 == p2.nr)				comp = -1;			else				comp = strcmp(p1.items[i1].string, p2.items[i2].string);			if (comp > 0)				n1 = NULL;			else {				strbuf_addstr(&buffer1, p1.items[i1++].string);				n1 = buffer1.buf;			}			if (comp < 0)				n2 = NULL;			else {				strbuf_addstr(&buffer2, p2.items[i2++].string);				n2 = buffer2.buf;			}			ret = queue_diff(o, n1, n2);		}		string_list_clear(&p1, 0);		string_list_clear(&p2, 0);		strbuf_release(&buffer1);		strbuf_release(&buffer2);		return ret;	} else {		struct diff_filespec *d1, *d2;		if (DIFF_OPT_TST(o, REVERSE_DIFF)) {			unsigned tmp;			const char *tmp_c;			tmp = mode1; mode1 = mode2; mode2 = tmp;			tmp_c = name1; name1 = name2; name2 = tmp_c;		}		d1 = noindex_filespec(name1, mode1);		d2 = noindex_filespec(name2, mode2);		diff_queue(&diff_queued_diff, d1, d2);		return 0;	}}
开发者ID:120011676,项目名称:git,代码行数:92,


示例16: merge_name

/* Get the name for the merge commit's message. */static void merge_name(const char *remote, struct strbuf *msg){	struct object *remote_head;	unsigned char branch_head[20], buf_sha[20];	struct strbuf buf = STRBUF_INIT;	struct strbuf bname = STRBUF_INIT;	const char *ptr;	char *found_ref;	int len, early;	strbuf_branchname(&bname, remote);	remote = bname.buf;	memset(branch_head, 0, sizeof(branch_head));	remote_head = peel_to_type(remote, 0, NULL, OBJ_COMMIT);	if (!remote_head)		die("'%s' does not point to a commit", remote);	if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) {		if (!prefixcmp(found_ref, "refs/heads/")) {			strbuf_addf(msg, "%s/t/tbranch '%s' of ./n",				    sha1_to_hex(branch_head), remote);			goto cleanup;		}		if (!prefixcmp(found_ref, "refs/remotes/")) {			strbuf_addf(msg, "%s/t/tremote branch '%s' of ./n",				    sha1_to_hex(branch_head), remote);			goto cleanup;		}	}	/* See if remote matches <name>^^^.. or <name>~<number> */	for (len = 0, ptr = remote + strlen(remote);	     remote < ptr && ptr[-1] == '^';	     ptr--)		len++;	if (len)		early = 1;	else {		early = 0;		ptr = strrchr(remote, '~');		if (ptr) {			int seen_nonzero = 0;			len++; /* count ~ */			while (*++ptr && isdigit(*ptr)) {				seen_nonzero |= (*ptr != '0');				len++;			}			if (*ptr)				len = 0; /* not ...~<number> */			else if (seen_nonzero)				early = 1;			else if (len == 1)				early = 1; /* "name~" is "name~1"! */		}	}	if (len) {		struct strbuf truname = STRBUF_INIT;		strbuf_addstr(&truname, "refs/heads/");		strbuf_addstr(&truname, remote);		strbuf_setlen(&truname, truname.len - len);		if (resolve_ref(truname.buf, buf_sha, 0, NULL)) {			strbuf_addf(msg,				    "%s/t/tbranch '%s'%s of ./n",				    sha1_to_hex(remote_head->sha1),				    truname.buf + 11,				    (early ? " (early part)" : ""));			strbuf_release(&truname);			goto cleanup;		}	}	if (!strcmp(remote, "FETCH_HEAD") &&			!access(git_path("FETCH_HEAD"), R_OK)) {		FILE *fp;		struct strbuf line = STRBUF_INIT;		char *ptr;		fp = fopen(git_path("FETCH_HEAD"), "r");		if (!fp)			die_errno("could not open '%s' for reading",				  git_path("FETCH_HEAD"));		strbuf_getline(&line, fp, '/n');		fclose(fp);		ptr = strstr(line.buf, "/tnot-for-merge/t");		if (ptr)			strbuf_remove(&line, ptr-line.buf+1, 13);		strbuf_addbuf(msg, &line);		strbuf_release(&line);		goto cleanup;	}	strbuf_addf(msg, "%s/t/tcommit '%s'/n",		sha1_to_hex(remote_head->sha1), remote);cleanup:	strbuf_release(&buf);	strbuf_release(&bname);}
开发者ID:samv,项目名称:git,代码行数:99,


示例17: strbuf_addstr

static struct ref *get_refs_via_rsync(struct transport *transport, int for_push){	struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;	struct ref dummy = {NULL}, *tail = &dummy;	struct child_process rsync;	const char *args[5];	int temp_dir_len;	if (for_push)		return NULL;	/* copy the refs to the temporary directory */	strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX"));	if (!mkdtemp(temp_dir.buf))		die_errno ("Could not make temporary directory");	temp_dir_len = temp_dir.len;	strbuf_addstr(&buf, rsync_url(transport->url));	strbuf_addstr(&buf, "/refs");	memset(&rsync, 0, sizeof(rsync));	rsync.argv = args;	rsync.stdout_to_stderr = 1;	args[0] = "rsync";	args[1] = (transport->verbose > 1) ? "-rv" : "-r";	args[2] = buf.buf;	args[3] = temp_dir.buf;	args[4] = NULL;	if (run_command(&rsync))		die ("Could not run rsync to get refs");	strbuf_reset(&buf);	strbuf_addstr(&buf, rsync_url(transport->url));	strbuf_addstr(&buf, "/packed-refs");	args[2] = buf.buf;	if (run_command(&rsync))		die ("Could not run rsync to get refs");	/* read the copied refs */	strbuf_addstr(&temp_dir, "/refs");	read_loose_refs(&temp_dir, temp_dir_len + 1, &tail);	strbuf_setlen(&temp_dir, temp_dir_len);	tail = &dummy;	strbuf_addstr(&temp_dir, "/packed-refs");	insert_packed_refs(temp_dir.buf, &tail);	strbuf_setlen(&temp_dir, temp_dir_len);	if (remove_dir_recursively(&temp_dir, 0))		warning ("Error removing temporary directory %s.",				temp_dir.buf);	strbuf_release(&buf);	strbuf_release(&temp_dir);	return dummy.next;}
开发者ID:7sOddities,项目名称:git,代码行数:62,


示例18: cmd_merge

//.........这里部分代码省略.........			die("Can merge only exactly one commit into "				"empty head");		if (squash)			die("Squash commit into empty head not supported yet");		if (!allow_fast_forward)			die("Non-fast-forward commit does not make sense into "			    "an empty head");		remote_head = peel_to_type(argv[0], 0, NULL, OBJ_COMMIT);		if (!remote_head)			die("%s - not something we can merge", argv[0]);		update_ref("initial pull", "HEAD", remote_head->sha1, NULL, 0,				DIE_ON_ERR);		reset_hard(remote_head->sha1, 0);		return 0;	} else {		struct strbuf msg = STRBUF_INIT;		/* We are invoked directly as the first-class UI. */		head_arg = "HEAD";		/*		 * All the rest are the commits being merged;		 * prepare the standard merge summary message to		 * be appended to the given message.  If remote		 * is invalid we will die later in the common		 * codepath so we discard the error in this		 * loop.		 */		if (!have_message) {			for (i = 0; i < argc; i++)				merge_name(argv[i], &msg);			fmt_merge_msg(option_log, &msg, &merge_msg);			if (merge_msg.len)				strbuf_setlen(&merge_msg, merge_msg.len-1);		}	}	if (head_invalid || !argc)		usage_with_options(builtin_merge_usage,			builtin_merge_options);	strbuf_addstr(&buf, "merge");	for (i = 0; i < argc; i++)		strbuf_addf(&buf, " %s", argv[i]);	setenv("GIT_REFLOG_ACTION", buf.buf, 0);	strbuf_reset(&buf);	for (i = 0; i < argc; i++) {		struct object *o;		struct commit *commit;		o = peel_to_type(argv[i], 0, NULL, OBJ_COMMIT);		if (!o)			die("%s - not something we can merge", argv[i]);		commit = lookup_commit(o->sha1);		commit->util = (void *)argv[i];		remotes = &commit_list_insert(commit, remotes)->next;		strbuf_addf(&buf, "GITHEAD_%s", sha1_to_hex(o->sha1));		setenv(buf.buf, argv[i], 1);		strbuf_reset(&buf);	}	if (!use_strategies) {		if (!remoteheads->next)			add_strategies(pull_twohead, DEFAULT_TWOHEAD);
开发者ID:samv,项目名称:git,代码行数:67,


示例19: clear_ce_flags_1

/* * Traverse the index, find every entry that matches according to * o->el. Do "ce_flags &= ~clear_mask" on those entries. Return the * number of traversed entries. * * If select_mask is non-zero, only entries whose ce_flags has on of * those bits enabled are traversed. * * cache	: pointer to an index entry * prefix_len	: an offset to its path * * The current path ("prefix") including the trailing '/' is *   cache[0]->name[0..(prefix_len-1)] * Top level path has prefix_len zero. */static int clear_ce_flags_1(struct cache_entry **cache, int nr,			    struct strbuf *prefix,			    int select_mask, int clear_mask,			    struct exclude_list *el, int defval){	struct cache_entry **cache_end = cache + nr;	/*	 * Process all entries that have the given prefix and meet	 * select_mask condition	 */	while(cache != cache_end) {		struct cache_entry *ce = *cache;		const char *name, *slash;		int len, dtype, ret;		if (select_mask && !(ce->ce_flags & select_mask)) {			cache++;			continue;		}		if (prefix->len && strncmp(ce->name, prefix->buf, prefix->len))			break;		name = ce->name + prefix->len;		slash = strchr(name, '/');		/* If it's a directory, try whole directory match first */		if (slash) {			int processed;			len = slash - name;			strbuf_add(prefix, name, len);			processed = clear_ce_flags_dir(cache, cache_end - cache,						       prefix,						       prefix->buf + prefix->len - len,						       select_mask, clear_mask,						       el, defval);			/* clear_c_f_dir eats a whole dir already? */			if (processed) {				cache += processed;				strbuf_setlen(prefix, prefix->len - len);				continue;			}			strbuf_addch(prefix, '/');			cache += clear_ce_flags_1(cache, cache_end - cache,						  prefix,						  select_mask, clear_mask, el, defval);			strbuf_setlen(prefix, prefix->len - len - 1);			continue;		}		/* Non-directory */		dtype = ce_to_dtype(ce);		ret = is_excluded_from_list(ce->name, ce_namelen(ce),					    name, &dtype, el);		if (ret < 0)			ret = defval;		if (ret > 0)			ce->ce_flags &= ~clear_mask;		cache++;	}	return nr - (cache_end - cache);}
开发者ID:Ryosuke0307,项目名称:git,代码行数:82,


示例20: prep_exclude

/* * Loads the per-directory exclude list for the substring of base * which has a char length of baselen. */static void prep_exclude(struct dir_struct *dir, const char *base, int baselen){	struct exclude_list_group *group;	struct exclude_list *el;	struct exclude_stack *stk = NULL;	int current;	group = &dir->exclude_list_group[EXC_DIRS];	/*	 * Pop the exclude lists from the EXCL_DIRS exclude_list_group	 * which originate from directories not in the prefix of the	 * path being checked.	 */	while ((stk = dir->exclude_stack) != NULL) {		if (stk->baselen <= baselen &&		    !strncmp(dir->basebuf.buf, base, stk->baselen))			break;		el = &group->el[dir->exclude_stack->exclude_ix];		dir->exclude_stack = stk->prev;		dir->exclude = NULL;		free((char *)el->src); /* see strbuf_detach() below */		clear_exclude_list(el);		free(stk);		group->nr--;	}	/* Skip traversing into sub directories if the parent is excluded */	if (dir->exclude)		return;	/*	 * Lazy initialization. All call sites currently just	 * memset(dir, 0, sizeof(*dir)) before use. Changing all of	 * them seems lots of work for little benefit.	 */	if (!dir->basebuf.buf)		strbuf_init(&dir->basebuf, PATH_MAX);	/* Read from the parent directories and push them down. */	current = stk ? stk->baselen : -1;	strbuf_setlen(&dir->basebuf, current < 0 ? 0 : current);	while (current < baselen) {		const char *cp;		stk = xcalloc(1, sizeof(*stk));		if (current < 0) {			cp = base;			current = 0;		} else {			cp = strchr(base + current + 1, '/');			if (!cp)				die("oops in prep_exclude");			cp++;		}		stk->prev = dir->exclude_stack;		stk->baselen = cp - base;		stk->exclude_ix = group->nr;		el = add_exclude_list(dir, EXC_DIRS, NULL);		strbuf_add(&dir->basebuf, base + current, stk->baselen - current);		assert(stk->baselen == dir->basebuf.len);		/* Abort if the directory is excluded */		if (stk->baselen) {			int dt = DT_DIR;			dir->basebuf.buf[stk->baselen - 1] = 0;			dir->exclude = last_exclude_matching_from_lists(dir,				dir->basebuf.buf, stk->baselen - 1,				dir->basebuf.buf + current, &dt);			dir->basebuf.buf[stk->baselen - 1] = '/';			if (dir->exclude &&			    dir->exclude->flags & EXC_FLAG_NEGATIVE)				dir->exclude = NULL;			if (dir->exclude) {				dir->exclude_stack = stk;				return;			}		}		/* Try to read per-directory file */		if (dir->exclude_per_dir) {			/*			 * dir->basebuf gets reused by the traversal, but we			 * need fname to remain unchanged to ensure the src			 * member of each struct exclude correctly			 * back-references its source file.  Other invocations			 * of add_exclude_list provide stable strings, so we			 * strbuf_detach() and free() here in the caller.			 */			struct strbuf sb = STRBUF_INIT;			strbuf_addbuf(&sb, &dir->basebuf);			strbuf_addstr(&sb, dir->exclude_per_dir);			el->src = strbuf_detach(&sb, NULL);			add_excludes_from_file_to_list(el->src, el->src,						       stk->baselen, el, 1);		}//.........这里部分代码省略.........
开发者ID:AnithaPandiyan,项目名称:git,代码行数:101,


示例21: process_tree

static void process_tree(struct rev_info *revs,			 struct tree *tree,			 show_object_fn show,			 struct strbuf *base,			 const char *name,			 void *cb_data){	struct object *obj = &tree->object;	struct tree_desc desc;	struct name_entry entry;	enum interesting match = revs->diffopt.pathspec.nr == 0 ?		all_entries_interesting: entry_not_interesting;	int baselen = base->len;	if (!revs->tree_objects)		return;	if (!obj)		die("bad tree object");	if (obj->flags & (UNINTERESTING | SEEN))		return;	if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) {		if (revs->ignore_missing_links)			return;		die("bad tree object %s", oid_to_hex(&obj->oid));	}	obj->flags |= SEEN;	strbuf_addstr(base, name);	show(obj, base->buf, cb_data);	if (base->len)		strbuf_addch(base, '/');	init_tree_desc(&desc, tree->buffer, tree->size);	while (tree_entry(&desc, &entry)) {		if (match != all_entries_interesting) {			match = tree_entry_interesting(&entry, base, 0,						       &revs->diffopt.pathspec);			if (match == all_entries_not_interesting)				break;			if (match == entry_not_interesting)				continue;		}		if (S_ISDIR(entry.mode))			process_tree(revs,				     lookup_tree(entry.sha1),				     show, base, entry.path,				     cb_data);		else if (S_ISGITLINK(entry.mode))			process_gitlink(revs, entry.sha1,					show, base, entry.path,					cb_data);		else			process_blob(revs,				     lookup_blob(entry.sha1),				     show, base, entry.path,				     cb_data);	}	strbuf_setlen(base, baselen);	free_tree_buffer(tree);}
开发者ID:0369,项目名称:git,代码行数:62,


示例22: grep_tree

static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,		     struct tree_desc *tree, struct strbuf *base, int tn_len,		     int check_attr, struct repository *repo){	int hit = 0;	enum interesting match = entry_not_interesting;	struct name_entry entry;	int old_baselen = base->len;	struct strbuf name = STRBUF_INIT;	int name_base_len = 0;	if (repo->submodule_prefix) {		strbuf_addstr(&name, repo->submodule_prefix);		name_base_len = name.len;	}	while (tree_entry(tree, &entry)) {		int te_len = tree_entry_len(&entry);		if (match != all_entries_interesting) {			strbuf_addstr(&name, base->buf + tn_len);			match = tree_entry_interesting(&entry, &name,						       0, pathspec);			strbuf_setlen(&name, name_base_len);			if (match == all_entries_not_interesting)				break;			if (match == entry_not_interesting)				continue;		}		strbuf_add(base, entry.path, te_len);		if (S_ISREG(entry.mode)) {			hit |= grep_oid(opt, entry.oid, base->buf, tn_len,					 check_attr ? base->buf + tn_len : NULL);		} else if (S_ISDIR(entry.mode)) {			enum object_type type;			struct tree_desc sub;			void *data;			unsigned long size;			data = lock_and_read_oid_file(entry.oid, &type, &size);			if (!data)				die(_("unable to read tree (%s)"),				    oid_to_hex(entry.oid));			strbuf_addch(base, '/');			init_tree_desc(&sub, data, size);			hit |= grep_tree(opt, pathspec, &sub, base, tn_len,					 check_attr, repo);			free(data);		} else if (recurse_submodules && S_ISGITLINK(entry.mode)) {			hit |= grep_submodule(opt, repo, pathspec, entry.oid,					      base->buf, base->buf + tn_len);		}		strbuf_setlen(base, old_baselen);		if (hit && opt->status_only)			break;	}	strbuf_release(&name);	return hit;}
开发者ID:SuguruTakahashi,项目名称:git,代码行数:65,


示例23: format_and_pad_commit

static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */				    const char *placeholder,				    struct format_commit_context *c){	struct strbuf local_sb = STRBUF_INIT;	int total_consumed = 0, len, padding = c->padding;	if (padding < 0) {		const char *start = strrchr(sb->buf, '/n');		int occupied;		if (!start)			start = sb->buf;		occupied = utf8_strnwidth(start, -1, 1);		padding = (-padding) - occupied;	}	while (1) {		int modifier = *placeholder == 'C';		int consumed = format_commit_one(&local_sb, placeholder, c);		total_consumed += consumed;		if (!modifier)			break;		placeholder += consumed;		if (*placeholder != '%')			break;		placeholder++;		total_consumed++;	}	len = utf8_strnwidth(local_sb.buf, -1, 1);	if (c->flush_type == flush_left_and_steal) {		const char *ch = sb->buf + sb->len - 1;		while (len > padding && ch > sb->buf) {			const char *p;			if (*ch == ' ') {				ch--;				padding++;				continue;			}			/* check for trailing ansi sequences */			if (*ch != 'm')				break;			p = ch - 1;			while (ch - p < 10 && *p != '/033')				p--;			if (*p != '/033' ||			    ch + 1 - p != display_mode_esc_sequence_len(p))				break;			/*			 * got a good ansi sequence, put it back to			 * local_sb as we're cutting sb			 */			strbuf_insert(&local_sb, 0, p, ch + 1 - p);			ch = p - 1;		}		strbuf_setlen(sb, ch + 1 - sb->buf);		c->flush_type = flush_left;	}	if (len > padding) {		switch (c->truncate) {		case trunc_left:			strbuf_utf8_replace(&local_sb,					    0, len - (padding - 2),					    "..");			break;		case trunc_middle:			strbuf_utf8_replace(&local_sb,					    padding / 2 - 1,					    len - (padding - 2),					    "..");			break;		case trunc_right:			strbuf_utf8_replace(&local_sb,					    padding - 2, len - (padding - 2),					    "..");			break;		case trunc_none:			break;		}		strbuf_addbuf(sb, &local_sb);	} else {		int sb_len = sb->len, offset = 0;		if (c->flush_type == flush_left)			offset = padding - len;		else if (c->flush_type == flush_both)			offset = (padding - len) / 2;		/*		 * we calculate padding in columns, now		 * convert it back to chars		 */		padding = padding - len + local_sb.len;		strbuf_grow(sb, padding);		strbuf_setlen(sb, sb_len + padding);		memset(sb->buf + sb_len, ' ', sb->len - sb_len);		memcpy(sb->buf + sb_len + offset, local_sb.buf,		       local_sb.len);	}	strbuf_release(&local_sb);	c->flush_type = no_flush;//.........这里部分代码省略.........
开发者ID:CookieChen,项目名称:git,代码行数:101,


示例24: read_tree_1

static int read_tree_1(struct tree *tree, struct strbuf *base,		       int stage, const struct pathspec *pathspec,		       read_tree_fn_t fn, void *context){	struct tree_desc desc;	struct name_entry entry;	unsigned char sha1[20];	int len, oldlen = base->len;	enum interesting retval = entry_not_interesting;	if (parse_tree(tree))		return -1;	init_tree_desc(&desc, tree->buffer, tree->size);	while (tree_entry(&desc, &entry)) {		if (retval != all_entries_interesting) {			retval = tree_entry_interesting(&entry, base, 0, pathspec);			if (retval == all_entries_not_interesting)				break;			if (retval == entry_not_interesting)				continue;		}		switch (fn(entry.sha1, base,			   entry.path, entry.mode, stage, context)) {		case 0:			continue;		case READ_TREE_RECURSIVE:			break;		default:			return -1;		}		if (S_ISDIR(entry.mode))			hashcpy(sha1, entry.sha1);		else if (S_ISGITLINK(entry.mode)) {			struct commit *commit;			commit = lookup_commit(entry.sha1);			if (!commit)				die("Commit %s in submodule path %s%s not found",				    sha1_to_hex(entry.sha1),				    base->buf, entry.path);			if (parse_commit(commit))				die("Invalid commit %s in submodule path %s%s",				    sha1_to_hex(entry.sha1),				    base->buf, entry.path);			hashcpy(sha1, commit->tree->object.sha1);		}		else			continue;		len = tree_entry_len(&entry);		strbuf_add(base, entry.path, len);		strbuf_addch(base, '/');		retval = read_tree_1(lookup_tree(sha1),				     base, stage, pathspec,				     fn, context);		strbuf_setlen(base, oldlen);		if (retval)			return -1;	}	return 0;}
开发者ID:AbelTian,项目名称:git,代码行数:67,


示例25: getenv

//.........这里部分代码省略.........	 * ignored previously).	 */	git_config_clear();	/*	 * Let's assume that we are in a git repository.	 * If it turns out later that we are somewhere else, the value will be	 * updated accordingly.	 */	if (nongit_ok)		*nongit_ok = 0;	if (strbuf_getcwd(&cwd))		die_errno("Unable to read current working directory");	offset = cwd.len;	/*	 * If GIT_DIR is set explicitly, we're not going	 * to do any discovery, but we still do repository	 * validation.	 */	gitdirenv = getenv(GIT_DIR_ENVIRONMENT);	if (gitdirenv)		return setup_explicit_git_dir(gitdirenv, &cwd, nongit_ok);	if (env_ceiling_dirs) {		int empty_entry_found = 0;		string_list_split(&ceiling_dirs, env_ceiling_dirs, PATH_SEP, -1);		filter_string_list(&ceiling_dirs, 0,				   canonicalize_ceiling_entry, &empty_entry_found);		ceil_offset = longest_ancestor_length(cwd.buf, &ceiling_dirs);		string_list_clear(&ceiling_dirs, 0);	}	if (ceil_offset < 0 && has_dos_drive_prefix(cwd.buf))		ceil_offset = 1;	/*	 * Test in the following order (relative to the cwd):	 * - .git (file containing "gitdir: <path>")	 * - .git/	 * - ./ (bare)	 * - ../.git	 * - ../.git/	 * - ../ (bare)	 * - ../../.git/	 *   etc.	 */	one_filesystem = !git_env_bool("GIT_DISCOVERY_ACROSS_FILESYSTEM", 0);	if (one_filesystem)		current_device = get_device_or_die(".", NULL, 0);	for (;;) {		gitfile = (char*)read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);		if (gitfile)			gitdirenv = gitfile = xstrdup(gitfile);		else {			if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))				gitdirenv = DEFAULT_GIT_DIR_ENVIRONMENT;		}		if (gitdirenv) {			ret = setup_discovered_git_dir(gitdirenv,						       &cwd, offset,						       nongit_ok);			free(gitfile);			return ret;		}		free(gitfile);		if (is_git_directory("."))			return setup_bare_git_dir(&cwd, offset, nongit_ok);		offset_parent = offset;		while (--offset_parent > ceil_offset && cwd.buf[offset_parent] != '/');		if (offset_parent <= ceil_offset)			return setup_nongit(cwd.buf, nongit_ok);		if (one_filesystem) {			dev_t parent_device = get_device_or_die("..", cwd.buf,								offset);			if (parent_device != current_device) {				if (nongit_ok) {					if (chdir(cwd.buf))						die_errno("Cannot come back to cwd");					*nongit_ok = 1;					return NULL;				}				strbuf_setlen(&cwd, offset);				die("Not a git repository (or any parent up to mount point %s)/n"				"Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).",				    cwd.buf);			}		}		if (chdir("..")) {			strbuf_setlen(&cwd, offset);			die_errno("Cannot change to '%s/..'", cwd.buf);		}		offset = offset_parent;	}}
开发者ID:1tgr,项目名称:git,代码行数:101,


示例26: strbuf_add_wrapped_text

/* * Wrap the text, if necessary. The variable indent is the indent for the * first line, indent2 is the indent for all other lines. * If indent is negative, assume that already -indent columns have been * consumed (and no extra indent is necessary for the first line). */int strbuf_add_wrapped_text(struct strbuf *buf,		const char *text, int indent1, int indent2, int width){	int indent, w, assume_utf8 = 1;	const char *bol, *space, *start = text;	size_t orig_len = buf->len;	if (width <= 0) {		strbuf_add_indented_text(buf, text, indent1, indent2);		return 1;	}retry:	bol = text;	w = indent = indent1;	space = NULL;	if (indent < 0) {		w = -indent;		space = text;	}	for (;;) {		char c;		size_t skip;		while ((skip = display_mode_esc_sequence_len(text)))			text += skip;		c = *text;		if (!c || isspace(c)) {			if (w < width || !space) {				const char *start = bol;				if (!c && text == start)					return w;				if (space)					start = space;				else					strbuf_addchars(buf, ' ', indent);				strbuf_add(buf, start, text - start);				if (!c)					return w;				space = text;				if (c == '/t')					w |= 0x07;				else if (c == '/n') {					space++;					if (*space == '/n') {						strbuf_addch(buf, '/n');						goto new_line;					}					else if (!isalnum(*space))						goto new_line;					else						strbuf_addch(buf, ' ');				}				w++;				text++;			}			else {new_line:				strbuf_addch(buf, '/n');				text = bol = space + isspace(*space);				space = NULL;				w = indent = indent2;			}			continue;		}		if (assume_utf8) {			w += utf8_width(&text, NULL);			if (!text) {				assume_utf8 = 0;				text = start;				strbuf_setlen(buf, orig_len);				goto retry;			}		} else {			w++;			text++;		}	}}
开发者ID:Advael,项目名称:git,代码行数:87,


示例27: strbuf_add

void strbuf_add(struct strbuf *sb, const void *data, size_t len){	strbuf_grow(sb, len);	memcpy(sb->buf + sb->len, data, len);	strbuf_setlen(sb, sb->len + len);}
开发者ID:KarthikNayak,项目名称:git,代码行数:6,


示例28: strbuf_addchars

void strbuf_addchars(struct strbuf *sb, int c, size_t n){	strbuf_grow(sb, n);	memset(sb->buf + sb->len, c, n);	strbuf_setlen(sb, sb->len + n);}
开发者ID:3Schneider,项目名称:git,代码行数:6,


示例29: strbuf_adddup

void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len){	strbuf_grow(sb, len);	memcpy(sb->buf + sb->len, sb->buf + pos, len);	strbuf_setlen(sb, sb->len + len);}
开发者ID:KarthikNayak,项目名称:git,代码行数:6,


示例30: verify_one

static void verify_one(struct repository *r,		       struct index_state *istate,		       struct cache_tree *it,		       struct strbuf *path){	int i, pos, len = path->len;	struct strbuf tree_buf = STRBUF_INIT;	struct object_id new_oid;	for (i = 0; i < it->subtree_nr; i++) {		strbuf_addf(path, "%s/", it->down[i]->name);		verify_one(r, istate, it->down[i]->cache_tree, path);		strbuf_setlen(path, len);	}	if (it->entry_count < 0 ||	    /* no verification on tests (t7003) that replace trees */	    lookup_replace_object(r, &it->oid) != &it->oid)		return;	if (path->len) {		pos = index_name_pos(istate, path->buf, path->len);		pos = -pos - 1;	} else {		pos = 0;	}	i = 0;	while (i < it->entry_count) {		struct cache_entry *ce = istate->cache[pos + i];		const char *slash;		struct cache_tree_sub *sub = NULL;		const struct object_id *oid;		const char *name;		unsigned mode;		int entlen;		if (ce->ce_flags & (CE_STAGEMASK | CE_INTENT_TO_ADD | CE_REMOVE))			BUG("%s with flags 0x%x should not be in cache-tree",			    ce->name, ce->ce_flags);		name = ce->name + path->len;		slash = strchr(name, '/');		if (slash) {			entlen = slash - name;			sub = find_subtree(it, ce->name + path->len, entlen, 0);			if (!sub || sub->cache_tree->entry_count < 0)				BUG("bad subtree '%.*s'", entlen, name);			oid = &sub->cache_tree->oid;			mode = S_IFDIR;			i += sub->cache_tree->entry_count;		} else {			oid = &ce->oid;			mode = ce->ce_mode;			entlen = ce_namelen(ce) - path->len;			i++;		}		strbuf_addf(&tree_buf, "%o %.*s%c", mode, entlen, name, '/0');		strbuf_add(&tree_buf, oid->hash, the_hash_algo->rawsz);	}	hash_object_file(tree_buf.buf, tree_buf.len, tree_type, &new_oid);	if (!oideq(&new_oid, &it->oid))		BUG("cache-tree for path %.*s does not match. "		    "Expected %s got %s", len, path->buf,		    oid_to_hex(&new_oid), oid_to_hex(&it->oid));	strbuf_setlen(path, len);	strbuf_release(&tree_buf);}
开发者ID:fcharlie,项目名称:git,代码行数:67,



注:本文中的strbuf_setlen函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ strbuf_sprintf函数代码示例
C++ strbuf_remove函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。