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
3704ac35
Commit
3704ac35
authored
Jul 07, 2015
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3277 from git-up/git_diff_index_to_index
Added git_diff_index_to_index()
parents
ea445e06
ccef5adb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
+76
-0
include/git2/diff.h
+19
-0
src/diff.c
+25
-0
tests/diff/index.c
+32
-0
No files found.
include/git2/diff.h
View file @
3704ac35
...
...
@@ -836,6 +836,25 @@ GIT_EXTERN(int) git_diff_tree_to_workdir_with_index(
const
git_diff_options
*
opts
);
/**< can be NULL for defaults */
/**
* Create a diff with the difference between two index objects.
*
* The first index will be used for the "old_file" side of the delta and the
* second index will be used for the "new_file" side of the delta.
*
* @param diff Output pointer to a git_diff pointer to be allocated.
* @param repo The repository containing the indexes.
* @param old_index A git_index object to diff from.
* @param new_index A git_index object to diff to.
* @param opts Structure with options to influence diff or NULL for defaults.
*/
GIT_EXTERN
(
int
)
git_diff_index_to_index
(
git_diff
**
diff
,
git_repository
*
repo
,
git_index
*
old_index
,
git_index
*
new_index
,
const
git_diff_options
*
opts
);
/**< can be NULL for defaults */
/**
* Merge one diff into another.
*
* This merges items from the "from" list into the "onto" list. The
...
...
src/diff.c
View file @
3704ac35
...
...
@@ -1421,6 +1421,31 @@ int git_diff_tree_to_workdir_with_index(
return
error
;
}
int
git_diff_index_to_index
(
git_diff
**
diff
,
git_repository
*
repo
,
git_index
*
old_index
,
git_index
*
new_index
,
const
git_diff_options
*
opts
)
{
int
error
=
0
;
assert
(
diff
&&
old_index
&&
new_index
);
DIFF_FROM_ITERATORS
(
git_iterator_for_index
(
&
a
,
old_index
,
GIT_ITERATOR_DONT_IGNORE_CASE
,
pfx
,
pfx
),
git_iterator_for_index
(
&
b
,
new_index
,
GIT_ITERATOR_DONT_IGNORE_CASE
,
pfx
,
pfx
)
);
/* if index is in case-insensitive order, re-sort deltas to match */
if
(
!
error
&&
(
old_index
->
ignore_case
||
new_index
->
ignore_case
))
diff_set_ignore_case
(
*
diff
,
true
);
return
error
;
}
size_t
git_diff_num_deltas
(
const
git_diff
*
diff
)
{
assert
(
diff
);
...
...
tests/diff/index.c
View file @
3704ac35
...
...
@@ -268,3 +268,35 @@ void test_diff_index__not_in_head_conflicted(void)
git_index_free
(
index
);
git_tree_free
(
a
);
}
void
test_diff_index__to_index
(
void
)
{
const
char
*
a_commit
=
"26a125ee1bf"
;
/* the current HEAD */
git_tree
*
old_tree
;
git_index
*
old_index
;
git_index
*
new_index
;
git_diff
*
diff
;
diff_expects
exp
;
cl_git_pass
(
git_index_new
(
&
old_index
));
old_tree
=
resolve_commit_oid_to_tree
(
g_repo
,
a_commit
);
cl_git_pass
(
git_index_read_tree
(
old_index
,
old_tree
));
cl_git_pass
(
git_repository_index
(
&
new_index
,
g_repo
));
cl_git_pass
(
git_diff_index_to_index
(
&
diff
,
g_repo
,
old_index
,
new_index
,
NULL
));
memset
(
&
exp
,
0
,
sizeof
(
diff_expects
));
cl_git_pass
(
git_diff_foreach
(
diff
,
diff_file_cb
,
diff_binary_cb
,
diff_hunk_cb
,
diff_line_cb
,
&
exp
));
cl_assert_equal_i
(
8
,
exp
.
files
);
cl_assert_equal_i
(
3
,
exp
.
file_status
[
GIT_DELTA_ADDED
]);
cl_assert_equal_i
(
2
,
exp
.
file_status
[
GIT_DELTA_DELETED
]);
cl_assert_equal_i
(
3
,
exp
.
file_status
[
GIT_DELTA_MODIFIED
]);
cl_assert_equal_i
(
0
,
exp
.
file_status
[
GIT_DELTA_CONFLICTED
]);
git_diff_free
(
diff
);
git_index_free
(
new_index
);
git_index_free
(
old_index
);
git_tree_free
(
old_tree
);
}
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