Esempio n. 1
0
static void assert_message_prettifying(char *expected_output, char *input, int strip_comments)
{
	git_buf prettified_message = GIT_BUF_INIT;

	git_message_prettify(&prettified_message, input, strip_comments);
	cl_assert_equal_s(expected_output, git_buf_cstr(&prettified_message));

	git_buf_free(&prettified_message);
}
Esempio n. 2
0
/**
 * ggit_message_prettify:
 * @message: the message.
 * @strip_comments: whether to strip comments.
 * @comment_char: comment character.
 *
 * Prettify a commit message by removing excess whitespace and making sure the
 * last line ends with a newline. If @strip_comments is %TRUE, then lines
 * starting with a @comment_char will be removed.
 *
 * Returns: the prettified message.
 *
 */
gchar *
ggit_message_prettify (const gchar *message,
                       gboolean     strip_comments,
                       gchar        comment_char)
{
	git_buf buf = {0,};
	gchar *d;

	git_message_prettify (&buf, message, strip_comments, comment_char);

	d = g_strdup (buf.ptr);
	git_buf_free (&buf);

	return d;
}
Esempio n. 3
0
/**
 * ggit_message_prettify:
 * @message: the message.
 * @strip_comments: whether to strip comments.
 *
 * Prettify a commit message by removing excess whitespace and making sure the
 * last line ends with a newline. If @strip_comments is %TRUE, then lines
 * starting with a '#' will be removed.
 *
 * Returns: the prettified message.
 *
 */
gchar *
ggit_message_prettify (const gchar *message,
                       gboolean     strip_comments)
{
	gchar *ret;
	gint len;
	gchar *d;

	len = strlen (message) * 2;
	ret = g_new0 (gchar, len);

	git_message_prettify (ret, len, message, strip_comments);

	d = g_strdup (ret);
	g_free (ret);

	return d;
}
Esempio n. 4
0
/*
 *  call-seq:
 *    Rugged.prettify_message(message, strip_comments) -> clean_message
 *
 *  Process a commit or tag message into standard form, by stripping trailing spaces and
 *  comments, and making sure that the message has a proper header line.
 */
static VALUE rb_git_prettify_message(VALUE self, VALUE rb_message, VALUE rb_strip_comments)
{
    char *message;
    int strip_comments, message_len;
    VALUE result;

    Check_Type(rb_message, T_STRING);
    strip_comments = rugged_parse_bool(rb_strip_comments);

    message_len = (int)RSTRING_LEN(rb_message) + 2;
    message = xmalloc(message_len);

    message_len = git_message_prettify(message, message_len, StringValueCStr(rb_message), strip_comments);
    rugged_exception_check(message_len);

    result = rb_enc_str_new(message, message_len - 1, rb_utf8_encoding());
    xfree(message);

    return result;
}
Esempio n. 5
0
/*
 *  call-seq:
 *    Rugged.prettify_message(message, strip_comments = '#') -> clean_message
 *
 *  Process a commit or tag message into standard form, by stripping trailing spaces and
 *  comments, and making sure that the message has a proper header line.
 */
static VALUE rb_git_prettify_message(int argc, VALUE *argv, VALUE self)
{
	char comment_char = '#';
	int strip_comments = 1;

	git_buf message = { NULL };
	VALUE rb_message, rb_strip;
	int error;
	VALUE result = Qnil;

	rb_scan_args(argc, argv, "11", &rb_message, &rb_strip);

	Check_Type(rb_message, T_STRING);

	switch (TYPE(rb_strip)) {
	case T_FALSE:
		strip_comments = 0;
		break;

	case T_STRING:
		if (RSTRING_LEN(rb_strip) > 0)
			comment_char = RSTRING_PTR(rb_strip)[0];
		break;

	case T_TRUE:
	case T_NIL:
	default:
		break;
	}

	error = git_message_prettify(&message,
				StringValueCStr(rb_message), strip_comments, comment_char);

	if (!error)
		result = rb_enc_str_new(message.ptr, message.size, rb_utf8_encoding());

	git_buf_free(&message);
	rugged_exception_check(error);

	return result;
}
Esempio n. 6
0
bool PmrWorkspace::commit(const QString &pMessage)
{
    // Make sure that we are open

    if (!isOpen()) {
        return false;
    }

    // Get an empty buffer to hold the cleaned message

    git_buf message;

    message.ptr = nullptr;

    git_buf_set(&message, nullptr, 0);

    // Clean up the message and remove comments (which start with ";")

    git_message_prettify(&message, pMessage.toUtf8().constData(), 1, ';');

    bool res = true;

    if (message.size != 0) {
        int parentsCount = -1;
        git_commit *parent = nullptr;

        if (git_repository_head_unborn(mGitRepository) == 1) {
            // We are committing to an empty repository

            parentsCount = 0;
        } else {
            // Get HEAD as the commit object to use as the parent of the commit

            git_oid parentId;

            if (   (git_reference_name_to_id(&parentId, mGitRepository, "HEAD") == GIT_OK)
                && (git_commit_lookup(&parent, mGitRepository, &parentId) == GIT_OK)) {
                parentsCount = 1;
            }
        }

        if (parentsCount >= 0) {
            res = commit(message.ptr, size_t(parentsCount),
                         const_cast<const git_commit **>(&parent));

            if (!res) {
                emitGitError(tr("An error occurred while trying to commit to the workspace (you must provide both a name and an email)."));
            }
        }

        if (parent != nullptr) {
            git_commit_free(parent);
        }
    } else {
        emitGitError(tr("An error occurred while trying to commit to the workspace (you must provide a message)."));
    }

    git_buf_dispose(&message);

    return res;
}
Esempio n. 7
0
void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
{
	git_index *index;
	const git_index_entry *entry;
	git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid;
	git_signature *signature;
	git_tree *tree;
	char buffer[128];

	/*
	 * The test below replicates the following git scenario
	 *
	 * $ echo "test" > test.txt
	 * $ git hash-object test.txt
	 * 9daeafb9864cf43055ae93beb0afd6c7d144bfa4
	 *
	 * $ git add .
	 * $ git commit -m "Initial commit"
	 *
	 * $ git log
	 * commit 1fe3126578fc4eca68c193e4a3a0a14a0704624d
	 * Author: nulltoken <*****@*****.**>
	 * Date:   Wed Dec 14 08:29:03 2011 +0100
	 *
	 *     Initial commit
	 *
	 * $ git show 1fe3 --format=raw
	 * commit 1fe3126578fc4eca68c193e4a3a0a14a0704624d
	 * tree 2b297e643c551e76cfa1f93810c50811382f9117
	 * author nulltoken <*****@*****.**> 1323847743 +0100
	 * committer nulltoken <*****@*****.**> 1323847743 +0100
	 * 
	 *     Initial commit
	 * 
	 * diff --git a/test.txt b/test.txt
	 * new file mode 100644
	 * index 0000000..9daeafb
	 * --- /dev/null
	 * +++ b/test.txt
	 * @@ -0,0 +1 @@
	 * +test
	 *
	 * $ git ls-tree 2b297
	 * 100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4    test.txt
	 */

	cl_git_pass(git_oid_fromstr(&expected_commit_oid, "1fe3126578fc4eca68c193e4a3a0a14a0704624d"));
	cl_git_pass(git_oid_fromstr(&expected_tree_oid, "2b297e643c551e76cfa1f93810c50811382f9117"));
	cl_git_pass(git_oid_fromstr(&expected_blob_oid, "9daeafb9864cf43055ae93beb0afd6c7d144bfa4"));

	/*
	 * Add a new file to the index
	 */
	cl_git_mkfile("treebuilder/test.txt", "test\n");
	cl_git_pass(git_repository_index(&index, repo));
	cl_git_pass(git_index_add_bypath(index, "test.txt"));

	entry = git_index_get_byindex(index, 0);

	cl_assert(git_oid_cmp(&expected_blob_oid, &entry->oid) == 0);

	/*
	 * Information about index entry should match test file
	 */
	{
		struct stat st;
		cl_must_pass(p_lstat("treebuilder/test.txt", &st));
		cl_assert(entry->file_size == st.st_size);
#ifndef _WIN32
		/*
		 * Windows doesn't populate these fields, and the signage is
		 * wrong in the Windows version of the struct, so lets avoid
		 * the "comparing signed and unsigned" compilation warning in
		 * that case.
		 */
		cl_assert(entry->uid == st.st_uid);
		cl_assert(entry->gid == st.st_gid);
#endif
	}

	/*
	 * Build the tree from the index
	 */
	cl_git_pass(git_index_write_tree(&tree_oid, index));

	cl_assert(git_oid_cmp(&expected_tree_oid, &tree_oid) == 0);

	/*
	 * Commit the staged file
	 */
	cl_git_pass(git_signature_new(&signature, "nulltoken", "*****@*****.**", 1323847743, 60));
	cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));

	cl_assert_equal_i(16, git_message_prettify(buffer, 128, "Initial commit", 0));

	cl_git_pass(git_commit_create_v(
		&commit_oid,
		repo,
		"HEAD",
		signature,
		signature,
		NULL,
		buffer,
		tree,
		0));

	cl_assert(git_oid_cmp(&expected_commit_oid, &commit_oid) == 0);

	git_signature_free(signature);
	git_tree_free(tree);
	git_index_free(index);
}