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
e479628a
Commit
e479628a
authored
Nov 19, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1966 from nickh/patch_content_offsets
Add content offset to git_diff_line
parents
7146eff3
d8e7ffc2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
4 deletions
+20
-4
include/git2/diff.h
+1
-0
src/diff_xdiff.c
+13
-4
tests/diff/patch.c
+6
-0
No files found.
include/git2/diff.h
View file @
e479628a
...
@@ -446,6 +446,7 @@ struct git_diff_line {
...
@@ -446,6 +446,7 @@ struct git_diff_line {
int
new_lineno
;
/** Line number in new file or -1 for deleted line */
int
new_lineno
;
/** Line number in new file or -1 for deleted line */
int
num_lines
;
/** Number of newline characters in content */
int
num_lines
;
/** Number of newline characters in content */
size_t
content_len
;
/** Number of bytes of data */
size_t
content_len
;
/** Number of bytes of data */
git_off_t
content_offset
;
/** Offset in the original file to the content */
const
char
*
content
;
/** Pointer to diff text, not NUL-byte terminated */
const
char
*
content
;
/** Pointer to diff text, not NUL-byte terminated */
};
};
...
...
src/diff_xdiff.c
View file @
e479628a
...
@@ -54,6 +54,7 @@ typedef struct {
...
@@ -54,6 +54,7 @@ typedef struct {
git_patch
*
patch
;
git_patch
*
patch
;
git_diff_hunk
hunk
;
git_diff_hunk
hunk
;
int
old_lineno
,
new_lineno
;
int
old_lineno
,
new_lineno
;
mmfile_t
xd_old_data
,
xd_new_data
;
}
git_xdiff_info
;
}
git_xdiff_info
;
static
int
diff_update_lines
(
static
int
diff_update_lines
(
...
@@ -135,6 +136,13 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
...
@@ -135,6 +136,13 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
(
*
bufs
[
0
].
ptr
==
'-'
)
?
GIT_DIFF_LINE_DELETION
:
(
*
bufs
[
0
].
ptr
==
'-'
)
?
GIT_DIFF_LINE_DELETION
:
GIT_DIFF_LINE_CONTEXT
;
GIT_DIFF_LINE_CONTEXT
;
if
(
line
.
origin
==
GIT_DIFF_LINE_ADDITION
)
line
.
content_offset
=
bufs
[
1
].
ptr
-
info
->
xd_new_data
.
ptr
;
else
if
(
line
.
origin
==
GIT_DIFF_LINE_DELETION
)
line
.
content_offset
=
bufs
[
1
].
ptr
-
info
->
xd_old_data
.
ptr
;
else
line
.
content_offset
=
-
1
;
output
->
error
=
diff_update_lines
(
output
->
error
=
diff_update_lines
(
info
,
&
line
,
bufs
[
1
].
ptr
,
bufs
[
1
].
size
);
info
,
&
line
,
bufs
[
1
].
ptr
,
bufs
[
1
].
size
);
...
@@ -155,6 +163,8 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
...
@@ -155,6 +163,8 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
(
*
bufs
[
0
].
ptr
==
'-'
)
?
GIT_DIFF_LINE_ADD_EOFNL
:
(
*
bufs
[
0
].
ptr
==
'-'
)
?
GIT_DIFF_LINE_ADD_EOFNL
:
GIT_DIFF_LINE_CONTEXT_EOFNL
;
GIT_DIFF_LINE_CONTEXT_EOFNL
;
line
.
content_offset
=
-
1
;
output
->
error
=
diff_update_lines
(
output
->
error
=
diff_update_lines
(
info
,
&
line
,
bufs
[
2
].
ptr
,
bufs
[
2
].
size
);
info
,
&
line
,
bufs
[
2
].
ptr
,
bufs
[
2
].
size
);
...
@@ -172,7 +182,6 @@ static int git_xdiff(git_diff_output *output, git_patch *patch)
...
@@ -172,7 +182,6 @@ static int git_xdiff(git_diff_output *output, git_patch *patch)
git_xdiff_output
*
xo
=
(
git_xdiff_output
*
)
output
;
git_xdiff_output
*
xo
=
(
git_xdiff_output
*
)
output
;
git_xdiff_info
info
;
git_xdiff_info
info
;
git_diff_find_context_payload
findctxt
;
git_diff_find_context_payload
findctxt
;
mmfile_t
xd_old_data
,
xd_new_data
;
memset
(
&
info
,
0
,
sizeof
(
info
));
memset
(
&
info
,
0
,
sizeof
(
info
));
info
.
patch
=
patch
;
info
.
patch
=
patch
;
...
@@ -193,10 +202,10 @@ static int git_xdiff(git_diff_output *output, git_patch *patch)
...
@@ -193,10 +202,10 @@ static int git_xdiff(git_diff_output *output, git_patch *patch)
* updates are needed to xo->params.flags
* updates are needed to xo->params.flags
*/
*/
git_patch__old_data
(
&
xd_old_data
.
ptr
,
&
xd_old_data
.
size
,
patch
);
git_patch__old_data
(
&
info
.
xd_old_data
.
ptr
,
&
info
.
xd_old_data
.
size
,
patch
);
git_patch__new_data
(
&
xd_new_data
.
ptr
,
&
xd_new_data
.
size
,
patch
);
git_patch__new_data
(
&
info
.
xd_new_data
.
ptr
,
&
info
.
xd_new_data
.
size
,
patch
);
xdl_diff
(
&
xd_old_data
,
&
xd_new_data
,
xdl_diff
(
&
info
.
xd_old_data
,
&
info
.
xd_new_data
,
&
xo
->
params
,
&
xo
->
config
,
&
xo
->
callback
);
&
xo
->
params
,
&
xo
->
config
,
&
xo
->
callback
);
git_diff_find_context_clear
(
&
findctxt
);
git_diff_find_context_clear
(
&
findctxt
);
...
...
tests/diff/patch.c
View file @
e479628a
...
@@ -275,6 +275,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
...
@@ -275,6 +275,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_s
(
"Ivory their outposts were--the guardrooms of them gilded,
\n
"
,
actual
.
ptr
);
cl_assert_equal_s
(
"Ivory their outposts were--the guardrooms of them gilded,
\n
"
,
actual
.
ptr
);
cl_assert_equal_i
(
6
,
line
->
old_lineno
);
cl_assert_equal_i
(
6
,
line
->
old_lineno
);
cl_assert_equal_i
(
6
,
line
->
new_lineno
);
cl_assert_equal_i
(
6
,
line
->
new_lineno
);
cl_assert_equal_i
(
-
1
,
line
->
content_offset
);
cl_git_pass
(
git_patch_get_line_in_hunk
(
&
line
,
patch
,
0
,
3
));
cl_git_pass
(
git_patch_get_line_in_hunk
(
&
line
,
patch
,
0
,
3
));
cl_assert_equal_i
(
GIT_DIFF_LINE_DELETION
,
(
int
)
line
->
origin
);
cl_assert_equal_i
(
GIT_DIFF_LINE_DELETION
,
(
int
)
line
->
origin
);
...
@@ -282,6 +283,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
...
@@ -282,6 +283,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_s
(
"All the world went softly when it walked before my Cities--
\n
"
,
actual
.
ptr
);
cl_assert_equal_s
(
"All the world went softly when it walked before my Cities--
\n
"
,
actual
.
ptr
);
cl_assert_equal_i
(
9
,
line
->
old_lineno
);
cl_assert_equal_i
(
9
,
line
->
old_lineno
);
cl_assert_equal_i
(
-
1
,
line
->
new_lineno
);
cl_assert_equal_i
(
-
1
,
line
->
new_lineno
);
cl_assert_equal_i
(
252
,
line
->
content_offset
);
cl_git_pass
(
git_patch_get_line_in_hunk
(
&
line
,
patch
,
0
,
12
));
cl_git_pass
(
git_patch_get_line_in_hunk
(
&
line
,
patch
,
0
,
12
));
cl_assert_equal_i
(
GIT_DIFF_LINE_ADDITION
,
(
int
)
line
->
origin
);
cl_assert_equal_i
(
GIT_DIFF_LINE_ADDITION
,
(
int
)
line
->
origin
);
...
@@ -289,6 +291,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
...
@@ -289,6 +291,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_s
(
"This is some new text;
\n
"
,
actual
.
ptr
);
cl_assert_equal_s
(
"This is some new text;
\n
"
,
actual
.
ptr
);
cl_assert_equal_i
(
-
1
,
line
->
old_lineno
);
cl_assert_equal_i
(
-
1
,
line
->
old_lineno
);
cl_assert_equal_i
(
9
,
line
->
new_lineno
);
cl_assert_equal_i
(
9
,
line
->
new_lineno
);
cl_assert_equal_i
(
252
,
line
->
content_offset
);
/* check hunk 1 */
/* check hunk 1 */
...
@@ -309,6 +312,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
...
@@ -309,6 +312,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_s
(
"My rulers and their treasure and their unborn populations,
\n
"
,
actual
.
ptr
);
cl_assert_equal_s
(
"My rulers and their treasure and their unborn populations,
\n
"
,
actual
.
ptr
);
cl_assert_equal_i
(
31
,
line
->
old_lineno
);
cl_assert_equal_i
(
31
,
line
->
old_lineno
);
cl_assert_equal_i
(
25
,
line
->
new_lineno
);
cl_assert_equal_i
(
25
,
line
->
new_lineno
);
cl_assert_equal_i
(
-
1
,
line
->
content_offset
);
cl_git_pass
(
git_patch_get_line_in_hunk
(
&
line
,
patch
,
1
,
3
));
cl_git_pass
(
git_patch_get_line_in_hunk
(
&
line
,
patch
,
1
,
3
));
cl_assert_equal_i
(
GIT_DIFF_LINE_DELETION
,
(
int
)
line
->
origin
);
cl_assert_equal_i
(
GIT_DIFF_LINE_DELETION
,
(
int
)
line
->
origin
);
...
@@ -316,6 +320,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
...
@@ -316,6 +320,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_s
(
"The Daughters of the Palace whom they cherished in my Cities,
\n
"
,
actual
.
ptr
);
cl_assert_equal_s
(
"The Daughters of the Palace whom they cherished in my Cities,
\n
"
,
actual
.
ptr
);
cl_assert_equal_i
(
34
,
line
->
old_lineno
);
cl_assert_equal_i
(
34
,
line
->
old_lineno
);
cl_assert_equal_i
(
-
1
,
line
->
new_lineno
);
cl_assert_equal_i
(
-
1
,
line
->
new_lineno
);
cl_assert_equal_i
(
1468
,
line
->
content_offset
);
cl_git_pass
(
git_patch_get_line_in_hunk
(
&
line
,
patch
,
1
,
12
));
cl_git_pass
(
git_patch_get_line_in_hunk
(
&
line
,
patch
,
1
,
12
));
cl_assert_equal_i
(
GIT_DIFF_LINE_ADDITION
,
(
int
)
line
->
origin
);
cl_assert_equal_i
(
GIT_DIFF_LINE_ADDITION
,
(
int
)
line
->
origin
);
...
@@ -323,6 +328,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
...
@@ -323,6 +328,7 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
cl_assert_equal_s
(
"Another replacement;
\n
"
,
actual
.
ptr
);
cl_assert_equal_s
(
"Another replacement;
\n
"
,
actual
.
ptr
);
cl_assert_equal_i
(
-
1
,
line
->
old_lineno
);
cl_assert_equal_i
(
-
1
,
line
->
old_lineno
);
cl_assert_equal_i
(
28
,
line
->
new_lineno
);
cl_assert_equal_i
(
28
,
line
->
new_lineno
);
cl_assert_equal_i
(
1066
,
line
->
content_offset
);
git_patch_free
(
patch
);
git_patch_free
(
patch
);
git_diff_free
(
diff
);
git_diff_free
(
diff
);
...
...
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