s/git_merge_head/git_annotated_commit · nodegit/libgit2@18b0040 · GitHub
Skip to content

Commit 18b0040

Browse files
author
Edward Thomson
committed
s/git_merge_head/git_annotated_commit
Rename git_merge_head to git_annotated_commit, as it becomes used in more operations than just merge.
1 parent 796b03b commit 18b0040

21 files changed

Lines changed: 700 additions & 631 deletions

‎include/git2.h‎

Lines changed: 1 addition & 0 deletions

‎include/git2/annotated_commit.h‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
#ifndef INCLUDE_git_annotated_commit_h__
8+
#define INCLUDE_git_annotated_commit_h__
9+
10+
#include "common.h"
11+
#include "repository.h"
12+
#include "types.h"
13+
14+
/**
15+
* @file git2/annotated_commit.h
16+
* @brief Git annotated commit routines
17+
* @defgroup git_annotated_commit Git annotated commit routines
18+
* @ingroup Git
19+
* @{
20+
*/
21+
GIT_BEGIN_DECL
22+
23+
/**
24+
* Creates a `git_annotated_commit` from the given reference.
25+
* The resulting git_annotated_commit must be freed with
26+
* `git_annotated_commit_free`.
27+
*
28+
* @param out pointer to store the git_annotated_commit result in
29+
* @param repo repository that contains the given reference
30+
* @param ref reference to use to lookup the git_annotated_commit
31+
* @return 0 on success or error code
32+
*/
33+
GIT_EXTERN(int) git_annotated_commit_from_ref(
34+
git_annotated_commit **out,
35+
git_repository *repo,
36+
const git_reference *ref);
37+
38+
/**
39+
* Creates a `git_annotated_commit` from the given fetch head data.
40+
* The resulting git_annotated_commit must be freed with
41+
* `git_annotated_commit_free`.
42+
*
43+
* @param out pointer to store the git_annotated_commit result in
44+
* @param repo repository that contains the given commit
45+
* @param branch_name name of the (remote) branch
46+
* @param remote_url url of the remote
47+
* @param oid the commit object id of the remote branch
48+
* @return 0 on success or error code
49+
*/
50+
GIT_EXTERN(int) git_annotated_commit_from_fetchhead(
51+
git_annotated_commit **out,
52+
git_repository *repo,
53+
const char *branch_name,
54+
const char *remote_url,
55+
const git_oid *id);
56+
57+
/**
58+
* Creates a `git_annotated_commit` from the given commit id.
59+
* The resulting git_annotated_commit must be freed with
60+
* `git_annotated_commit_free`.
61+
*
62+
* An annotated commit contains information about how it was
63+
* looked up, which may be useful for functions like merge or
64+
* rebase to provide context to the operation. For example,
65+
* conflict files will include the name of the source or target
66+
* branches being merged. It is therefore preferable to use the
67+
* most specific function (eg `git_annotated_commit_from_ref`)
68+
* instead of this one when that data is known.
69+
*
70+
* @param out pointer to store the git_annotated_commit result in
71+
* @param repo repository that contains the given commit
72+
* @param id the commit object id to lookup
73+
* @return 0 on success or error code
74+
*/
75+
GIT_EXTERN(int) git_annotated_commit_lookup(
76+
git_annotated_commit **out,
77+
git_repository *repo,
78+
const git_oid *id);
79+
80+
/**
81+
* Gets the commit ID that the given `git_annotated_commit` refers to.
82+
*
83+
* @param head the given annotated commit
84+
* @return commit id
85+
*/
86+
GIT_EXTERN(const git_oid *) git_annotated_commit_id(
87+
const git_annotated_commit *commit);
88+
89+
/**
90+
* Frees a `git_annotated_commit`.
91+
*
92+
* @param annotated_commit annotated commit to free
93+
*/
94+
GIT_EXTERN(void) git_annotated_commit_free(
95+
git_annotated_commit *commit);
96+
97+
/** @} */
98+
GIT_END_DECL
99+
#endif

‎include/git2/merge.h‎

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "oidarray.h"
1414
#include "checkout.h"
1515
#include "index.h"
16+
#include "annotated_commit.h"
1617

1718
/**
1819
* @file git2/merge.h
@@ -303,7 +304,7 @@ GIT_EXTERN(int) git_merge_analysis(
303304
git_merge_analysis_t *analysis_out,
304305
git_merge_preference_t *preference_out,
305306
git_repository *repo,
306-
const git_merge_head **their_heads,
307+
const git_annotated_commit **their_heads,
307308
size_t their_heads_len);
308309

309310
/**
@@ -381,69 +382,6 @@ GIT_EXTERN(int) git_merge_base_octopus(
381382
size_t length,
382383
const git_oid input_array[]);
383384

384-
/**
385-
* Creates a `git_merge_head` from the given reference. The resulting
386-
* git_merge_head must be freed with `git_merge_head_free`.
387-
*
388-
* @param out pointer to store the git_merge_head result in
389-
* @param repo repository that contains the given reference
390-
* @param ref reference to use as a merge input
391-
* @return 0 on success or error code
392-
*/
393-
GIT_EXTERN(int) git_merge_head_from_ref(
394-
git_merge_head **out,
395-
git_repository *repo,
396-
const git_reference *ref);
397-
398-
/**
399-
* Creates a `git_merge_head` from the given fetch head data. The resulting
400-
* git_merge_head must be freed with `git_merge_head_free`.
401-
*
402-
* @param out pointer to store the git_merge_head result in
403-
* @param repo repository that contains the given commit
404-
* @param branch_name name of the (remote) branch
405-
* @param remote_url url of the remote
406-
* @param oid the commit object id to use as a merge input
407-
* @return 0 on success or error code
408-
*/
409-
GIT_EXTERN(int) git_merge_head_from_fetchhead(
410-
git_merge_head **out,
411-
git_repository *repo,
412-
const char *branch_name,
413-
const char *remote_url,
414-
const git_oid *oid);
415-
416-
/**
417-
* Creates a `git_merge_head` from the given commit id. The resulting
418-
* git_merge_head must be freed with `git_merge_head_free`.
419-
*
420-
* @param out pointer to store the git_merge_head result in
421-
* @param repo repository that contains the given commit
422-
* @param id the commit object id to use as a merge input
423-
* @return 0 on success or error code
424-
*/
425-
GIT_EXTERN(int) git_merge_head_from_id(
426-
git_merge_head **out,
427-
git_repository *repo,
428-
const git_oid *id);
429-
430-
/**
431-
* Gets the commit ID that the given `git_merge_head` refers to.
432-
*
433-
* @param head the given merge head
434-
* @return commit id
435-
*/
436-
GIT_EXTERN(const git_oid *) git_merge_head_id(
437-
const git_merge_head *head);
438-
439-
/**
440-
* Frees a `git_merge_head`.
441-
*
442-
* @param head merge head to free
443-
*/
444-
GIT_EXTERN(void) git_merge_head_free(
445-
git_merge_head *head);
446-
447385
/**
448386
* Merge two files as they exist in the in-memory data structures, using
449387
* the given common ancestor as the baseline, producing a
@@ -557,7 +495,7 @@ GIT_EXTERN(int) git_merge_commits(
557495
*/
558496
GIT_EXTERN(int) git_merge(
559497
git_repository *repo,
560-
const git_merge_head **their_heads,
498+
const git_annotated_commit **their_heads,
561499
size_t their_heads_len,
562500
const git_merge_options *merge_opts,
563501
const git_checkout_options *checkout_opts);

‎include/git2/rebase.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "common.h"
1111
#include "types.h"
1212
#include "oid.h"
13+
#include "annotated_commit.h"
1314

1415
/**
1516
* @file git2/rebase.h
@@ -133,9 +134,9 @@ GIT_EXTERN(int) git_rebase_init_options(
133134
GIT_EXTERN(int) git_rebase_init(
134135
git_rebase **out,
135136
git_repository *repo,
136-
const git_merge_head *branch,
137-
const git_merge_head *upstream,
138-
const git_merge_head *onto,
137+
const git_annotated_commit *branch,
138+
const git_annotated_commit *upstream,
139+
const git_annotated_commit *onto,
139140
const git_signature *signature,
140141
const git_rebase_options *opts);
141142

‎include/git2/types.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ typedef struct git_reference_iterator git_reference_iterator;
174174
/** Transactional interface to references */
175175
typedef struct git_transaction git_transaction;
176176

177-
/** Merge heads, the input to merge */
178-
typedef struct git_merge_head git_merge_head;
177+
/** Annotated commits, the input to merge and rebase. */
178+
typedef struct git_annotated_commit git_annotated_commit;
179179

180180
/** Merge result */
181181
typedef struct git_merge_result git_merge_result;

‎src/annotated_commit.c‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
8+
#include "common.h"
9+
#include "annotated_commit.h"
10+
11+
#include "git2/commit.h"
12+
#include "git2/refs.h"
13+
#include "git2/repository.h"
14+
#include "git2/annotated_commit.h"
15+
16+
static int annotated_commit_init(
17+
git_annotated_commit **out,
18+
git_repository *repo,
19+
const git_oid *id,
20+
const char *ref_name,
21+
const char *remote_url)
22+
{
23+
git_annotated_commit *annotated_commit;
24+
int error = 0;
25+
26+
assert(out && id);
27+
28+
*out = NULL;
29+
30+
annotated_commit = git__calloc(1, sizeof(git_annotated_commit));
31+
GITERR_CHECK_ALLOC(annotated_commit);
32+
33+
if (ref_name) {
34+
annotated_commit->ref_name = git__strdup(ref_name);
35+
GITERR_CHECK_ALLOC(annotated_commit->ref_name);
36+
}
37+
38+
if (remote_url) {
39+
annotated_commit->remote_url = git__strdup(remote_url);
40+
GITERR_CHECK_ALLOC(annotated_commit->remote_url);
41+
}
42+
43+
git_oid_fmt(annotated_commit->id_str, id);
44+
annotated_commit->id_str[GIT_OID_HEXSZ] = '\0';
45+
46+
if ((error = git_commit_lookup(&annotated_commit->commit, repo, id)) < 0) {
47+
git_annotated_commit_free(annotated_commit);
48+
return error;
49+
}
50+
51+
*out = annotated_commit;
52+
return error;
53+
}
54+
55+
int git_annotated_commit_from_ref(
56+
git_annotated_commit **out,
57+
git_repository *repo,
58+
const git_reference *ref)
59+
{
60+
git_reference *resolved;
61+
int error = 0;
62+
63+
assert(out && repo && ref);
64+
65+
*out = NULL;
66+
67+
if ((error = git_reference_resolve(&resolved, ref)) < 0)
68+
return error;
69+
70+
error = annotated_commit_init(out, repo, git_reference_target(resolved),
71+
git_reference_name(ref), NULL);
72+
73+
git_reference_free(resolved);
74+
return error;
75+
}
76+
77+
int git_annotated_commit_lookup(
78+
git_annotated_commit **out,
79+
git_repository *repo,
80+
const git_oid *id)
81+
{
82+
assert(out && repo && id);
83+
84+
return annotated_commit_init(out, repo, id, NULL, NULL);
85+
}
86+
87+
int git_annotated_commit_from_fetchhead(
88+
git_annotated_commit **out,
89+
git_repository *repo,
90+
const char *branch_name,
91+
const char *remote_url,
92+
const git_oid *id)
93+
{
94+
assert(repo && id && branch_name && remote_url);
95+
96+
return annotated_commit_init(out, repo, id, branch_name, remote_url);
97+
}
98+
99+
const git_oid *git_annotated_commit_id(
100+
const git_annotated_commit *annotated_commit)
101+
{
102+
assert(annotated_commit);
103+
return git_commit_id(annotated_commit->commit);
104+
}
105+
106+
void git_annotated_commit_free(git_annotated_commit *annotated_commit)
107+
{
108+
if (annotated_commit == NULL)
109+
return;
110+
111+
if (annotated_commit->commit != NULL)
112+
git_commit_free(annotated_commit->commit);
113+
114+
if (annotated_commit->ref_name != NULL)
115+
git__free(annotated_commit->ref_name);
116+
117+
if (annotated_commit->remote_url != NULL)
118+
git__free(annotated_commit->remote_url);
119+
120+
git__free(annotated_commit);
121+
}

‎src/annotated_commit.h‎

Lines changed: 22 additions & 0 deletions

0 commit comments

Comments
 (0)