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
eb3d71a5
Commit
eb3d71a5
authored
Apr 25, 2012
by
nulltoken
Committed by
Russell Belfer
Apr 25, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
diff: fix generation of the header of a removal patch
parent
3fc5c65d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
8 deletions
+86
-8
src/diff.c
+0
-3
src/diff.h
+3
-0
src/diff_output.c
+15
-5
tests-clar/diff/patch.c
+68
-0
No files found.
src/diff.c
View file @
eb3d71a5
...
...
@@ -232,9 +232,6 @@ static int diff_delta__from_two(
return
0
;
}
#define DIFF_SRC_PREFIX_DEFAULT "a/"
#define DIFF_DST_PREFIX_DEFAULT "b/"
static
char
*
diff_strdup_prefix
(
git_pool
*
pool
,
const
char
*
prefix
)
{
size_t
len
=
strlen
(
prefix
);
...
...
src/diff.h
View file @
eb3d71a5
...
...
@@ -14,6 +14,9 @@
#include "repository.h"
#include "pool.h"
#define DIFF_SRC_PREFIX_DEFAULT "a/"
#define DIFF_DST_PREFIX_DEFAULT "b/"
enum
{
GIT_DIFFCAPS_HAS_SYMLINKS
=
(
1
<<
0
),
/* symlinks on platform? */
GIT_DIFFCAPS_ASSUME_UNCHANGED
=
(
1
<<
1
),
/* use stat? */
...
...
src/diff_output.c
View file @
eb3d71a5
...
...
@@ -553,9 +553,16 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
const
char
*
oldpath
=
delta
->
old
.
path
;
const
char
*
newpfx
=
pi
->
diff
->
opts
.
dst_prefix
;
const
char
*
newpath
=
delta
->
new
.
path
;
int
result
;
GIT_UNUSED
(
progress
);
if
(
!
oldpfx
)
oldpfx
=
DIFF_SRC_PREFIX_DEFAULT
;
if
(
!
newpfx
)
newpfx
=
DIFF_DST_PREFIX_DEFAULT
;
git_buf_clear
(
pi
->
buf
);
git_buf_printf
(
pi
->
buf
,
"diff --git %s%s %s%s
\n
"
,
oldpfx
,
delta
->
old
.
path
,
newpfx
,
delta
->
new
.
path
);
...
...
@@ -567,8 +574,8 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
oldpath
=
"/dev/null"
;
}
if
(
git_oid_iszero
(
&
delta
->
new
.
oid
))
{
old
pfx
=
""
;
old
path
=
"/dev/null"
;
new
pfx
=
""
;
new
path
=
"/dev/null"
;
}
if
(
delta
->
binary
!=
1
)
{
...
...
@@ -579,9 +586,12 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
if
(
git_buf_oom
(
pi
->
buf
))
return
-
1
;
if
(
pi
->
print_cb
(
pi
->
cb_data
,
GIT_DIFF_LINE_FILE_HDR
,
pi
->
buf
->
ptr
)
<
0
||
delta
->
binary
!=
1
)
return
-
1
;
result
=
pi
->
print_cb
(
pi
->
cb_data
,
GIT_DIFF_LINE_FILE_HDR
,
pi
->
buf
->
ptr
);
if
(
result
<
0
)
return
result
;
if
(
delta
->
binary
!=
1
)
return
0
;
git_buf_clear
(
pi
->
buf
);
git_buf_printf
(
...
...
tests-clar/diff/patch.c
0 → 100644
View file @
eb3d71a5
#include "clar_libgit2.h"
#include "diff_helpers.h"
static
git_repository
*
g_repo
=
NULL
;
void
test_diff_patch__initialize
(
void
)
{
g_repo
=
cl_git_sandbox_init
(
"status"
);
}
void
test_diff_patch__cleanup
(
void
)
{
cl_git_sandbox_cleanup
();
}
#define EXPECTED_OUTPUT "diff --git a/subdir.txt b/subdir.txt\n" \
"deleted file mode 100644\n" \
"index e8ee89e..0000000\n" \
"--- a/subdir.txt\n" \
"+++ /dev/null\n"
static
int
check_removal_cb
(
void
*
cb_data
,
char
line_origin
,
const
char
*
formatted_output
)
{
GIT_UNUSED
(
cb_data
);
if
(
line_origin
!=
'F'
)
return
0
;
if
(
strcmp
(
EXPECTED_OUTPUT
,
formatted_output
)
==
0
)
return
0
;
return
-
1
;
}
void
test_diff_patch__can_properly_display_the_removal_of_a_file
(
void
)
{
/*
* $ git diff 26a125e..735b6a2
* diff --git a/subdir.txt b/subdir.txt
* deleted file mode 100644
* index e8ee89e..0000000
* --- a/subdir.txt
* +++ /dev/null
* @@ -1,2 +0,0 @@
* -Is it a bird?
* -Is it a plane?
*/
const
char
*
one_sha
=
"26a125e"
;
const
char
*
another_sha
=
"735b6a2"
;
git_tree
*
one
,
*
another
;
git_diff_list
*
diff
;
one
=
resolve_commit_oid_to_tree
(
g_repo
,
one_sha
);
another
=
resolve_commit_oid_to_tree
(
g_repo
,
another_sha
);
cl_git_pass
(
git_diff_tree_to_tree
(
g_repo
,
NULL
,
one
,
another
,
&
diff
));
cl_git_pass
(
git_diff_print_patch
(
diff
,
NULL
,
check_removal_cb
));
git_diff_list_free
(
diff
);
git_tree_free
(
another
);
git_tree_free
(
one
);
}
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