Commit 9233b3de by Russell Belfer

Move git_commit_create_from_oids into sys/commit.h

Actually this renames git_commit_create_oid to
git_commit_create_from_oids and moves the API declaration to
include/git2/sys/commit.h since it is a dangerous API for general
use (because it doesn't check that the OID list items actually
refer to real objects).
parent 92550398
......@@ -201,14 +201,12 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
unsigned int n);
/**
* Create a new commit in the repository using `git_object`
* instances as parameters.
* Create new commit in the repository from a list of `git_object` pointers
*
* The message will not be cleaned up. This can be achieved
* through `git_message_prettify()`.
* The message will not be cleaned up automatically. You can do that with
* the `git_message_prettify()` function.
*
* @param id Pointer where to store the OID of the
* newly created commit
* @param id Pointer in which to store the OID of the newly created commit
*
* @param repo Repository where to store the commit
*
......@@ -219,93 +217,69 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
* make it point to this commit. If the reference doesn't
* exist yet, it will be created.
*
* @param author Signature representing the author and the authory
* time of this commit
* @param author Signature with author and author time of commit
*
* @param committer Signature representing the committer and the
* commit time of this commit
* @param committer Signature with committer and * commit time of commit
*
* @param message_encoding The encoding for the message in the
* commit, represented with a standard encoding name.
* E.g. "UTF-8". If NULL, no encoding header is written and
* UTF-8 is assumed.
* commit, represented with a standard encoding name.
* E.g. "UTF-8". If NULL, no encoding header is written and
* UTF-8 is assumed.
*
* @param message Full message for this commit
*
* @param tree An instance of a `git_tree` object that will
* be used as the tree for the commit. This tree object must
* also be owned by the given `repo`.
* be used as the tree for the commit. This tree object must
* also be owned by the given `repo`.
*
* @param parent_count Number of parents for this commit
*
* @param parents[] Array of `parent_count` pointers to `git_commit`
* objects that will be used as the parents for this commit. This
* array may be NULL if `parent_count` is 0 (root commit). All the
* given commits must be owned by the `repo`.
* objects that will be used as the parents for this commit. This
* array may be NULL if `parent_count` is 0 (root commit). All the
* given commits must be owned by the `repo`.
*
* @return 0 or an error code
* The created commit will be written to the Object Database and
* the given reference will be updated to point to it
*/
GIT_EXTERN(int) git_commit_create(
git_oid *id,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
int parent_count,
const git_commit *parents[]);
git_oid *id,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
int parent_count,
const git_commit *parents[]);
/**
* Create a new commit in the repository using a variable
* argument list.
* Create new commit in the repository using a variable argument list.
*
* The message will be cleaned up from excess whitespace
* it will be made sure that the last line ends with a '\n'.
* The message will be cleaned up from excess whitespace and it will be made
* sure that the last line ends with a '\n'.
*
* The parents for the commit are specified as a variable
* list of pointers to `const git_commit *`. Note that this
* is a convenience method which may not be safe to export
* for certain languages or compilers
* The parents for the commit are specified as a variable list of pointers
* to `const git_commit *`. Note that this is a convenience method which may
* not be safe to export for certain languages or compilers
*
* All other parameters remain the same
* All other parameters remain the same at `git_commit_create()`.
*
* @see git_commit_create
*/
GIT_EXTERN(int) git_commit_create_v(
git_oid *id,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
int parent_count,
...);
/**
* Create a new commit in the repository, as with `git_commit_create`,
* using `git_oid` instances as parameters instead of `git_object`.
*
* See documentation for `git_commit_create` for information about the
* parameters, as the meaning is identical excepting that `tree` and
* `parents` now take `git_oid`.
*/
GIT_EXTERN(int) git_commit_create_oid(
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_oid *tree,
int parent_count,
const git_oid *parents[]);
git_oid *id,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
int parent_count,
...);
/** @} */
GIT_END_DECL
......
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sys_git_commit_h__
#define INCLUDE_sys_git_commit_h__
#include "git2/common.h"
#include "git2/types.h"
#include "git2/oid.h"
/**
* @file git2/sys/commit.h
* @brief Low-level Git commit creation
* @defgroup git_backend Git custom backend APIs
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Create new commit in the repository from a list of `git_oid` values
*
* See documentation for `git_commit_create()` for information about the
* parameters, as the meaning is identical excepting that `tree` and
* `parents` now take `git_oid`. This is a dangerous API in that the
* `parents` list of `git_oid`s in not checked for validity.
*/
GIT_EXTERN(int) git_commit_create_from_oids(
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_oid *tree,
int parent_count,
const git_oid *parents[]);
/** @} */
GIT_END_DECL
#endif
......@@ -9,6 +9,7 @@
#include "git2/object.h"
#include "git2/repository.h"
#include "git2/signature.h"
#include "git2/sys/commit.h"
#include "common.h"
#include "odb.h"
......@@ -44,16 +45,16 @@ void git_commit__free(git_commit *commit)
}
int git_commit_create_v(
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
int parent_count,
...)
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
int parent_count,
...)
{
va_list ap;
int i, res;
......@@ -76,22 +77,25 @@ int git_commit_create_v(
return res;
}
int git_commit_create_oid(
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_oid *tree,
int parent_count,
const git_oid *parents[])
int git_commit_create_from_oids(
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_oid *tree,
int parent_count,
const git_oid *parents[])
{
git_buf commit = GIT_BUF_INIT;
int i;
git_odb *odb;
assert(oid && repo && tree && parent_count >= 0);
assert(git_object_owner((const git_object *)tree) == repo);
git_oid__writebuf(&commit, "tree ", tree);
for (i = 0; i < parent_count; ++i)
......@@ -128,21 +132,21 @@ on_error:
}
int git_commit_create(
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
int parent_count,
const git_commit *parents[])
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
int parent_count,
const git_commit *parents[])
{
int retval, i;
int retval, i;
const git_oid **parent_oids;
assert(git_object_owner((const git_object *)tree) == repo);
assert(parent_count >= 0);
parent_oids = git__malloc(parent_count * sizeof(git_oid *));
GITERR_CHECK_ALLOC(parent_oids);
......@@ -152,13 +156,14 @@ int git_commit_create(
parent_oids[i] = git_object_id((const git_object *)parents[i]);
}
retval = git_commit_create_oid(oid, repo, update_ref, author, committer,
message_encoding, message,
git_object_id((const git_object *)tree),
parent_count, parent_oids);
retval = git_commit_create_from_oids(
oid, repo, update_ref, author, committer,
message_encoding, message,
git_object_id((const git_object *)tree), parent_count, parent_oids);
git__free((void *)parent_oids);
return retval;
return retval;
}
int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment