Exemplo n.º 1
0
void test_diff_stats__shortstat(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" 1 file changed, 5 insertions(+), 3 deletions(-)\n";

	diff_stats_from_commit_oid(
		&_stats, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", false);

	cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(5, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(3, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 2
0
void test_diff_stats__shortstat_nodeletions(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" 1 file changed, 3 insertions(+)\n";

	diff_stats_from_commit_oid(
		&_stats, "5219b9784f9a92d7bd7cb567a6d6a21bfb86697e", false);

	cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(3, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 3
0
void test_diff_stats__shortstat_noinsertions(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" 1 file changed, 2 deletions(-)\n";

	diff_stats_from_commit_oid(
		&_stats, "06b7b69a62cbd1e53c6c4e0c3f16473dcfdb4af6", false);

	cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(0, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(2, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 4
0
void test_diff_stats__multiple_hunks(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" file2.txt | 5 +++--\n" \
	" file3.txt | 6 ++++--\n" \
	" 2 files changed, 7 insertions(+), 4 deletions(-)\n";

	diff_stats_from_commit_oid(
		&_stats, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2", false);

	cl_assert_equal_sz(2, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(7, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(4, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 5
0
void test_diff_stats__binary(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" binary.bin | Bin 3 -> 0 bytes\n"
	" 1 file changed, 0 insertions(+), 0 deletions(-)\n";
	/* TODO: Actually 0 bytes here should be 5!. Seems like we don't load the new content for binary files? */

	diff_stats_from_commit_oid(
		&_stats, "8d7523f6fcb2404257889abe0d96f093d9f524f9", false);

	cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(0, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 6
0
void test_diff_stats__rename_and_modifiy(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" file2.txt.renamed2                      | 2 +-\n"
	" file3.txt.renamed2 => file3.txt.renamed | 0\n"
	" 2 files changed, 1 insertion(+), 1 deletion(-)\n";

	diff_stats_from_commit_oid(
		&_stats, "4ca10087e696d2ba78d07b146a118e9a7096ed4f", true);

	cl_assert_equal_sz(2, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(1, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(1, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 7
0
void test_diff_stats__rename_nochanges(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" file2.txt.renamed => file2.txt.renamed2 | 0\n"
	" file3.txt.renamed => file3.txt.renamed2 | 0\n"
	" 2 files changed, 0 insertions(+), 0 deletions(-)\n";

	diff_stats_from_commit_oid(
		&_stats, "3991dce9e71a0641ca49a6a4eea6c9e7ff402ed4", true);

	cl_assert_equal_sz(2, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(0, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(0, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 8
0
void test_diff_stats__rename(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" file2.txt => file2.txt.renamed | 1 +\n"
	" file3.txt => file3.txt.renamed | 4 +++-\n"
	" 2 files changed, 4 insertions(+), 1 deletion(-)\n";

	diff_stats_from_commit_oid(
		&_stats, "8947a46e2097638ca6040ad4877246f4186ec3bd", true);

	cl_assert_equal_sz(2, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(4, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(1, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 9
0
void test_diff_stats__rename_and_modifiy_no_find(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" file2.txt.renamed2 | 2 +-\n"
	" file3.txt.renamed  | 7 +++++++\n"
	" file3.txt.renamed2 | 7 -------\n"
	" 3 files changed, 8 insertions(+), 8 deletions(-)\n";

	diff_stats_from_commit_oid(
		&_stats, "4ca10087e696d2ba78d07b146a118e9a7096ed4f", false);

	cl_assert_equal_sz(3, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(8, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(8, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 10
0
void test_diff_stats__rename_nochanges_no_find(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" file2.txt.renamed  | 6 ------\n"
	" file2.txt.renamed2 | 6 ++++++\n"
	" file3.txt.renamed  | 7 -------\n"
	" file3.txt.renamed2 | 7 +++++++\n"
	" 4 files changed, 13 insertions(+), 13 deletions(-)\n";

	diff_stats_from_commit_oid(
		&_stats, "3991dce9e71a0641ca49a6a4eea6c9e7ff402ed4", false);

	cl_assert_equal_sz(4, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(13, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(13, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 11
0
void test_diff_stats__rename_no_find(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *stat =
	" file2.txt         | 5 -----\n"
	" file2.txt.renamed | 6 ++++++\n"
	" file3.txt         | 5 -----\n"
	" file3.txt.renamed | 7 +++++++\n"
	" 4 files changed, 13 insertions(+), 10 deletions(-)\n";

	diff_stats_from_commit_oid(
		&_stats, "8947a46e2097638ca6040ad4877246f4186ec3bd", false);

	cl_assert_equal_sz(4, git_diff_stats_files_changed(_stats));
	cl_assert_equal_sz(13, git_diff_stats_insertions(_stats));
	cl_assert_equal_sz(10, git_diff_stats_deletions(_stats));

	cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0));
	cl_assert_equal_s(stat, git_buf_cstr(&buf));
	git_buf_free(&buf);
}
Exemplo n.º 12
0
PyObject *
DiffStats_files_changed__get__(DiffStats *self)
{
    return PyLong_FromSize_t(git_diff_stats_files_changed(self->stats));
}
Exemplo n.º 13
0
size_t Diff::filesChanged() const {
  std::shared_ptr<git_diff_stats> stats = getStats();
  return git_diff_stats_files_changed(stats.get());
}
Exemplo n.º 14
0
int configctl_git_commit(char *path)
{
	int rc;
	int git_status = -1;
	git_oid oid_blob;
	git_oid oid_tree;
	git_oid oid_commit;
	git_blob *blob;
	git_tree *tree_cmt;
	git_treebuilder *tree_bld;
	char *file;

	file = get_file(path);

#if 0
	// TODO: check if file is changed
	__debug("%s", file);
	git_diff_stats *stats;
	git_diff *diff;
	git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
	opts.pathspec.strings = &file;
	opts.pathspec.count = 1;
	rc = git_diff_index_to_workdir(&diff, repo, NULL, &opts);
	if(rc)
		goto error;
	int diff_num = git_diff_num_deltas(diff);
	__debug("%d", diff_num);

	git_diff_get_stats(&stats, diff);
	int x = git_diff_stats_files_changed(stats);
	__debug("%d", x);

	git_diff_free(diff);
#endif

	rc = git_add(file);
	if (rc)
		goto error;

	rc = git_blob_create_fromworkdir(&oid_blob, repo, file);
	if (rc)
		goto error;

	rc = git_blob_lookup(&blob, repo, &oid_blob);
	if (rc)
		goto error;

	rc = git_treebuilder_new(&tree_bld, repo, NULL );
	if (0 == rc) {
		rc = git_treebuilder_insert(NULL, tree_bld, file, &oid_blob, GIT_FILEMODE_BLOB);
		if (!rc) {
			rc = git_treebuilder_write(&oid_tree, tree_bld);
			if (!rc) {
				rc = git_tree_lookup(&tree_cmt, repo, &oid_tree);
				if (0 == rc) {
					git_commit *commit;
					commit = get_last_commit();
					git_signature_now(&sign, sign_name, sign_email);
					rc = git_commit_create(&oid_commit, repo, "HEAD", sign, sign, NULL,
						commit_message, tree_cmt, 1, (const struct git_commit **) &commit);
					if (!rc) {
						git_status = 0;
						__debug("successful git commit");
					}
					git_tree_free( tree_cmt );
					git_commit_free(commit);
					git_signature_free(sign);
				}
			}
		}
		git_treebuilder_free(tree_bld);
	}
	git_blob_free( blob );

error:
	return git_status;
}
Exemplo n.º 15
0
std::size_t DiffStats::getFilesChanged() const
{
    return git_diff_stats_files_changed(get());
}