Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
eb095435
Commit
eb095435
authored
Nov 30, 2010
by
Justin Love
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add git_commit_parent to retrieve a parent by index
parent
12114415
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
1 deletions
+30
-1
src/commit.c
+14
-0
src/git/commit.h
+8
-0
tests/t0402-details.c
+8
-1
No files found.
src/commit.c
View file @
eb095435
...
@@ -272,6 +272,20 @@ unsigned int git_commit_parentcount(git_commit *commit)
...
@@ -272,6 +272,20 @@ unsigned int git_commit_parentcount(git_commit *commit)
return
count
;
return
count
;
}
}
git_commit
*
git_commit_parent
(
git_commit
*
commit
,
unsigned
int
n
)
{
git_commit_parents
*
parent
;
assert
(
commit
);
CHECK_FULL_PARSE
();
for
(
parent
=
commit
->
parents
;
parent
!=
NULL
&&
n
>
0
;
parent
=
parent
->
next
)
{
n
--
;
}
return
parent
?
parent
->
commit
:
NULL
;
}
void
git_commit_set_tree
(
git_commit
*
commit
,
git_tree
*
tree
)
void
git_commit_set_tree
(
git_commit
*
commit
,
git_tree
*
tree
)
{
{
assert
(
commit
&&
tree
);
assert
(
commit
&&
tree
);
...
...
src/git/commit.h
View file @
eb095435
...
@@ -102,6 +102,14 @@ GIT_EXTERN(const git_tree *) git_commit_tree(git_commit *commit);
...
@@ -102,6 +102,14 @@ GIT_EXTERN(const git_tree *) git_commit_tree(git_commit *commit);
GIT_EXTERN
(
unsigned
int
)
git_commit_parentcount
(
git_commit
*
commit
);
GIT_EXTERN
(
unsigned
int
)
git_commit_parentcount
(
git_commit
*
commit
);
/**
/**
* Get the specified parent of the commit.
* @param commit a previously loaded commit.
* @param n the position of the entry
* @return a pointer to the commit; NULL if out of bounds
*/
GIT_EXTERN
(
git_commit
*
)
git_commit_parent
(
git_commit
*
commit
,
unsigned
int
n
);
/**
* Add a new parent commit to an existing commit
* Add a new parent commit to an existing commit
* @param commit the commit object
* @param commit the commit object
* @param new_parent the new commit which will be a parent
* @param new_parent the new commit which will be a parent
...
...
tests/t0402-details.c
View file @
eb095435
...
@@ -31,7 +31,8 @@ BEGIN_TEST(query_details_test)
...
@@ -31,7 +31,8 @@ BEGIN_TEST(query_details_test)
const
git_person
*
author
,
*
committer
;
const
git_person
*
author
,
*
committer
;
const
char
*
message
,
*
message_short
;
const
char
*
message
,
*
message_short
;
time_t
commit_time
;
time_t
commit_time
;
unsigned
int
parents
;
unsigned
int
parents
,
p
;
git_commit
*
parent
;
git_oid_mkstr
(
&
id
,
commit_ids
[
i
]);
git_oid_mkstr
(
&
id
,
commit_ids
[
i
]);
...
@@ -52,6 +53,12 @@ BEGIN_TEST(query_details_test)
...
@@ -52,6 +53,12 @@ BEGIN_TEST(query_details_test)
must_be_true
(
strchr
(
message_short
,
'\n'
)
==
NULL
);
must_be_true
(
strchr
(
message_short
,
'\n'
)
==
NULL
);
must_be_true
(
commit_time
>
0
);
must_be_true
(
commit_time
>
0
);
must_be_true
(
0
<=
parents
&&
parents
<=
2
);
must_be_true
(
0
<=
parents
&&
parents
<=
2
);
for
(
p
=
0
;
p
<
parents
;
p
++
)
{
parent
=
git_commit_parent
(
commit
,
p
);
must_be_true
(
parent
!=
NULL
);
must_be_true
(
git_commit_author
(
parent
)
!=
NULL
);
// is it really a commit?
}
must_be_true
(
git_commit_parent
(
commit
,
parents
)
==
NULL
);
}
}
git_repository_free
(
repo
);
git_repository_free
(
repo
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment