diff options
| author | nulltoken <emeric.fermas@gmail.com> | 2012-04-25 22:23:35 +0200 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2012-04-25 15:37:17 -0700 |
| commit | eb3d71a5bcd78cb4840e62194e8998141508af88 (patch) | |
| tree | 6121c4a4dae045c693f47a3ca8fbe5355221b2a6 /src | |
| parent | 3fc5c65d1a072fc727226cd66a1b096df4919da5 (diff) | |
| download | libgit2-eb3d71a5bcd78cb4840e62194e8998141508af88.tar.gz | |
diff: fix generation of the header of a removal patch
Diffstat (limited to 'src')
| -rw-r--r-- | src/diff.c | 3 | ||||
| -rw-r--r-- | src/diff.h | 3 | ||||
| -rw-r--r-- | src/diff_output.c | 20 |
3 files changed, 18 insertions, 8 deletions
diff --git a/src/diff.c b/src/diff.c index 7d2ad59aa..b239031a2 100644 --- a/src/diff.c +++ b/src/diff.c @@ -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); diff --git a/src/diff.h b/src/diff.h index 4de18beea..6c432c894 100644 --- a/src/diff.h +++ b/src/diff.h @@ -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? */ diff --git a/src/diff_output.c b/src/diff_output.c index f4c214314..7c5b6f276 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -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)) { - oldpfx = ""; - oldpath = "/dev/null"; + newpfx = ""; + newpath = "/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( |
