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
0dc8e95e
Commit
0dc8e95e
authored
Apr 30, 2012
by
Russell Belfer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #652 from nulltoken/topic/diff-callbacks
diff: provide more context to the consumer of the callbacks
parents
8b9ec201
2de0652b
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
136 additions
and
96 deletions
+136
-96
include/git2/diff.h
+17
-20
src/buffer.h
+6
-1
src/config_file.c
+1
-1
src/crlf.c
+2
-2
src/diff_output.c
+17
-18
src/filter.c
+5
-5
src/indexer.c
+2
-2
src/odb_loose.c
+8
-8
src/odb_pack.c
+1
-1
src/path.c
+7
-7
src/pkt.c
+1
-1
src/protocol.c
+3
-3
src/refs.c
+2
-2
src/refspec.c
+2
-2
src/repository.c
+3
-3
src/transports/http.c
+5
-5
src/tree.c
+1
-1
tests-clar/diff/diff_helpers.c
+15
-7
tests-clar/diff/diff_helpers.h
+1
-0
tests-clar/diff/patch.c
+37
-7
No files found.
include/git2/diff.h
View file @
0dc8e95e
...
@@ -154,19 +154,22 @@ typedef int (*git_diff_hunk_fn)(
...
@@ -154,19 +154,22 @@ typedef int (*git_diff_hunk_fn)(
* Line origin constants.
* Line origin constants.
*
*
* These values describe where a line came from and will be passed to
* These values describe where a line came from and will be passed to
* the git_diff_
line
_fn when iterating over a diff. There are some
* the git_diff_
data
_fn when iterating over a diff. There are some
* special origin contants at the end that are used for the text
* special origin contants at the end that are used for the text
* output callbacks to demarcate lines that are actually part of
* output callbacks to demarcate lines that are actually part of
* the file or hunk headers.
* the file or hunk headers.
*/
*/
enum
{
enum
{
/* these values will be sent to `git_diff_
line
_fn` along with the line */
/* these values will be sent to `git_diff_
data
_fn` along with the line */
GIT_DIFF_LINE_CONTEXT
=
' '
,
GIT_DIFF_LINE_CONTEXT
=
' '
,
GIT_DIFF_LINE_ADDITION
=
'+'
,
GIT_DIFF_LINE_ADDITION
=
'+'
,
GIT_DIFF_LINE_DELETION
=
'-'
,
GIT_DIFF_LINE_DELETION
=
'-'
,
GIT_DIFF_LINE_ADD_EOFNL
=
'\n'
,
/**< LF was added at end of file */
GIT_DIFF_LINE_ADD_EOFNL
=
'\n'
,
/**< LF was added at end of file */
GIT_DIFF_LINE_DEL_EOFNL
=
'\0'
,
/**< LF was removed at end of file */
GIT_DIFF_LINE_DEL_EOFNL
=
'\0'
,
/**< LF was removed at end of file */
/* these values will only be sent to a `git_diff_output_fn` */
/* these values will only be sent to a `git_diff_data_fn` when the content
* of a diff is being formatted (eg. through git_diff_print_patch() or
* git_diff_print_compact(), for instance).
*/
GIT_DIFF_LINE_FILE_HDR
=
'F'
,
GIT_DIFF_LINE_FILE_HDR
=
'F'
,
GIT_DIFF_LINE_HUNK_HDR
=
'H'
,
GIT_DIFF_LINE_HUNK_HDR
=
'H'
,
GIT_DIFF_LINE_BINARY
=
'B'
GIT_DIFF_LINE_BINARY
=
'B'
...
@@ -174,25 +177,19 @@ enum {
...
@@ -174,25 +177,19 @@ enum {
/**
/**
* When iterating over a diff, callback that will be made per text diff
* When iterating over a diff, callback that will be made per text diff
* line.
* line. In this context, the provided range will be NULL.
*/
*
typedef
int
(
*
git_diff_line_fn
)(
void
*
cb_data
,
git_diff_delta
*
delta
,
char
line_origin
,
/**< GIT_DIFF_LINE_... value from above */
const
char
*
content
,
size_t
content_len
);
/**
* When printing a diff, callback that will be made to output each line
* When printing a diff, callback that will be made to output each line
* of text. This uses some extra GIT_DIFF_LINE_... constants for output
* of text. This uses some extra GIT_DIFF_LINE_... constants for output
* of lines of file and hunk headers.
* of lines of file and hunk headers.
*/
*/
typedef
int
(
*
git_diff_
output
_fn
)(
typedef
int
(
*
git_diff_
data
_fn
)(
void
*
cb_data
,
void
*
cb_data
,
git_diff_delta
*
delta
,
git_diff_range
*
range
,
char
line_origin
,
/**< GIT_DIFF_LINE_... value from above */
char
line_origin
,
/**< GIT_DIFF_LINE_... value from above */
const
char
*
formatted_output
);
const
char
*
content
,
size_t
content_len
);
/** @name Diff List Generator Functions
/** @name Diff List Generator Functions
*
*
...
@@ -311,7 +308,7 @@ GIT_EXTERN(int) git_diff_foreach(
...
@@ -311,7 +308,7 @@ GIT_EXTERN(int) git_diff_foreach(
void
*
cb_data
,
void
*
cb_data
,
git_diff_file_fn
file_cb
,
git_diff_file_fn
file_cb
,
git_diff_hunk_fn
hunk_cb
,
git_diff_hunk_fn
hunk_cb
,
git_diff_
line
_fn
line_cb
);
git_diff_
data
_fn
line_cb
);
/**
/**
* Iterate over a diff generating text output like "git diff --name-status".
* Iterate over a diff generating text output like "git diff --name-status".
...
@@ -319,7 +316,7 @@ GIT_EXTERN(int) git_diff_foreach(
...
@@ -319,7 +316,7 @@ GIT_EXTERN(int) git_diff_foreach(
GIT_EXTERN
(
int
)
git_diff_print_compact
(
GIT_EXTERN
(
int
)
git_diff_print_compact
(
git_diff_list
*
diff
,
git_diff_list
*
diff
,
void
*
cb_data
,
void
*
cb_data
,
git_diff_
output
_fn
print_cb
);
git_diff_
data
_fn
print_cb
);
/**
/**
* Iterate over a diff generating text output like "git diff".
* Iterate over a diff generating text output like "git diff".
...
@@ -329,7 +326,7 @@ GIT_EXTERN(int) git_diff_print_compact(
...
@@ -329,7 +326,7 @@ GIT_EXTERN(int) git_diff_print_compact(
GIT_EXTERN
(
int
)
git_diff_print_patch
(
GIT_EXTERN
(
int
)
git_diff_print_patch
(
git_diff_list
*
diff
,
git_diff_list
*
diff
,
void
*
cb_data
,
void
*
cb_data
,
git_diff_
output
_fn
print_cb
);
git_diff_
data
_fn
print_cb
);
/**@}*/
/**@}*/
...
@@ -348,7 +345,7 @@ GIT_EXTERN(int) git_diff_blobs(
...
@@ -348,7 +345,7 @@ GIT_EXTERN(int) git_diff_blobs(
git_diff_options
*
options
,
git_diff_options
*
options
,
void
*
cb_data
,
void
*
cb_data
,
git_diff_hunk_fn
hunk_cb
,
git_diff_hunk_fn
hunk_cb
,
git_diff_
line
_fn
line_cb
);
git_diff_
data
_fn
line_cb
);
GIT_END_DECL
GIT_END_DECL
...
...
src/buffer.h
View file @
0dc8e95e
...
@@ -93,11 +93,16 @@ GIT_INLINE(int) git_buf_joinpath(git_buf *buf, const char *a, const char *b)
...
@@ -93,11 +93,16 @@ GIT_INLINE(int) git_buf_joinpath(git_buf *buf, const char *a, const char *b)
return
git_buf_join
(
buf
,
'/'
,
a
,
b
);
return
git_buf_join
(
buf
,
'/'
,
a
,
b
);
}
}
GIT_INLINE
(
const
char
*
)
git_buf_cstr
(
git_buf
*
buf
)
GIT_INLINE
(
const
char
*
)
git_buf_cstr
(
const
git_buf
*
buf
)
{
{
return
buf
->
ptr
;
return
buf
->
ptr
;
}
}
GIT_INLINE
(
size_t
)
git_buf_len
(
const
git_buf
*
buf
)
{
return
buf
->
size
;
}
void
git_buf_copy_cstr
(
char
*
data
,
size_t
datasize
,
const
git_buf
*
buf
);
void
git_buf_copy_cstr
(
char
*
data
,
size_t
datasize
,
const
git_buf
*
buf
);
#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)
#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1)
...
...
src/config_file.c
View file @
0dc8e95e
...
@@ -1233,7 +1233,7 @@ static int parse_multiline_variable(diskfile_backend *cfg, git_buf *value, int i
...
@@ -1233,7 +1233,7 @@ static int parse_multiline_variable(diskfile_backend *cfg, git_buf *value, int i
* standard, this character **has** to be last one in the buf, with
* standard, this character **has** to be last one in the buf, with
* no whitespace after it */
* no whitespace after it */
assert
(
is_multiline_var
(
value
->
ptr
));
assert
(
is_multiline_var
(
value
->
ptr
));
git_buf_truncate
(
value
,
value
->
size
-
1
);
git_buf_truncate
(
value
,
git_buf_len
(
value
)
-
1
);
proc_line
=
fixup_line
(
line
,
in_quotes
);
proc_line
=
fixup_line
(
line
,
in_quotes
);
if
(
proc_line
==
NULL
)
{
if
(
proc_line
==
NULL
)
{
...
...
src/crlf.c
View file @
0dc8e95e
...
@@ -105,7 +105,7 @@ static int crlf_load_attributes(struct crlf_attrs *ca, git_repository *repo, con
...
@@ -105,7 +105,7 @@ static int crlf_load_attributes(struct crlf_attrs *ca, git_repository *repo, con
static
int
drop_crlf
(
git_buf
*
dest
,
const
git_buf
*
source
)
static
int
drop_crlf
(
git_buf
*
dest
,
const
git_buf
*
source
)
{
{
const
char
*
scan
=
source
->
ptr
,
*
next
;
const
char
*
scan
=
source
->
ptr
,
*
next
;
const
char
*
scan_end
=
source
->
ptr
+
source
->
size
;
const
char
*
scan_end
=
git_buf_cstr
(
source
)
+
git_buf_len
(
source
)
;
/* Main scan loop. Find the next carriage return and copy the
/* Main scan loop. Find the next carriage return and copy the
* whole chunk up to that point to the destination buffer.
* whole chunk up to that point to the destination buffer.
...
@@ -138,7 +138,7 @@ static int crlf_apply_to_odb(git_filter *self, git_buf *dest, const git_buf *sou
...
@@ -138,7 +138,7 @@ static int crlf_apply_to_odb(git_filter *self, git_buf *dest, const git_buf *sou
assert
(
self
&&
dest
&&
source
);
assert
(
self
&&
dest
&&
source
);
/* Empty file? Nothing to do */
/* Empty file? Nothing to do */
if
(
source
->
size
==
0
)
if
(
git_buf_len
(
source
)
==
0
)
return
0
;
return
0
;
/* Heuristics to see if we can skip the conversion.
/* Heuristics to see if we can skip the conversion.
...
...
src/diff_output.c
View file @
0dc8e95e
...
@@ -18,9 +18,10 @@ typedef struct {
...
@@ -18,9 +18,10 @@ typedef struct {
git_diff_list
*
diff
;
git_diff_list
*
diff
;
void
*
cb_data
;
void
*
cb_data
;
git_diff_hunk_fn
hunk_cb
;
git_diff_hunk_fn
hunk_cb
;
git_diff_
line
_fn
line_cb
;
git_diff_
data
_fn
line_cb
;
unsigned
int
index
;
unsigned
int
index
;
git_diff_delta
*
delta
;
git_diff_delta
*
delta
;
git_diff_range
range
;
}
diff_output_info
;
}
diff_output_info
;
static
int
read_next_int
(
const
char
**
str
,
int
*
value
)
static
int
read_next_int
(
const
char
**
str
,
int
*
value
)
...
@@ -62,6 +63,8 @@ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len)
...
@@ -62,6 +63,8 @@ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len)
if
(
range
.
old_start
<
0
||
range
.
new_start
<
0
)
if
(
range
.
old_start
<
0
||
range
.
new_start
<
0
)
return
-
1
;
return
-
1
;
memcpy
(
&
info
->
range
,
&
range
,
sizeof
(
git_diff_range
));
return
info
->
hunk_cb
(
return
info
->
hunk_cb
(
info
->
cb_data
,
info
->
delta
,
&
range
,
bufs
[
0
].
ptr
,
bufs
[
0
].
size
);
info
->
cb_data
,
info
->
delta
,
&
range
,
bufs
[
0
].
ptr
,
bufs
[
0
].
size
);
}
}
...
@@ -76,7 +79,7 @@ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len)
...
@@ -76,7 +79,7 @@ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len)
GIT_DIFF_LINE_CONTEXT
;
GIT_DIFF_LINE_CONTEXT
;
if
(
info
->
line_cb
(
if
(
info
->
line_cb
(
info
->
cb_data
,
info
->
delta
,
origin
,
bufs
[
1
].
ptr
,
bufs
[
1
].
size
)
<
0
)
info
->
cb_data
,
info
->
delta
,
&
info
->
range
,
origin
,
bufs
[
1
].
ptr
,
bufs
[
1
].
size
)
<
0
)
return
-
1
;
return
-
1
;
/* deal with adding and removing newline at EOF */
/* deal with adding and removing newline at EOF */
...
@@ -87,7 +90,7 @@ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len)
...
@@ -87,7 +90,7 @@ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len)
origin
=
GIT_DIFF_LINE_DEL_EOFNL
;
origin
=
GIT_DIFF_LINE_DEL_EOFNL
;
return
info
->
line_cb
(
return
info
->
line_cb
(
info
->
cb_data
,
info
->
delta
,
origin
,
bufs
[
2
].
ptr
,
bufs
[
2
].
size
);
info
->
cb_data
,
info
->
delta
,
&
info
->
range
,
origin
,
bufs
[
2
].
ptr
,
bufs
[
2
].
size
);
}
}
}
}
...
@@ -291,7 +294,7 @@ int git_diff_foreach(
...
@@ -291,7 +294,7 @@ int git_diff_foreach(
void
*
data
,
void
*
data
,
git_diff_file_fn
file_cb
,
git_diff_file_fn
file_cb
,
git_diff_hunk_fn
hunk_cb
,
git_diff_hunk_fn
hunk_cb
,
git_diff_
line
_fn
line_cb
)
git_diff_
data
_fn
line_cb
)
{
{
int
error
=
0
;
int
error
=
0
;
diff_output_info
info
;
diff_output_info
info
;
...
@@ -433,7 +436,7 @@ cleanup:
...
@@ -433,7 +436,7 @@ cleanup:
typedef
struct
{
typedef
struct
{
git_diff_list
*
diff
;
git_diff_list
*
diff
;
git_diff_
output
_fn
print_cb
;
git_diff_
data
_fn
print_cb
;
void
*
cb_data
;
void
*
cb_data
;
git_buf
*
buf
;
git_buf
*
buf
;
}
diff_print_info
;
}
diff_print_info
;
...
@@ -491,13 +494,13 @@ static int print_compact(void *data, git_diff_delta *delta, float progress)
...
@@ -491,13 +494,13 @@ static int print_compact(void *data, git_diff_delta *delta, float progress)
if
(
git_buf_oom
(
pi
->
buf
))
if
(
git_buf_oom
(
pi
->
buf
))
return
-
1
;
return
-
1
;
return
pi
->
print_cb
(
pi
->
cb_data
,
GIT_DIFF_LINE_FILE_HDR
,
pi
->
buf
->
ptr
);
return
pi
->
print_cb
(
pi
->
cb_data
,
delta
,
NULL
,
GIT_DIFF_LINE_FILE_HDR
,
git_buf_cstr
(
pi
->
buf
),
git_buf_len
(
pi
->
buf
)
);
}
}
int
git_diff_print_compact
(
int
git_diff_print_compact
(
git_diff_list
*
diff
,
git_diff_list
*
diff
,
void
*
cb_data
,
void
*
cb_data
,
git_diff_
output
_fn
print_cb
)
git_diff_
data
_fn
print_cb
)
{
{
int
error
;
int
error
;
git_buf
buf
=
GIT_BUF_INIT
;
git_buf
buf
=
GIT_BUF_INIT
;
...
@@ -586,7 +589,7 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
...
@@ -586,7 +589,7 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
if
(
git_buf_oom
(
pi
->
buf
))
if
(
git_buf_oom
(
pi
->
buf
))
return
-
1
;
return
-
1
;
result
=
pi
->
print_cb
(
pi
->
cb_data
,
GIT_DIFF_LINE_FILE_HDR
,
pi
->
buf
->
ptr
);
result
=
pi
->
print_cb
(
pi
->
cb_data
,
delta
,
NULL
,
GIT_DIFF_LINE_FILE_HDR
,
git_buf_cstr
(
pi
->
buf
),
git_buf_len
(
pi
->
buf
)
);
if
(
result
<
0
)
if
(
result
<
0
)
return
result
;
return
result
;
...
@@ -600,7 +603,7 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
...
@@ -600,7 +603,7 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
if
(
git_buf_oom
(
pi
->
buf
))
if
(
git_buf_oom
(
pi
->
buf
))
return
-
1
;
return
-
1
;
return
pi
->
print_cb
(
pi
->
cb_data
,
GIT_DIFF_LINE_BINARY
,
pi
->
buf
->
ptr
);
return
pi
->
print_cb
(
pi
->
cb_data
,
delta
,
NULL
,
GIT_DIFF_LINE_BINARY
,
git_buf_cstr
(
pi
->
buf
),
git_buf_len
(
pi
->
buf
)
);
}
}
static
int
print_patch_hunk
(
static
int
print_patch_hunk
(
...
@@ -612,27 +615,23 @@ static int print_patch_hunk(
...
@@ -612,27 +615,23 @@ static int print_patch_hunk(
{
{
diff_print_info
*
pi
=
data
;
diff_print_info
*
pi
=
data
;
GIT_UNUSED
(
d
);
GIT_UNUSED
(
r
);
git_buf_clear
(
pi
->
buf
);
git_buf_clear
(
pi
->
buf
);
if
(
git_buf_printf
(
pi
->
buf
,
"%.*s"
,
(
int
)
header_len
,
header
)
<
0
)
if
(
git_buf_printf
(
pi
->
buf
,
"%.*s"
,
(
int
)
header_len
,
header
)
<
0
)
return
-
1
;
return
-
1
;
return
pi
->
print_cb
(
pi
->
cb_data
,
GIT_DIFF_LINE_HUNK_HDR
,
pi
->
buf
->
ptr
);
return
pi
->
print_cb
(
pi
->
cb_data
,
d
,
r
,
GIT_DIFF_LINE_HUNK_HDR
,
git_buf_cstr
(
pi
->
buf
),
git_buf_len
(
pi
->
buf
)
);
}
}
static
int
print_patch_line
(
static
int
print_patch_line
(
void
*
data
,
void
*
data
,
git_diff_delta
*
delta
,
git_diff_delta
*
delta
,
git_diff_range
*
range
,
char
line_origin
,
/* GIT_DIFF_LINE value from above */
char
line_origin
,
/* GIT_DIFF_LINE value from above */
const
char
*
content
,
const
char
*
content
,
size_t
content_len
)
size_t
content_len
)
{
{
diff_print_info
*
pi
=
data
;
diff_print_info
*
pi
=
data
;
GIT_UNUSED
(
delta
);
git_buf_clear
(
pi
->
buf
);
git_buf_clear
(
pi
->
buf
);
if
(
line_origin
==
GIT_DIFF_LINE_ADDITION
||
if
(
line_origin
==
GIT_DIFF_LINE_ADDITION
||
...
@@ -645,13 +644,13 @@ static int print_patch_line(
...
@@ -645,13 +644,13 @@ static int print_patch_line(
if
(
git_buf_oom
(
pi
->
buf
))
if
(
git_buf_oom
(
pi
->
buf
))
return
-
1
;
return
-
1
;
return
pi
->
print_cb
(
pi
->
cb_data
,
line_origin
,
pi
->
buf
->
ptr
);
return
pi
->
print_cb
(
pi
->
cb_data
,
delta
,
range
,
line_origin
,
git_buf_cstr
(
pi
->
buf
),
git_buf_len
(
pi
->
buf
)
);
}
}
int
git_diff_print_patch
(
int
git_diff_print_patch
(
git_diff_list
*
diff
,
git_diff_list
*
diff
,
void
*
cb_data
,
void
*
cb_data
,
git_diff_
output
_fn
print_cb
)
git_diff_
data
_fn
print_cb
)
{
{
int
error
;
int
error
;
git_buf
buf
=
GIT_BUF_INIT
;
git_buf
buf
=
GIT_BUF_INIT
;
...
@@ -678,7 +677,7 @@ int git_diff_blobs(
...
@@ -678,7 +677,7 @@ int git_diff_blobs(
git_diff_options
*
options
,
git_diff_options
*
options
,
void
*
cb_data
,
void
*
cb_data
,
git_diff_hunk_fn
hunk_cb
,
git_diff_hunk_fn
hunk_cb
,
git_diff_
line
_fn
line_cb
)
git_diff_
data
_fn
line_cb
)
{
{
diff_output_info
info
;
diff_output_info
info
;
git_diff_delta
delta
;
git_diff_delta
delta
;
...
...
src/filter.c
View file @
0dc8e95e
...
@@ -19,13 +19,13 @@ void git_text_gather_stats(git_text_stats *stats, const git_buf *text)
...
@@ -19,13 +19,13 @@ void git_text_gather_stats(git_text_stats *stats, const git_buf *text)
memset
(
stats
,
0
,
sizeof
(
*
stats
));
memset
(
stats
,
0
,
sizeof
(
*
stats
));
for
(
i
=
0
;
i
<
text
->
size
;
i
++
)
{
for
(
i
=
0
;
i
<
git_buf_len
(
text
)
;
i
++
)
{
unsigned
char
c
=
text
->
ptr
[
i
];
unsigned
char
c
=
text
->
ptr
[
i
];
if
(
c
==
'\r'
)
{
if
(
c
==
'\r'
)
{
stats
->
cr
++
;
stats
->
cr
++
;
if
(
i
+
1
<
text
->
size
&&
text
->
ptr
[
i
+
1
]
==
'\n'
)
if
(
i
+
1
<
git_buf_len
(
text
)
&&
text
->
ptr
[
i
+
1
]
==
'\n'
)
stats
->
crlf
++
;
stats
->
crlf
++
;
}
}
...
@@ -59,7 +59,7 @@ void git_text_gather_stats(git_text_stats *stats, const git_buf *text)
...
@@ -59,7 +59,7 @@ void git_text_gather_stats(git_text_stats *stats, const git_buf *text)
}
}
/* If file ends with EOF then don't count this EOF as non-printable. */
/* If file ends with EOF then don't count this EOF as non-printable. */
if
(
text
->
size
>=
1
&&
text
->
ptr
[
text
->
size
-
1
]
==
'\032'
)
if
(
git_buf_len
(
text
)
>=
1
&&
text
->
ptr
[
text
->
size
-
1
]
==
'\032'
)
stats
->
nonprintable
--
;
stats
->
nonprintable
--
;
}
}
...
@@ -127,14 +127,14 @@ int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
...
@@ -127,14 +127,14 @@ int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
src
=
0
;
src
=
0
;
if
(
source
->
size
==
0
)
{
if
(
git_buf_len
(
source
)
==
0
)
{
git_buf_clear
(
dest
);
git_buf_clear
(
dest
);
return
GIT_SUCCESS
;
return
GIT_SUCCESS
;
}
}
/* Pre-grow the destination buffer to more or less the size
/* Pre-grow the destination buffer to more or less the size
* we expect it to have */
* we expect it to have */
if
(
git_buf_grow
(
dest
,
source
->
size
)
<
0
)
if
(
git_buf_grow
(
dest
,
git_buf_len
(
source
)
)
<
0
)
return
GIT_ENOMEM
;
return
GIT_ENOMEM
;
for
(
i
=
0
;
i
<
filters
->
length
;
++
i
)
{
for
(
i
=
0
;
i
<
filters
->
length
;
++
i
)
{
...
...
src/indexer.c
View file @
0dc8e95e
...
@@ -401,7 +401,7 @@ static int index_path_stream(git_buf *path, git_indexer_stream *idx, const char
...
@@ -401,7 +401,7 @@ static int index_path_stream(git_buf *path, git_indexer_stream *idx, const char
git_buf_truncate
(
path
,
slash
);
git_buf_truncate
(
path
,
slash
);
git_buf_puts
(
path
,
prefix
);
git_buf_puts
(
path
,
prefix
);
git_oid_fmt
(
path
->
ptr
+
path
->
size
,
&
idx
->
hash
);
git_oid_fmt
(
path
->
ptr
+
git_buf_len
(
path
)
,
&
idx
->
hash
);
path
->
size
+=
GIT_OID_HEXSZ
;
path
->
size
+=
GIT_OID_HEXSZ
;
git_buf_puts
(
path
,
suffix
);
git_buf_puts
(
path
,
suffix
);
...
@@ -633,7 +633,7 @@ static int index_path(git_buf *path, git_indexer *idx)
...
@@ -633,7 +633,7 @@ static int index_path(git_buf *path, git_indexer *idx)
git_buf_truncate
(
path
,
slash
);
git_buf_truncate
(
path
,
slash
);
git_buf_puts
(
path
,
prefix
);
git_buf_puts
(
path
,
prefix
);
git_oid_fmt
(
path
->
ptr
+
path
->
size
,
&
idx
->
hash
);
git_oid_fmt
(
path
->
ptr
+
git_buf_len
(
path
)
,
&
idx
->
hash
);
path
->
size
+=
GIT_OID_HEXSZ
;
path
->
size
+=
GIT_OID_HEXSZ
;
git_buf_puts
(
path
,
suffix
);
git_buf_puts
(
path
,
suffix
);
...
...
src/odb_loose.c
View file @
0dc8e95e
...
@@ -61,13 +61,13 @@ static int object_file_name(git_buf *name, const char *dir, const git_oid *id)
...
@@ -61,13 +61,13 @@ static int object_file_name(git_buf *name, const char *dir, const git_oid *id)
git_buf_sets
(
name
,
dir
);
git_buf_sets
(
name
,
dir
);
/* expand length for 40 hex sha1 chars + 2 * '/' + '\0' */
/* expand length for 40 hex sha1 chars + 2 * '/' + '\0' */
if
(
git_buf_grow
(
name
,
name
->
size
+
GIT_OID_HEXSZ
+
3
)
<
0
)
if
(
git_buf_grow
(
name
,
git_buf_len
(
name
)
+
GIT_OID_HEXSZ
+
3
)
<
0
)
return
-
1
;
return
-
1
;
git_path_to_dir
(
name
);
git_path_to_dir
(
name
);
/* loose object filename: aa/aaa... (41 bytes) */
/* loose object filename: aa/aaa... (41 bytes) */
git_oid_pathfmt
(
name
->
ptr
+
name
->
size
,
id
);
git_oid_pathfmt
(
name
->
ptr
+
git_buf_len
(
name
)
,
id
);
name
->
size
+=
GIT_OID_HEXSZ
+
1
;
name
->
size
+=
GIT_OID_HEXSZ
+
1
;
name
->
ptr
[
name
->
size
]
=
'\0'
;
name
->
ptr
[
name
->
size
]
=
'\0'
;
...
@@ -81,7 +81,7 @@ static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
...
@@ -81,7 +81,7 @@ static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
unsigned
char
*
data
=
(
unsigned
char
*
)
obj
->
ptr
;
unsigned
char
*
data
=
(
unsigned
char
*
)
obj
->
ptr
;
size_t
shift
,
size
,
used
=
0
;
size_t
shift
,
size
,
used
=
0
;
if
(
obj
->
size
==
0
)
if
(
git_buf_len
(
obj
)
==
0
)
return
0
;
return
0
;
c
=
data
[
used
++
];
c
=
data
[
used
++
];
...
@@ -90,7 +90,7 @@ static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
...
@@ -90,7 +90,7 @@ static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
size
=
c
&
15
;
size
=
c
&
15
;
shift
=
4
;
shift
=
4
;
while
(
c
&
0x80
)
{
while
(
c
&
0x80
)
{
if
(
obj
->
size
<=
used
)
if
(
git_buf_len
(
obj
)
<=
used
)
return
0
;
return
0
;
if
(
sizeof
(
size_t
)
*
8
<=
shift
)
if
(
sizeof
(
size_t
)
*
8
<=
shift
)
return
0
;
return
0
;
...
@@ -182,7 +182,7 @@ static int start_inflate(z_stream *s, git_buf *obj, void *out, size_t len)
...
@@ -182,7 +182,7 @@ static int start_inflate(z_stream *s, git_buf *obj, void *out, size_t len)
int
status
;
int
status
;
init_stream
(
s
,
out
,
len
);
init_stream
(
s
,
out
,
len
);
set_stream_input
(
s
,
obj
->
ptr
,
obj
->
size
);
set_stream_input
(
s
,
obj
->
ptr
,
git_buf_len
(
obj
)
);
if
((
status
=
inflateInit
(
s
))
<
Z_OK
)
if
((
status
=
inflateInit
(
s
))
<
Z_OK
)
return
status
;
return
status
;
...
@@ -469,7 +469,7 @@ static int locate_object(
...
@@ -469,7 +469,7 @@ static int locate_object(
static
int
fn_locate_object_short_oid
(
void
*
state
,
git_buf
*
pathbuf
)
{
static
int
fn_locate_object_short_oid
(
void
*
state
,
git_buf
*
pathbuf
)
{
loose_locate_object_state
*
sstate
=
(
loose_locate_object_state
*
)
state
;
loose_locate_object_state
*
sstate
=
(
loose_locate_object_state
*
)
state
;
if
(
pathbuf
->
size
-
sstate
->
dir_len
!=
GIT_OID_HEXSZ
-
2
)
{
if
(
git_buf_len
(
pathbuf
)
-
sstate
->
dir_len
!=
GIT_OID_HEXSZ
-
2
)
{
/* Entry cannot be an object. Continue to next entry */
/* Entry cannot be an object. Continue to next entry */
return
0
;
return
0
;
}
}
...
@@ -517,7 +517,7 @@ static int locate_object_short_oid(
...
@@ -517,7 +517,7 @@ static int locate_object_short_oid(
git_path_to_dir
(
object_location
);
git_path_to_dir
(
object_location
);
/* save adjusted position at end of dir so it can be restored later */
/* save adjusted position at end of dir so it can be restored later */
dir_len
=
object_location
->
size
;
dir_len
=
git_buf_len
(
object_location
)
;
/* Convert raw oid to hex formatted oid */
/* Convert raw oid to hex formatted oid */
git_oid_fmt
((
char
*
)
state
.
short_oid
,
short_oid
);
git_oid_fmt
((
char
*
)
state
.
short_oid
,
short_oid
);
...
@@ -530,7 +530,7 @@ static int locate_object_short_oid(
...
@@ -530,7 +530,7 @@ static int locate_object_short_oid(
if
(
git_path_isdir
(
object_location
->
ptr
)
==
false
)
if
(
git_path_isdir
(
object_location
->
ptr
)
==
false
)
return
git_odb__error_notfound
(
"failed to locate from short oid"
);
return
git_odb__error_notfound
(
"failed to locate from short oid"
);
state
.
dir_len
=
object_location
->
size
;
state
.
dir_len
=
git_buf_len
(
object_location
)
;
state
.
short_oid_len
=
len
;
state
.
short_oid_len
=
len
;
state
.
found
=
0
;
state
.
found
=
0
;
...
...
src/odb_pack.c
View file @
0dc8e95e
...
@@ -219,7 +219,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
...
@@ -219,7 +219,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
for
(
i
=
0
;
i
<
backend
->
packs
.
length
;
++
i
)
{
for
(
i
=
0
;
i
<
backend
->
packs
.
length
;
++
i
)
{
struct
git_pack_file
*
p
=
git_vector_get
(
&
backend
->
packs
,
i
);
struct
git_pack_file
*
p
=
git_vector_get
(
&
backend
->
packs
,
i
);
if
(
memcmp
(
p
->
pack_name
,
path
->
ptr
,
path
->
size
-
strlen
(
".idx"
))
==
0
)
if
(
memcmp
(
p
->
pack_name
,
git_buf_cstr
(
path
),
git_buf_len
(
path
)
-
strlen
(
".idx"
))
==
0
)
return
0
;
return
0
;
}
}
...
...
src/path.c
View file @
0dc8e95e
...
@@ -221,8 +221,8 @@ int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base)
...
@@ -221,8 +221,8 @@ int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base)
int
git_path_to_dir
(
git_buf
*
path
)
int
git_path_to_dir
(
git_buf
*
path
)
{
{
if
(
path
->
asize
>
0
&&
if
(
path
->
asize
>
0
&&
path
->
size
>
0
&&
git_buf_len
(
path
)
>
0
&&
path
->
ptr
[
path
->
size
-
1
]
!=
'/'
)
path
->
ptr
[
git_buf_len
(
path
)
-
1
]
!=
'/'
)
git_buf_putc
(
path
,
'/'
);
git_buf_putc
(
path
,
'/'
);
return
git_buf_oom
(
path
)
?
-
1
:
0
;
return
git_buf_oom
(
path
)
?
-
1
:
0
;
...
@@ -327,12 +327,12 @@ int git_path_walk_up(
...
@@ -327,12 +327,12 @@ int git_path_walk_up(
if
(
git__prefixcmp
(
path
->
ptr
,
ceiling
)
==
0
)
if
(
git__prefixcmp
(
path
->
ptr
,
ceiling
)
==
0
)
stop
=
(
ssize_t
)
strlen
(
ceiling
);
stop
=
(
ssize_t
)
strlen
(
ceiling
);
else
else
stop
=
path
->
size
;
stop
=
git_buf_len
(
path
)
;
}
}
scan
=
path
->
size
;
scan
=
git_buf_len
(
path
)
;
iter
.
ptr
=
path
->
ptr
;
iter
.
ptr
=
path
->
ptr
;
iter
.
size
=
path
->
size
;
iter
.
size
=
git_buf_len
(
path
)
;
iter
.
asize
=
path
->
asize
;
iter
.
asize
=
path
->
asize
;
while
(
scan
>=
stop
)
{
while
(
scan
>=
stop
)
{
...
@@ -407,7 +407,7 @@ static bool _check_dir_contents(
...
@@ -407,7 +407,7 @@ static bool _check_dir_contents(
bool
(
*
predicate
)(
const
char
*
))
bool
(
*
predicate
)(
const
char
*
))
{
{
bool
result
;
bool
result
;
size_t
dir_size
=
dir
->
size
;
size_t
dir_size
=
git_buf_len
(
dir
)
;
size_t
sub_size
=
strlen
(
sub
);
size_t
sub_size
=
strlen
(
sub
);
/* leave base valid even if we could not make space for subdir */
/* leave base valid even if we could not make space for subdir */
...
@@ -503,7 +503,7 @@ int git_path_direach(
...
@@ -503,7 +503,7 @@ int git_path_direach(
if
(
git_path_to_dir
(
path
)
<
0
)
if
(
git_path_to_dir
(
path
)
<
0
)
return
-
1
;
return
-
1
;
wd_len
=
path
->
size
;
wd_len
=
git_buf_len
(
path
)
;
if
((
dir
=
opendir
(
path
->
ptr
))
==
NULL
)
{
if
((
dir
=
opendir
(
path
->
ptr
))
==
NULL
)
{
giterr_set
(
GITERR_OS
,
"Failed to open directory '%s'"
,
path
->
ptr
);
giterr_set
(
GITERR_OS
,
"Failed to open directory '%s'"
,
path
->
ptr
);
...
...
src/pkt.c
View file @
0dc8e95e
...
@@ -277,7 +277,7 @@ static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps
...
@@ -277,7 +277,7 @@ static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps
len
=
(
unsigned
int
)
len
=
(
unsigned
int
)
(
strlen
(
"XXXXwant "
)
+
GIT_OID_HEXSZ
+
1
/* NUL */
+
(
strlen
(
"XXXXwant "
)
+
GIT_OID_HEXSZ
+
1
/* NUL */
+
strlen
(
capstr
)
+
1
/* LF */
);
strlen
(
capstr
)
+
1
/* LF */
);
git_buf_grow
(
buf
,
buf
->
size
+
len
);
git_buf_grow
(
buf
,
git_buf_len
(
buf
)
+
len
);
git_oid_fmt
(
oid
,
&
head
->
oid
);
git_oid_fmt
(
oid
,
&
head
->
oid
);
return
git_buf_printf
(
buf
,
"%04xwant %s%c%s
\n
"
,
len
,
oid
,
0
,
capstr
);
return
git_buf_printf
(
buf
,
"%04xwant %s%c%s
\n
"
,
len
,
oid
,
0
,
capstr
);
...
...
src/protocol.c
View file @
0dc8e95e
...
@@ -17,7 +17,7 @@ int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
...
@@ -17,7 +17,7 @@ int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
const
char
*
line_end
,
*
ptr
;
const
char
*
line_end
,
*
ptr
;
if
(
len
==
0
)
{
/* EOF */
if
(
len
==
0
)
{
/* EOF */
if
(
buf
->
size
!=
0
)
{
if
(
git_buf_len
(
buf
)
!=
0
)
{
giterr_set
(
GITERR_NET
,
"Unexpected EOF"
);
giterr_set
(
GITERR_NET
,
"Unexpected EOF"
);
return
p
->
error
=
-
1
;
return
p
->
error
=
-
1
;
}
else
{
}
else
{
...
@@ -30,10 +30,10 @@ int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
...
@@ -30,10 +30,10 @@ int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
while
(
1
)
{
while
(
1
)
{
git_pkt
*
pkt
;
git_pkt
*
pkt
;
if
(
buf
->
size
==
0
)
if
(
git_buf_len
(
buf
)
==
0
)
return
0
;
return
0
;
error
=
git_pkt_parse_line
(
&
pkt
,
ptr
,
&
line_end
,
buf
->
size
);
error
=
git_pkt_parse_line
(
&
pkt
,
ptr
,
&
line_end
,
git_buf_len
(
buf
)
);
if
(
error
==
GIT_ESHORTBUFFER
)
if
(
error
==
GIT_ESHORTBUFFER
)
return
0
;
/* Ask for more */
return
0
;
/* Ask for more */
if
(
error
<
0
)
if
(
error
<
0
)
...
...
src/refs.c
View file @
0dc8e95e
...
@@ -139,7 +139,7 @@ static int loose_parse_symbolic(git_reference *ref, git_buf *file_content)
...
@@ -139,7 +139,7 @@ static int loose_parse_symbolic(git_reference *ref, git_buf *file_content)
refname_start
=
(
const
char
*
)
file_content
->
ptr
;
refname_start
=
(
const
char
*
)
file_content
->
ptr
;
if
(
file_content
->
size
<
header_len
+
1
)
if
(
git_buf_len
(
file_content
)
<
header_len
+
1
)
goto
corrupt
;
goto
corrupt
;
/*
/*
...
@@ -174,7 +174,7 @@ static int loose_parse_oid(git_oid *oid, git_buf *file_content)
...
@@ -174,7 +174,7 @@ static int loose_parse_oid(git_oid *oid, git_buf *file_content)
buffer
=
(
char
*
)
file_content
->
ptr
;
buffer
=
(
char
*
)
file_content
->
ptr
;
/* File format: 40 chars (OID) + newline */
/* File format: 40 chars (OID) + newline */
if
(
file_content
->
size
<
GIT_OID_HEXSZ
+
1
)
if
(
git_buf_len
(
file_content
)
<
GIT_OID_HEXSZ
+
1
)
goto
corrupt
;
goto
corrupt
;
if
(
git_oid_fromstr
(
oid
,
buffer
)
<
0
)
if
(
git_oid_fromstr
(
oid
,
buffer
)
<
0
)
...
...
src/refspec.c
View file @
0dc8e95e
...
@@ -103,10 +103,10 @@ int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *n
...
@@ -103,10 +103,10 @@ int git_refspec_transform_r(git_buf *out, const git_refspec *spec, const char *n
* No '*' at the end means that it's mapped to one specific local
* No '*' at the end means that it's mapped to one specific local
* branch, so no actual transformation is needed.
* branch, so no actual transformation is needed.
*/
*/
if
(
out
->
size
>
0
&&
out
->
ptr
[
out
->
size
-
1
]
!=
'*'
)
if
(
git_buf_len
(
out
)
>
0
&&
out
->
ptr
[
git_buf_len
(
out
)
-
1
]
!=
'*'
)
return
GIT_SUCCESS
;
return
GIT_SUCCESS
;
git_buf_truncate
(
out
,
out
->
size
-
1
);
/* remove trailing '*' */
git_buf_truncate
(
out
,
git_buf_len
(
out
)
-
1
);
/* remove trailing '*' */
git_buf_puts
(
out
,
name
+
strlen
(
spec
->
src
)
-
1
);
git_buf_puts
(
out
,
name
+
strlen
(
spec
->
src
)
-
1
);
if
(
git_buf_oom
(
out
))
if
(
git_buf_oom
(
out
))
...
...
src/repository.c
View file @
0dc8e95e
...
@@ -278,7 +278,7 @@ static int find_repo(
...
@@ -278,7 +278,7 @@ static int find_repo(
if
((
error
=
git_buf_joinpath
(
&
path
,
path
.
ptr
,
DOT_GIT
))
<
0
)
if
((
error
=
git_buf_joinpath
(
&
path
,
path
.
ptr
,
DOT_GIT
))
<
0
)
return
error
;
return
error
;
while
(
!
error
&&
!
repo_path
->
size
)
{
while
(
!
error
&&
!
git_buf_len
(
repo_path
)
)
{
if
(
p_stat
(
path
.
ptr
,
&
st
)
==
0
)
{
if
(
p_stat
(
path
.
ptr
,
&
st
)
==
0
)
{
/* check that we have not crossed device boundaries */
/* check that we have not crossed device boundaries */
if
(
initial_device
==
0
)
if
(
initial_device
==
0
)
...
@@ -328,7 +328,7 @@ static int find_repo(
...
@@ -328,7 +328,7 @@ static int find_repo(
}
}
if
(
!
error
&&
parent_path
!=
NULL
)
{
if
(
!
error
&&
parent_path
!=
NULL
)
{
if
(
!
repo_path
->
size
)
if
(
!
git_buf_len
(
repo_path
)
)
git_buf_clear
(
parent_path
);
git_buf_clear
(
parent_path
);
else
{
else
{
git_path_dirname_r
(
parent_path
,
path
.
ptr
);
git_path_dirname_r
(
parent_path
,
path
.
ptr
);
...
@@ -340,7 +340,7 @@ static int find_repo(
...
@@ -340,7 +340,7 @@ static int find_repo(
git_buf_free
(
&
path
);
git_buf_free
(
&
path
);
if
(
!
repo_path
->
size
&&
!
error
)
{
if
(
!
git_buf_len
(
repo_path
)
&&
!
error
)
{
giterr_set
(
GITERR_REPOSITORY
,
giterr_set
(
GITERR_REPOSITORY
,
"Could not find repository from '%s'"
,
start_path
);
"Could not find repository from '%s'"
,
start_path
);
error
=
GIT_ENOTFOUND
;
error
=
GIT_ENOTFOUND
;
...
...
src/transports/http.c
View file @
0dc8e95e
...
@@ -321,7 +321,7 @@ static int on_body_parse_response(http_parser *parser, const char *str, size_t l
...
@@ -321,7 +321,7 @@ static int on_body_parse_response(http_parser *parser, const char *str, size_t l
const
char
*
line_end
,
*
ptr
;
const
char
*
line_end
,
*
ptr
;
if
(
len
==
0
)
{
/* EOF */
if
(
len
==
0
)
{
/* EOF */
if
(
buf
->
size
!=
0
)
{
if
(
git_buf_len
(
buf
)
!=
0
)
{
giterr_set
(
GITERR_NET
,
"Unexpected EOF"
);
giterr_set
(
GITERR_NET
,
"Unexpected EOF"
);
return
t
->
error
=
-
1
;
return
t
->
error
=
-
1
;
}
else
{
}
else
{
...
@@ -334,10 +334,10 @@ static int on_body_parse_response(http_parser *parser, const char *str, size_t l
...
@@ -334,10 +334,10 @@ static int on_body_parse_response(http_parser *parser, const char *str, size_t l
while
(
1
)
{
while
(
1
)
{
git_pkt
*
pkt
;
git_pkt
*
pkt
;
if
(
buf
->
size
==
0
)
if
(
git_buf_len
(
buf
)
==
0
)
return
0
;
return
0
;
error
=
git_pkt_parse_line
(
&
pkt
,
ptr
,
&
line_end
,
buf
->
size
);
error
=
git_pkt_parse_line
(
&
pkt
,
ptr
,
&
line_end
,
git_buf_len
(
buf
)
);
if
(
error
==
GIT_ESHORTBUFFER
)
{
if
(
error
==
GIT_ESHORTBUFFER
)
{
return
0
;
/* Ask for more */
return
0
;
/* Ask for more */
}
}
...
@@ -555,9 +555,9 @@ static int http_download_pack(git_transport *transport, git_repository *repo, gi
...
@@ -555,9 +555,9 @@ static int http_download_pack(git_transport *transport, git_repository *repo, gi
memset
(
&
settings
,
0x0
,
sizeof
(
settings
));
memset
(
&
settings
,
0x0
,
sizeof
(
settings
));
settings
.
on_message_complete
=
on_message_complete_download_pack
;
settings
.
on_message_complete
=
on_message_complete_download_pack
;
settings
.
on_body
=
on_body_download_pack
;
settings
.
on_body
=
on_body_download_pack
;
*
bytes
=
oldbuf
->
size
;
*
bytes
=
git_buf_len
(
oldbuf
)
;
if
(
git_indexer_stream_add
(
idx
,
oldbuf
->
ptr
,
oldbuf
->
size
,
stats
)
<
0
)
if
(
git_indexer_stream_add
(
idx
,
git_buf_cstr
(
oldbuf
),
git_buf_len
(
oldbuf
)
,
stats
)
<
0
)
goto
on_error
;
goto
on_error
;
do
{
do
{
...
...
src/tree.c
View file @
0dc8e95e
...
@@ -711,7 +711,7 @@ static int tree_walk_post(
...
@@ -711,7 +711,7 @@ static int tree_walk_post(
if
(
entry_is_tree
(
entry
))
{
if
(
entry_is_tree
(
entry
))
{
git_tree
*
subtree
;
git_tree
*
subtree
;
size_t
path_len
=
path
->
size
;
size_t
path_len
=
git_buf_len
(
path
)
;
if
((
error
=
git_tree_lookup
(
if
((
error
=
git_tree_lookup
(
&
subtree
,
tree
->
object
.
repo
,
&
entry
->
oid
))
<
0
)
&
subtree
,
tree
->
object
.
repo
,
&
entry
->
oid
))
<
0
)
...
...
tests-clar/diff/diff_helpers.c
View file @
0dc8e95e
...
@@ -27,7 +27,9 @@ int diff_file_fn(
...
@@ -27,7 +27,9 @@ int diff_file_fn(
float
progress
)
float
progress
)
{
{
diff_expects
*
e
=
cb_data
;
diff_expects
*
e
=
cb_data
;
(
void
)
progress
;
GIT_UNUSED
(
progress
);
e
->
files
++
;
e
->
files
++
;
switch
(
delta
->
status
)
{
switch
(
delta
->
status
)
{
case
GIT_DELTA_ADDED
:
e
->
file_adds
++
;
break
;
case
GIT_DELTA_ADDED
:
e
->
file_adds
++
;
break
;
...
@@ -48,9 +50,11 @@ int diff_hunk_fn(
...
@@ -48,9 +50,11 @@ int diff_hunk_fn(
size_t
header_len
)
size_t
header_len
)
{
{
diff_expects
*
e
=
cb_data
;
diff_expects
*
e
=
cb_data
;
(
void
)
delta
;
(
void
)
header
;
GIT_UNUSED
(
delta
);
(
void
)
header_len
;
GIT_UNUSED
(
header
);
GIT_UNUSED
(
header_len
);
e
->
hunks
++
;
e
->
hunks
++
;
e
->
hunk_old_lines
+=
range
->
old_lines
;
e
->
hunk_old_lines
+=
range
->
old_lines
;
e
->
hunk_new_lines
+=
range
->
new_lines
;
e
->
hunk_new_lines
+=
range
->
new_lines
;
...
@@ -60,14 +64,18 @@ int diff_hunk_fn(
...
@@ -60,14 +64,18 @@ int diff_hunk_fn(
int
diff_line_fn
(
int
diff_line_fn
(
void
*
cb_data
,
void
*
cb_data
,
git_diff_delta
*
delta
,
git_diff_delta
*
delta
,
git_diff_range
*
range
,
char
line_origin
,
char
line_origin
,
const
char
*
content
,
const
char
*
content
,
size_t
content_len
)
size_t
content_len
)
{
{
diff_expects
*
e
=
cb_data
;
diff_expects
*
e
=
cb_data
;
(
void
)
delta
;
(
void
)
content
;
GIT_UNUSED
(
delta
);
(
void
)
content_len
;
GIT_UNUSED
(
range
);
GIT_UNUSED
(
content
);
GIT_UNUSED
(
content_len
);
e
->
lines
++
;
e
->
lines
++
;
switch
(
line_origin
)
{
switch
(
line_origin
)
{
case
GIT_DIFF_LINE_CONTEXT
:
case
GIT_DIFF_LINE_CONTEXT
:
...
...
tests-clar/diff/diff_helpers.h
View file @
0dc8e95e
...
@@ -37,6 +37,7 @@ extern int diff_hunk_fn(
...
@@ -37,6 +37,7 @@ extern int diff_hunk_fn(
extern
int
diff_line_fn
(
extern
int
diff_line_fn
(
void
*
cb_data
,
void
*
cb_data
,
git_diff_delta
*
delta
,
git_diff_delta
*
delta
,
git_diff_range
*
range
,
char
line_origin
,
char
line_origin
,
const
char
*
content
,
const
char
*
content
,
size_t
content_len
);
size_t
content_len
);
...
...
tests-clar/diff/patch.c
View file @
0dc8e95e
...
@@ -13,26 +13,56 @@ void test_diff_patch__cleanup(void)
...
@@ -13,26 +13,56 @@ void test_diff_patch__cleanup(void)
cl_git_sandbox_cleanup
();
cl_git_sandbox_cleanup
();
}
}
#define EXPECTED_
OUTPUT
"diff --git a/subdir.txt b/subdir.txt\n" \
#define EXPECTED_
HEADER
"diff --git a/subdir.txt b/subdir.txt\n" \
"deleted file mode 100644\n" \
"deleted file mode 100644\n" \
"index e8ee89e..0000000\n" \
"index e8ee89e..0000000\n" \
"--- a/subdir.txt\n" \
"--- a/subdir.txt\n" \
"+++ /dev/null\n"
"+++ /dev/null\n"
#define EXPECTED_HUNK "@@ -1,2 +0,0 @@\n"
static
int
check_removal_cb
(
static
int
check_removal_cb
(
void
*
cb_data
,
void
*
cb_data
,
git_diff_delta
*
delta
,
git_diff_range
*
range
,
char
line_origin
,
char
line_origin
,
const
char
*
formatted_output
)
const
char
*
formatted_output
,
size_t
output_len
)
{
{
GIT_UNUSED
(
cb_data
);
GIT_UNUSED
(
cb_data
);
if
(
line_origin
!=
'F'
)
switch
(
line_origin
)
{
return
0
;
case
GIT_DIFF_LINE_FILE_HDR
:
cl_assert_equal_s
(
EXPECTED_HEADER
,
formatted_output
);
cl_assert
(
range
==
NULL
);
goto
check_delta
;
case
GIT_DIFF_LINE_HUNK_HDR
:
cl_assert_equal_s
(
EXPECTED_HUNK
,
formatted_output
);
/* Fall through */
case
GIT_DIFF_LINE_CONTEXT
:
case
GIT_DIFF_LINE_DELETION
:
goto
check_range
;
default:
/* unexpected code path */
return
-
1
;
}
check_range:
cl_assert
(
range
!=
NULL
);
cl_assert_equal_i
(
1
,
range
->
old_start
);
cl_assert_equal_i
(
2
,
range
->
old_lines
);
cl_assert_equal_i
(
0
,
range
->
new_start
);
cl_assert_equal_i
(
0
,
range
->
new_lines
);
if
(
strcmp
(
EXPECTED_OUTPUT
,
formatted_output
)
==
0
)
check_delta:
return
0
;
cl_assert_equal_s
(
"subdir.txt"
,
delta
->
old
.
path
);
cl_assert_equal_s
(
"subdir.txt"
,
delta
->
new
.
path
);
cl_assert_equal_i
(
GIT_DELTA_DELETED
,
delta
->
status
);
return
-
1
;
return
0
;
}
}
void
test_diff_patch__can_properly_display_the_removal_of_a_file
(
void
)
void
test_diff_patch__can_properly_display_the_removal_of_a_file
(
void
)
...
...
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