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( ...@@ -201,14 +201,12 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
unsigned int n); unsigned int n);
/** /**
* Create a new commit in the repository using `git_object` * Create new commit in the repository from a list of `git_object` pointers
* instances as parameters.
* *
* The message will not be cleaned up. This can be achieved * The message will not be cleaned up automatically. You can do that with
* through `git_message_prettify()`. * the `git_message_prettify()` function.
* *
* @param id Pointer where to store the OID of the * @param id Pointer in which to store the OID of the newly created commit
* newly created commit
* *
* @param repo Repository where to store the commit * @param repo Repository where to store the commit
* *
...@@ -219,11 +217,9 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor( ...@@ -219,11 +217,9 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
* make it point to this commit. If the reference doesn't * make it point to this commit. If the reference doesn't
* exist yet, it will be created. * exist yet, it will be created.
* *
* @param author Signature representing the author and the authory * @param author Signature with author and author time of commit
* time of this commit
* *
* @param committer Signature representing the committer and the * @param committer Signature with committer and * commit time of commit
* commit time of this commit
* *
* @param message_encoding The encoding for the message in the * @param message_encoding The encoding for the message in the
* commit, represented with a standard encoding name. * commit, represented with a standard encoding name.
...@@ -260,18 +256,16 @@ GIT_EXTERN(int) git_commit_create( ...@@ -260,18 +256,16 @@ GIT_EXTERN(int) git_commit_create(
const git_commit *parents[]); const git_commit *parents[]);
/** /**
* Create a new commit in the repository using a variable * Create new commit in the repository using a variable argument list.
* argument list.
* *
* The message will be cleaned up from excess whitespace * The message will be cleaned up from excess whitespace and it will be made
* it will be made sure that the last line ends with a '\n'. * sure that the last line ends with a '\n'.
* *
* The parents for the commit are specified as a variable * The parents for the commit are specified as a variable list of pointers
* list of pointers to `const git_commit *`. Note that this * to `const git_commit *`. Note that this is a convenience method which may
* is a convenience method which may not be safe to export * not be safe to export for certain languages or compilers
* 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 * @see git_commit_create
*/ */
...@@ -287,26 +281,6 @@ GIT_EXTERN(int) git_commit_create_v( ...@@ -287,26 +281,6 @@ GIT_EXTERN(int) git_commit_create_v(
int parent_count, 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_END_DECL GIT_END_DECL
#endif #endif
/*
* 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 @@ ...@@ -9,6 +9,7 @@
#include "git2/object.h" #include "git2/object.h"
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/signature.h" #include "git2/signature.h"
#include "git2/sys/commit.h"
#include "common.h" #include "common.h"
#include "odb.h" #include "odb.h"
...@@ -76,7 +77,7 @@ int git_commit_create_v( ...@@ -76,7 +77,7 @@ int git_commit_create_v(
return res; return res;
} }
int git_commit_create_oid( int git_commit_create_from_oids(
git_oid *oid, git_oid *oid,
git_repository *repo, git_repository *repo,
const char *update_ref, const char *update_ref,
...@@ -92,6 +93,9 @@ int git_commit_create_oid( ...@@ -92,6 +93,9 @@ int git_commit_create_oid(
int i; int i;
git_odb *odb; 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); git_oid__writebuf(&commit, "tree ", tree);
for (i = 0; i < parent_count; ++i) for (i = 0; i < parent_count; ++i)
...@@ -142,7 +146,7 @@ int git_commit_create( ...@@ -142,7 +146,7 @@ int git_commit_create(
int retval, i; int retval, i;
const git_oid **parent_oids; 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 *)); parent_oids = git__malloc(parent_count * sizeof(git_oid *));
GITERR_CHECK_ALLOC(parent_oids); GITERR_CHECK_ALLOC(parent_oids);
...@@ -152,12 +156,13 @@ int git_commit_create( ...@@ -152,12 +156,13 @@ int git_commit_create(
parent_oids[i] = git_object_id((const git_object *)parents[i]); parent_oids[i] = git_object_id((const git_object *)parents[i]);
} }
retval = git_commit_create_oid(oid, repo, update_ref, author, committer, retval = git_commit_create_from_oids(
oid, repo, update_ref, author, committer,
message_encoding, message, message_encoding, message,
git_object_id((const git_object *)tree), git_object_id((const git_object *)tree), parent_count, parent_oids);
parent_count, parent_oids);
git__free((void *)parent_oids); git__free((void *)parent_oids);
return retval; return retval;
} }
......
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