Exemplo n.º 1
0
OId Commit::amend(const Tree& tree, const QString& ref, const QString& message, const Signature& author, const Signature& committer)
{
    OId oid;
    qGitThrow(git_commit_amend(oid.data(), constData(), ref.isEmpty() ? NULL : PathCodec::toLibGit2(ref).constData(), author.data(), committer.data(),
                               NULL, message.isNull() ? NULL : message.toUtf8().constData(), tree.constData()));
    return oid;
}
Exemplo n.º 2
0
Arquivo: commit.c Projeto: jwes/luagi
/*
 * Needs a table
 * supported field names:
 * update_ref
 * author
 * committer
 * message_encoding
 * message
 * tree
 */
int luagi_commit_amend( lua_State *L )
{
   git_commit** commit = checkcommit( L );

   luaL_checktype( L, 2, LUA_TTABLE);
   // since all elements can be null, we use a table...

   lua_getfield( L, 2, "update_ref");
   const char* update_ref = luaL_optstring( L, -1, NULL );
   git_signature* author = NULL;
   int ret = 0;
   lua_getfield( L, 2, "author" );
   if( lua_istable( L, -1 ) )
   {
      ret = table_to_signature( L, &author, -1 );
   }
   git_signature* committer = NULL;
   lua_getfield( L, 2, "committer" );
   if( lua_istable( L, -1 ) )
   {
      ret = table_to_signature( L, &committer, -1 );
   }

   lua_getfield( L, 2, "message_encoding" );
   const char* message_encoding = luaL_optstring( L, -1, NULL );

   lua_getfield( L, 2, "message" );
   const char* message = luaL_optstring( L, -1, NULL );
   
   lua_getfield( L, 2, "tree" );
   git_tree* tree = NULL;
   if( lua_isuserdata( L, -1 ) )
   {
      tree = *( ( git_tree** ) luaL_checkudata( L, -1, LUAGI_TREE_FUNCS ) );
   }

   // use the table and modify the commit
   git_oid outid;
   ret = git_commit_amend( &outid, *commit, update_ref, author, committer, message_encoding, message, tree );
   git_signature_free( author );
   git_signature_free( committer );
   if( ret != 0 )
   {
      lua_pushnil( L );
      lua_pushfstring( L, "commit amend failed %d", ret );
      return 2;
   }
   return luagi_push_oid( L, &outid );
}
Exemplo n.º 3
0
/*
 *  call-seq:
 *    commit.amend(data = {}) -> oid
 *
 *  Amend a commit object, with the given +data+
 *  arguments, passed as a +Hash+:
 *
 *  - +:message+: a string with the full text for the commit's message
 *  - +:committer+ (optional): a hash with the signature for the committer,
 *    defaults to the signature from the configuration
 *  - +:author+ (optional): a hash with the signature for the author,
 *    defaults to the signature from the configuration
 *  - +:tree+: the tree for this amended commit, represented as a <tt>Rugged::Tree</tt>
 *    instance or an OID +String+.
 *  - +:update_ref+ (optional): a +String+ with the name of a reference in the
 *  repository which should be updated to point to this amended commit (e.g. "HEAD")
 *
 *  When the amended commit is successfully written to disk, its +oid+ will be
 *  returned as a hex +String+.
 *
 *    author = {:email=>"*****@*****.**", :time=>Time.now, :name=>"Vicent Mart\303\255"}
 *
 *    commit.amend(
 *      :author => author,
 *      :message => "Updated Hello world\n\n",
 *      :committer => author,
 *      :tree => some_tree) #=> "f148106ca58764adc93ad4e2d6b1d168422b9796"
 */
static VALUE rb_git_commit_amend(VALUE self, VALUE rb_data)
{
	VALUE rb_message, rb_tree, rb_ref, owner;
	int error = 0;
	git_commit *commit_to_amend;
	char *message = NULL;
	git_tree *tree = NULL;
	git_signature *author = NULL, *committer = NULL;
	git_oid commit_oid;
	git_repository *repo;
	const char *update_ref = NULL;

	Check_Type(rb_data, T_HASH);

	Data_Get_Struct(self, git_commit, commit_to_amend);

	owner = rugged_owner(self);
	Data_Get_Struct(owner, git_repository, repo);

	rb_ref = rb_hash_aref(rb_data, CSTR2SYM("update_ref"));
	if (!NIL_P(rb_ref)) {
		Check_Type(rb_ref, T_STRING);
		update_ref = StringValueCStr(rb_ref);
	}

	rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
	if (!NIL_P(rb_message)) {
		Check_Type(rb_message, T_STRING);
		message = StringValueCStr(rb_message);
	}

	rb_tree = rb_hash_aref(rb_data, CSTR2SYM("tree"));
	if (!NIL_P(rb_tree))
		tree = (git_tree *)rugged_object_get(repo, rb_tree, GIT_OBJ_TREE);

	if (!NIL_P(rb_hash_aref(rb_data, CSTR2SYM("committer")))) {
		committer = rugged_signature_get(
			rb_hash_aref(rb_data, CSTR2SYM("committer")), repo
		);
	}

	if (!NIL_P(rb_hash_aref(rb_data, CSTR2SYM("author")))) {
		author = rugged_signature_get(
			rb_hash_aref(rb_data, CSTR2SYM("author")), repo
		);
	}

	error = git_commit_amend(
		&commit_oid,
		commit_to_amend,
		update_ref,
		author,
		committer,
		NULL,
		message,
		tree);

	git_signature_free(author);
	git_signature_free(committer);

	git_object_free((git_object *)tree);

	rugged_exception_check(error);

	return rugged_create_oid(&commit_oid);
}