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).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
diff --git a/include/git2/commit.h b/include/git2/commit.h
index e7ef518..0f76012 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -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
diff --git a/include/git2/sys/commit.h b/include/git2/sys/commit.h
new file mode 100644
index 0000000..096e028
--- /dev/null
+++ b/include/git2/sys/commit.h
@@ -0,0 +1,45 @@
+/*
+ * 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
diff --git a/src/commit.c b/src/commit.c
index e6bfd95..dd41692 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -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)