Exemplo n.º 1
0
Arquivo: notes.c Projeto: Noffica/git
int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
				const struct object_id *new_oid)
{
	struct string_list sort_uniq_list = STRING_LIST_INIT_DUP;
	struct strbuf buf = STRBUF_INIT;
	int ret = 1;

	/* read both note blob objects into unique_lines */
	if (string_list_add_note_lines(&sort_uniq_list, cur_oid))
		goto out;
	if (string_list_add_note_lines(&sort_uniq_list, new_oid))
		goto out;
	string_list_remove_empty_items(&sort_uniq_list, 0);
	string_list_sort(&sort_uniq_list);
	string_list_remove_duplicates(&sort_uniq_list, 0);

	/* create a new blob object from sort_uniq_list */
	if (for_each_string_list(&sort_uniq_list,
				 string_list_join_lines_helper, &buf))
		goto out;

	ret = write_object_file(buf.buf, buf.len, blob_type, cur_oid);

out:
	strbuf_release(&buf);
	string_list_clear(&sort_uniq_list, 0);
	return ret;
}
Exemplo n.º 2
0
void list_cmds_by_config(struct string_list *list)
{
	const char *cmd_list;

	/*
	 * There's no actual repository setup at this point (and even
	 * if there is, we don't really care; only global config
	 * matters). If we accidentally set up a repository, it's ok
	 * too since the caller (git --list-cmds=) should exit shortly
	 * anyway.
	 */
	if (git_config_get_string_const("completion.commands", &cmd_list))
		return;

	string_list_sort(list);
	string_list_remove_duplicates(list, 0);

	while (*cmd_list) {
		struct strbuf sb = STRBUF_INIT;
		const char *p = strchrnul(cmd_list, ' ');

		strbuf_add(&sb, cmd_list, p - cmd_list);
		if (*cmd_list == '-')
			string_list_remove(list, cmd_list + 1, 0);
		else
			string_list_insert(list, sb.buf);
		strbuf_release(&sb);
		while (*p == ' ')
			p++;
		cmd_list = p;
	}
}
Exemplo n.º 3
0
Arquivo: help.c Projeto: PKRoma/git
void list_cmds_by_config(struct string_list *list)
{
	const char *cmd_list;

	if (git_config_get_string_const("completion.commands", &cmd_list))
		return;

	string_list_sort(list);
	string_list_remove_duplicates(list, 0);

	while (*cmd_list) {
		struct strbuf sb = STRBUF_INIT;
		const char *p = strchrnul(cmd_list, ' ');

		strbuf_add(&sb, cmd_list, p - cmd_list);
		if (sb.buf[0] == '-')
			string_list_remove(list, sb.buf + 1, 0);
		else
			string_list_insert(list, sb.buf);
		strbuf_release(&sb);
		while (*p == ' ')
			p++;
		cmd_list = p;
	}
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
	if (argc == 5 && !strcmp(argv[1], "split")) {
		struct string_list list = STRING_LIST_INIT_DUP;
		int i;
		const char *s = argv[2];
		int delim = *argv[3];
		int maxsplit = atoi(argv[4]);

		i = string_list_split(&list, s, delim, maxsplit);
		printf("%d\n", i);
		write_list(&list);
		string_list_clear(&list, 0);
		return 0;
	}

	if (argc == 5 && !strcmp(argv[1], "split_in_place")) {
		struct string_list list = STRING_LIST_INIT_NODUP;
		int i;
		char *s = xstrdup(argv[2]);
		int delim = *argv[3];
		int maxsplit = atoi(argv[4]);

		i = string_list_split_in_place(&list, s, delim, maxsplit);
		printf("%d\n", i);
		write_list(&list);
		string_list_clear(&list, 0);
		free(s);
		return 0;
	}

	if (argc == 4 && !strcmp(argv[1], "filter")) {
		/*
		 * Retain only the items that have the specified prefix.
		 * Arguments: list|- prefix
		 */
		struct string_list list = STRING_LIST_INIT_DUP;
		const char *prefix = argv[3];

		parse_string_list(&list, argv[2]);
		filter_string_list(&list, 0, prefix_cb, (void *)prefix);
		write_list_compact(&list);
		string_list_clear(&list, 0);
		return 0;
	}

	if (argc == 3 && !strcmp(argv[1], "remove_duplicates")) {
		struct string_list list = STRING_LIST_INIT_DUP;

		parse_string_list(&list, argv[2]);
		string_list_remove_duplicates(&list, 0);
		write_list_compact(&list);
		string_list_clear(&list, 0);
		return 0;
	}

	fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
		argv[1] ? argv[1] : "(there was none)");
	return 1;
}
Exemplo n.º 5
0
struct ref *fetch_pack(struct fetch_pack_args *args,
		       int fd[], struct child_process *conn,
		       const struct ref *ref,
		       const char *dest,
		       struct string_list *sought,
		       char **pack_lockfile)
{
	struct stat st;
	struct ref *ref_cpy;

	fetch_pack_setup();
	if (args->depth > 0) {
		if (stat(git_path("shallow"), &st))
			st.st_mtime = 0;
	}

	if (sought->nr) {
		sort_string_list(sought);
		string_list_remove_duplicates(sought, 0);
	}

	if (!ref) {
		packet_flush(fd[1]);
		die("no matching remote head");
	}
	ref_cpy = do_fetch_pack(args, fd, ref, sought, pack_lockfile);

	if (args->depth > 0) {
		static struct lock_file lock;
		struct cache_time mtime;
		struct strbuf sb = STRBUF_INIT;
		char *shallow = git_path("shallow");
		int fd;

		mtime.sec = st.st_mtime;
		mtime.nsec = ST_MTIME_NSEC(st);
		if (stat(shallow, &st)) {
			if (mtime.sec)
				die("shallow file was removed during fetch");
		} else if (st.st_mtime != mtime.sec
#ifdef USE_NSEC
				|| ST_MTIME_NSEC(st) != mtime.nsec
#endif
			  )
			die("shallow file was changed during fetch");

		fd = hold_lock_file_for_update(&lock, shallow,
					       LOCK_DIE_ON_ERROR);
		if (!write_shallow_commits(&sb, 0)
		 || write_in_full(fd, sb.buf, sb.len) != sb.len) {
			unlink_or_warn(shallow);
			rollback_lock_file(&lock);
		} else {
			commit_lock_file(&lock);
		}
		strbuf_release(&sb);
	}

	reprepare_packed_git();
	return ref_cpy;
}