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
aadfa85b
Commit
aadfa85b
authored
May 17, 2013
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add git_diff_print_raw printing helper
Makes it easier to emulate the --raw option
parent
660d59ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
6 deletions
+78
-6
include/git2/diff.h
+16
-0
src/diff_output.c
+62
-6
No files found.
include/git2/diff.h
View file @
aadfa85b
...
...
@@ -689,6 +689,22 @@ GIT_EXTERN(int) git_diff_print_compact(
void
*
payload
);
/**
* Iterate over a diff generating text output like "git diff --raw".
*
* Returning a non-zero value from the callbacks will terminate the
* iteration and cause this return `GIT_EUSER`.
*
* @param diff A git_diff_list generated by one of the above functions.
* @param print_cb Callback to make per line of diff text.
* @param payload Reference pointer that will be passed to your callback.
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
GIT_EXTERN
(
int
)
git_diff_print_raw
(
git_diff_list
*
diff
,
git_diff_data_cb
print_cb
,
void
*
payload
);
/**
* Look up the single character abbreviation for a delta status code.
*
* When you call `git_diff_print_compact` it prints single letter codes into
...
...
src/diff_output.c
View file @
aadfa85b
...
...
@@ -1104,12 +1104,7 @@ int git_diff_print_compact(
{
int
error
;
git_buf
buf
=
GIT_BUF_INIT
;
diff_print_info
pi
;
pi
.
diff
=
diff
;
pi
.
print_cb
=
print_cb
;
pi
.
payload
=
payload
;
pi
.
buf
=
&
buf
;
diff_print_info
pi
=
{
diff
,
print_cb
,
payload
,
&
buf
};
error
=
git_diff_foreach
(
diff
,
print_compact
,
NULL
,
NULL
,
&
pi
);
...
...
@@ -1118,6 +1113,67 @@ int git_diff_print_compact(
return
error
;
}
static
int
print_raw
(
const
git_diff_delta
*
delta
,
float
progress
,
void
*
data
)
{
diff_print_info
*
pi
=
data
;
char
code
=
git_diff_status_char
(
delta
->
status
);
char
ooid
[
8
],
noid
[
8
];
GIT_UNUSED
(
progress
);
if
(
code
==
' '
)
return
0
;
git_buf_clear
(
pi
->
buf
);
git_oid_nfmt
(
ooid
,
sizeof
(
ooid
),
&
delta
->
old_file
.
oid
);
ooid
[
7
]
=
'\0'
;
git_oid_nfmt
(
noid
,
sizeof
(
noid
),
&
delta
->
new_file
.
oid
);
noid
[
7
]
=
'\0'
;
git_buf_printf
(
pi
->
buf
,
":%06o %06o %s... %s... %c"
,
delta
->
old_file
.
mode
,
delta
->
new_file
.
mode
,
ooid
,
noid
,
code
);
if
(
delta
->
similarity
>
0
)
git_buf_printf
(
pi
->
buf
,
"%03u"
,
delta
->
similarity
);
if
(
delta
->
status
==
GIT_DELTA_RENAMED
||
delta
->
status
==
GIT_DELTA_COPIED
)
git_buf_printf
(
pi
->
buf
,
"
\t
%s %s
\n
"
,
delta
->
old_file
.
path
,
delta
->
new_file
.
path
);
else
git_buf_printf
(
pi
->
buf
,
"
\t
%s
\n
"
,
delta
->
old_file
.
path
?
delta
->
old_file
.
path
:
delta
->
new_file
.
path
);
if
(
git_buf_oom
(
pi
->
buf
))
return
-
1
;
if
(
pi
->
print_cb
(
delta
,
NULL
,
GIT_DIFF_LINE_FILE_HDR
,
git_buf_cstr
(
pi
->
buf
),
git_buf_len
(
pi
->
buf
),
pi
->
payload
))
return
callback_error
();
return
0
;
}
int
git_diff_print_raw
(
git_diff_list
*
diff
,
git_diff_data_cb
print_cb
,
void
*
payload
)
{
int
error
;
git_buf
buf
=
GIT_BUF_INIT
;
diff_print_info
pi
=
{
diff
,
print_cb
,
payload
,
&
buf
};
error
=
git_diff_foreach
(
diff
,
print_raw
,
NULL
,
NULL
,
&
pi
);
git_buf_free
(
&
buf
);
return
error
;
}
static
int
print_oid_range
(
diff_print_info
*
pi
,
const
git_diff_delta
*
delta
)
{
int
abbrevlen
;
...
...
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