Commit a1683f28 by Russell Belfer

More tests and bug fixes for status with rename

This changes the behavior of the status RENAMED flags so that they
will be combined with the MODIFIED flags if appropriate.  If a file
is modified in the index and also renamed, then the status code
will have both the GIT_STATUS_INDEX_MODIFIED and INDEX_RENAMED bits
set.  If it is renamed but the OID has not changed, then just the
GIT_STATUS_INDEX_RENAMED bit will be set.  Similarly, the flags
GIT_STATUS_WT_MODIFIED and GIT_STATUS_WT_RENAMED can both be set
independently of one another.

This fixes a serious bug where the check for unmodified files that
was done at data load time could end up erasing the RENAMED state
of a file that was renamed with no changes.

Lastly, this contains a bunch of new tests for status with renames,
including tests where the only rename changes are case changes.
The expected results of these tests have to vary by whether the
platform uses a case sensitive filesystem or not, so the expected
data covers those platform differences separately.
parent fb03a223
...@@ -95,17 +95,16 @@ extern int git_diff__paired_foreach( ...@@ -95,17 +95,16 @@ extern int git_diff__paired_foreach(
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload), int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
void *payload); void *payload);
int git_diff_find_similar__hashsig_for_file( extern int git_diff_find_similar__hashsig_for_file(
void **out, const git_diff_file *f, const char *path, void *p); void **out, const git_diff_file *f, const char *path, void *p);
int git_diff_find_similar__hashsig_for_buf( extern int git_diff_find_similar__hashsig_for_buf(
void **out, const git_diff_file *f, const char *buf, size_t len, void *p); void **out, const git_diff_file *f, const char *buf, size_t len, void *p);
void git_diff_find_similar__hashsig_free(void *sig, void *payload); extern void git_diff_find_similar__hashsig_free(void *sig, void *payload);
int git_diff_find_similar__calc_similarity( extern int git_diff_find_similar__calc_similarity(
int *score, void *siga, void *sigb, void *payload); int *score, void *siga, void *sigb, void *payload);
#endif #endif
...@@ -175,10 +175,11 @@ static int diff_patch_load(git_diff_patch *patch, git_diff_output *output) ...@@ -175,10 +175,11 @@ static int diff_patch_load(git_diff_patch *patch, git_diff_output *output)
goto cleanup; goto cleanup;
} }
/* if we were previously missing an oid, reassess UNMODIFIED state */ /* if we were previously missing an oid, update MODIFIED->UNMODIFIED */
if (incomplete_data && if (incomplete_data &&
patch->ofile.file.mode == patch->nfile.file.mode && patch->ofile.file.mode == patch->nfile.file.mode &&
git_oid_equal(&patch->ofile.file.oid, &patch->nfile.file.oid)) git_oid_equal(&patch->ofile.file.oid, &patch->nfile.file.oid) &&
patch->delta->status == GIT_DELTA_MODIFIED) /* not RENAMED/COPIED! */
patch->delta->status = GIT_DELTA_UNMODIFIED; patch->delta->status = GIT_DELTA_UNMODIFIED;
cleanup: cleanup:
...@@ -284,6 +285,7 @@ int git_diff_foreach( ...@@ -284,6 +285,7 @@ int git_diff_foreach(
git_xdiff_init(&xo, &diff->opts); git_xdiff_init(&xo, &diff->opts);
git_vector_foreach(&diff->deltas, idx, patch.delta) { git_vector_foreach(&diff->deltas, idx, patch.delta) {
/* check flags against patch status */ /* check flags against patch status */
if (git_diff_delta__should_skip(&diff->opts, patch.delta)) if (git_diff_delta__should_skip(&diff->opts, patch.delta))
continue; continue;
......
...@@ -41,7 +41,7 @@ static int diff_print_info_init( ...@@ -41,7 +41,7 @@ static int diff_print_info_init(
return 0; return 0;
} }
static char pick_suffix(int mode) static char diff_pick_suffix(int mode)
{ {
if (S_ISDIR(mode)) if (S_ISDIR(mode))
return '/'; return '/';
...@@ -76,10 +76,11 @@ static int callback_error(void) ...@@ -76,10 +76,11 @@ static int callback_error(void)
return GIT_EUSER; return GIT_EUSER;
} }
static int print_compact( static int diff_print_one_compact(
const git_diff_delta *delta, float progress, void *data) const git_diff_delta *delta, float progress, void *data)
{ {
diff_print_info *pi = data; diff_print_info *pi = data;
git_buf *out = pi->buf;
char old_suffix, new_suffix, code = git_diff_status_char(delta->status); char old_suffix, new_suffix, code = git_diff_status_char(delta->status);
GIT_UNUSED(progress); GIT_UNUSED(progress);
...@@ -87,34 +88,35 @@ static int print_compact( ...@@ -87,34 +88,35 @@ static int print_compact(
if (code == ' ') if (code == ' ')
return 0; return 0;
old_suffix = pick_suffix(delta->old_file.mode); old_suffix = diff_pick_suffix(delta->old_file.mode);
new_suffix = pick_suffix(delta->new_file.mode); new_suffix = diff_pick_suffix(delta->new_file.mode);
git_buf_clear(pi->buf); git_buf_clear(out);
if (delta->old_file.path != delta->new_file.path && if (delta->old_file.path != delta->new_file.path &&
pi->diff->strcomp(delta->old_file.path,delta->new_file.path) != 0) pi->diff->strcomp(delta->old_file.path,delta->new_file.path) != 0)
git_buf_printf(pi->buf, "%c\t%s%c -> %s%c\n", code, git_buf_printf(out, "%c\t%s%c -> %s%c\n", code,
delta->old_file.path, old_suffix, delta->new_file.path, new_suffix); delta->old_file.path, old_suffix, delta->new_file.path, new_suffix);
else if (delta->old_file.mode != delta->new_file.mode && else if (delta->old_file.mode != delta->new_file.mode &&
delta->old_file.mode != 0 && delta->new_file.mode != 0) delta->old_file.mode != 0 && delta->new_file.mode != 0)
git_buf_printf(pi->buf, "%c\t%s%c (%o -> %o)\n", code, git_buf_printf(out, "%c\t%s%c (%o -> %o)\n", code,
delta->old_file.path, new_suffix, delta->old_file.mode, delta->new_file.mode); delta->old_file.path, new_suffix, delta->old_file.mode, delta->new_file.mode);
else if (old_suffix != ' ') else if (old_suffix != ' ')
git_buf_printf(pi->buf, "%c\t%s%c\n", code, delta->old_file.path, old_suffix); git_buf_printf(out, "%c\t%s%c\n", code, delta->old_file.path, old_suffix);
else else
git_buf_printf(pi->buf, "%c\t%s\n", code, delta->old_file.path); git_buf_printf(out, "%c\t%s\n", code, delta->old_file.path);
if (git_buf_oom(pi->buf)) if (git_buf_oom(out))
return -1; return -1;
if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR, if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload)) git_buf_cstr(out), git_buf_len(out), pi->payload))
return callback_error(); return callback_error();
return 0; return 0;
} }
/* print a git_diff_list to a print callback in compact format */
int git_diff_print_compact( int git_diff_print_compact(
git_diff_list *diff, git_diff_list *diff,
git_diff_data_cb print_cb, git_diff_data_cb print_cb,
...@@ -125,17 +127,18 @@ int git_diff_print_compact( ...@@ -125,17 +127,18 @@ int git_diff_print_compact(
diff_print_info pi; diff_print_info pi;
if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload))) if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload)))
error = git_diff_foreach(diff, print_compact, NULL, NULL, &pi); error = git_diff_foreach(diff, diff_print_one_compact, NULL, NULL, &pi);
git_buf_free(&buf); git_buf_free(&buf);
return error; return error;
} }
static int print_raw( static int diff_print_one_raw(
const git_diff_delta *delta, float progress, void *data) const git_diff_delta *delta, float progress, void *data)
{ {
diff_print_info *pi = data; diff_print_info *pi = data;
git_buf *out = pi->buf;
char code = git_diff_status_char(delta->status); char code = git_diff_status_char(delta->status);
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1]; char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
...@@ -144,36 +147,37 @@ static int print_raw( ...@@ -144,36 +147,37 @@ static int print_raw(
if (code == ' ') if (code == ' ')
return 0; return 0;
git_buf_clear(pi->buf); git_buf_clear(out);
git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.oid); git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.oid);
git_oid_tostr(end_oid, pi->oid_strlen, &delta->new_file.oid); git_oid_tostr(end_oid, pi->oid_strlen, &delta->new_file.oid);
git_buf_printf( git_buf_printf(
pi->buf, ":%06o %06o %s... %s... %c", out, ":%06o %06o %s... %s... %c",
delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code); delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code);
if (delta->similarity > 0) if (delta->similarity > 0)
git_buf_printf(pi->buf, "%03u", delta->similarity); git_buf_printf(out, "%03u", delta->similarity);
if (delta->status == GIT_DELTA_RENAMED || delta->status == GIT_DELTA_COPIED) if (delta->status == GIT_DELTA_RENAMED || delta->status == GIT_DELTA_COPIED)
git_buf_printf( git_buf_printf(
pi->buf, "\t%s %s\n", delta->old_file.path, delta->new_file.path); out, "\t%s %s\n", delta->old_file.path, delta->new_file.path);
else else
git_buf_printf( git_buf_printf(
pi->buf, "\t%s\n", delta->old_file.path ? out, "\t%s\n", delta->old_file.path ?
delta->old_file.path : delta->new_file.path); delta->old_file.path : delta->new_file.path);
if (git_buf_oom(pi->buf)) if (git_buf_oom(out))
return -1; return -1;
if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR, if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
git_buf_cstr(pi->buf), git_buf_len(pi->buf), pi->payload)) git_buf_cstr(out), git_buf_len(out), pi->payload))
return callback_error(); return callback_error();
return 0; return 0;
} }
/* print a git_diff_list to a print callback in raw output format */
int git_diff_print_raw( int git_diff_print_raw(
git_diff_list *diff, git_diff_list *diff,
git_diff_data_cb print_cb, git_diff_data_cb print_cb,
...@@ -184,15 +188,16 @@ int git_diff_print_raw( ...@@ -184,15 +188,16 @@ int git_diff_print_raw(
diff_print_info pi; diff_print_info pi;
if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload))) if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload)))
error = git_diff_foreach(diff, print_raw, NULL, NULL, &pi); error = git_diff_foreach(diff, diff_print_one_raw, NULL, NULL, &pi);
git_buf_free(&buf); git_buf_free(&buf);
return error; return error;
} }
static int print_oid_range(diff_print_info *pi, const git_diff_delta *delta) static int diff_print_oid_range(diff_print_info *pi, const git_diff_delta *delta)
{ {
git_buf *out = pi->buf;
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1]; char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.oid); git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.oid);
...@@ -200,27 +205,27 @@ static int print_oid_range(diff_print_info *pi, const git_diff_delta *delta) ...@@ -200,27 +205,27 @@ static int print_oid_range(diff_print_info *pi, const git_diff_delta *delta)
/* TODO: Match git diff more closely */ /* TODO: Match git diff more closely */
if (delta->old_file.mode == delta->new_file.mode) { if (delta->old_file.mode == delta->new_file.mode) {
git_buf_printf(pi->buf, "index %s..%s %o\n", git_buf_printf(out, "index %s..%s %o\n",
start_oid, end_oid, delta->old_file.mode); start_oid, end_oid, delta->old_file.mode);
} else { } else {
if (delta->old_file.mode == 0) { if (delta->old_file.mode == 0) {
git_buf_printf(pi->buf, "new file mode %o\n", delta->new_file.mode); git_buf_printf(out, "new file mode %o\n", delta->new_file.mode);
} else if (delta->new_file.mode == 0) { } else if (delta->new_file.mode == 0) {
git_buf_printf(pi->buf, "deleted file mode %o\n", delta->old_file.mode); git_buf_printf(out, "deleted file mode %o\n", delta->old_file.mode);
} else { } else {
git_buf_printf(pi->buf, "old mode %o\n", delta->old_file.mode); git_buf_printf(out, "old mode %o\n", delta->old_file.mode);
git_buf_printf(pi->buf, "new mode %o\n", delta->new_file.mode); git_buf_printf(out, "new mode %o\n", delta->new_file.mode);
} }
git_buf_printf(pi->buf, "index %s..%s\n", start_oid, end_oid); git_buf_printf(out, "index %s..%s\n", start_oid, end_oid);
} }
if (git_buf_oom(pi->buf)) if (git_buf_oom(out))
return -1; return -1;
return 0; return 0;
} }
static int print_patch_file( static int diff_print_patch_file(
const git_diff_delta *delta, float progress, void *data) const git_diff_delta *delta, float progress, void *data)
{ {
diff_print_info *pi = data; diff_print_info *pi = data;
...@@ -247,7 +252,7 @@ static int print_patch_file( ...@@ -247,7 +252,7 @@ static int print_patch_file(
git_buf_clear(pi->buf); git_buf_clear(pi->buf);
git_buf_printf(pi->buf, "diff --git %s%s %s%s\n", oldpfx, delta->old_file.path, newpfx, delta->new_file.path); git_buf_printf(pi->buf, "diff --git %s%s %s%s\n", oldpfx, delta->old_file.path, newpfx, delta->new_file.path);
if (print_oid_range(pi, delta) < 0) if (diff_print_oid_range(pi, delta) < 0)
return -1; return -1;
if (git_oid_iszero(&delta->old_file.oid)) { if (git_oid_iszero(&delta->old_file.oid)) {
...@@ -288,7 +293,7 @@ static int print_patch_file( ...@@ -288,7 +293,7 @@ static int print_patch_file(
return 0; return 0;
} }
static int print_patch_hunk( static int diff_print_patch_hunk(
const git_diff_delta *d, const git_diff_delta *d,
const git_diff_range *r, const git_diff_range *r,
const char *header, const char *header,
...@@ -311,7 +316,7 @@ static int print_patch_hunk( ...@@ -311,7 +316,7 @@ static int print_patch_hunk(
return 0; return 0;
} }
static int print_patch_line( static int diff_print_patch_line(
const git_diff_delta *delta, const git_diff_delta *delta,
const git_diff_range *range, const git_diff_range *range,
char line_origin, /* GIT_DIFF_LINE value from above */ char line_origin, /* GIT_DIFF_LINE value from above */
...@@ -343,6 +348,7 @@ static int print_patch_line( ...@@ -343,6 +348,7 @@ static int print_patch_line(
return 0; return 0;
} }
/* print a git_diff_list to an output callback in patch format */
int git_diff_print_patch( int git_diff_print_patch(
git_diff_list *diff, git_diff_list *diff,
git_diff_data_cb print_cb, git_diff_data_cb print_cb,
...@@ -354,27 +360,15 @@ int git_diff_print_patch( ...@@ -354,27 +360,15 @@ int git_diff_print_patch(
if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload))) if (!(error = diff_print_info_init(&pi, &buf, diff, print_cb, payload)))
error = git_diff_foreach( error = git_diff_foreach(
diff, print_patch_file, print_patch_hunk, print_patch_line, &pi); diff, diff_print_patch_file, diff_print_patch_hunk,
diff_print_patch_line, &pi);
git_buf_free(&buf); git_buf_free(&buf);
return error; return error;
} }
/* print a git_diff_patch to an output callback */
static int print_to_buffer_cb(
const git_diff_delta *delta,
const git_diff_range *range,
char line_origin,
const char *content,
size_t content_len,
void *payload)
{
git_buf *output = payload;
GIT_UNUSED(delta); GIT_UNUSED(range); GIT_UNUSED(line_origin);
return git_buf_put(output, content, content_len);
}
int git_diff_patch_print( int git_diff_patch_print(
git_diff_patch *patch, git_diff_patch *patch,
git_diff_data_cb print_cb, git_diff_data_cb print_cb,
...@@ -389,13 +383,28 @@ int git_diff_patch_print( ...@@ -389,13 +383,28 @@ int git_diff_patch_print(
if (!(error = diff_print_info_init( if (!(error = diff_print_info_init(
&pi, &temp, git_diff_patch__diff(patch), print_cb, payload))) &pi, &temp, git_diff_patch__diff(patch), print_cb, payload)))
error = git_diff_patch__invoke_callbacks( error = git_diff_patch__invoke_callbacks(
patch, print_patch_file, print_patch_hunk, print_patch_line, &pi); patch, diff_print_patch_file, diff_print_patch_hunk,
diff_print_patch_line, &pi);
git_buf_free(&temp); git_buf_free(&temp);
return error; return error;
} }
static int diff_print_to_buffer_cb(
const git_diff_delta *delta,
const git_diff_range *range,
char line_origin,
const char *content,
size_t content_len,
void *payload)
{
git_buf *output = payload;
GIT_UNUSED(delta); GIT_UNUSED(range); GIT_UNUSED(line_origin);
return git_buf_put(output, content, content_len);
}
/* print a git_diff_patch to a string buffer */
int git_diff_patch_to_str( int git_diff_patch_to_str(
char **string, char **string,
git_diff_patch *patch) git_diff_patch *patch)
...@@ -403,7 +412,7 @@ int git_diff_patch_to_str( ...@@ -403,7 +412,7 @@ int git_diff_patch_to_str(
int error; int error;
git_buf output = GIT_BUF_INIT; git_buf output = GIT_BUF_INIT;
error = git_diff_patch_print(patch, print_to_buffer_cb, &output); error = git_diff_patch_print(patch, diff_print_to_buffer_cb, &output);
/* GIT_EUSER means git_buf_put in print_to_buffer_cb returned -1, /* GIT_EUSER means git_buf_put in print_to_buffer_cb returned -1,
* meaning a memory allocation failure, so just map to -1... * meaning a memory allocation failure, so just map to -1...
......
...@@ -483,7 +483,7 @@ static int similarity_measure( ...@@ -483,7 +483,7 @@ static int similarity_measure(
if (GIT_MODE_TYPE(a_file->mode) != GIT_MODE_TYPE(b_file->mode)) if (GIT_MODE_TYPE(a_file->mode) != GIT_MODE_TYPE(b_file->mode))
return 0; return 0;
/* if exact match is requested, force calculation of missing OIDs */ /* if exact match is requested, force calculation of missing OIDs now */
if (exact_match) { if (exact_match) {
if (git_oid_iszero(&a_file->oid) && if (git_oid_iszero(&a_file->oid) &&
diff->old_src == GIT_ITERATOR_TYPE_WORKDIR && diff->old_src == GIT_ITERATOR_TYPE_WORKDIR &&
......
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
#include "git2/diff.h" #include "git2/diff.h"
#include "diff.h" #include "diff.h"
static unsigned int index_delta2status(git_delta_t index_status) static unsigned int index_delta2status(const git_diff_delta *head2idx)
{ {
unsigned int st = GIT_STATUS_CURRENT; git_status_t st = GIT_STATUS_CURRENT;
switch (index_status) { switch (head2idx->status) {
case GIT_DELTA_ADDED: case GIT_DELTA_ADDED:
case GIT_DELTA_COPIED: case GIT_DELTA_COPIED:
st = GIT_STATUS_INDEX_NEW; st = GIT_STATUS_INDEX_NEW;
...@@ -37,6 +37,9 @@ static unsigned int index_delta2status(git_delta_t index_status) ...@@ -37,6 +37,9 @@ static unsigned int index_delta2status(git_delta_t index_status)
break; break;
case GIT_DELTA_RENAMED: case GIT_DELTA_RENAMED:
st = GIT_STATUS_INDEX_RENAMED; st = GIT_STATUS_INDEX_RENAMED;
if (!git_oid_equal(&head2idx->old_file.oid, &head2idx->new_file.oid))
st |= GIT_STATUS_INDEX_MODIFIED;
break; break;
case GIT_DELTA_TYPECHANGE: case GIT_DELTA_TYPECHANGE:
st = GIT_STATUS_INDEX_TYPECHANGE; st = GIT_STATUS_INDEX_TYPECHANGE;
...@@ -48,11 +51,12 @@ static unsigned int index_delta2status(git_delta_t index_status) ...@@ -48,11 +51,12 @@ static unsigned int index_delta2status(git_delta_t index_status)
return st; return st;
} }
static unsigned int workdir_delta2status(git_delta_t workdir_status) static unsigned int workdir_delta2status(
git_diff_list *diff, git_diff_delta *idx2wd)
{ {
unsigned int st = GIT_STATUS_CURRENT; git_status_t st = GIT_STATUS_CURRENT;
switch (workdir_status) { switch (idx2wd->status) {
case GIT_DELTA_ADDED: case GIT_DELTA_ADDED:
case GIT_DELTA_COPIED: case GIT_DELTA_COPIED:
case GIT_DELTA_UNTRACKED: case GIT_DELTA_UNTRACKED:
...@@ -69,6 +73,28 @@ static unsigned int workdir_delta2status(git_delta_t workdir_status) ...@@ -69,6 +73,28 @@ static unsigned int workdir_delta2status(git_delta_t workdir_status)
break; break;
case GIT_DELTA_RENAMED: case GIT_DELTA_RENAMED:
st = GIT_STATUS_WT_RENAMED; st = GIT_STATUS_WT_RENAMED;
if (!git_oid_equal(&idx2wd->old_file.oid, &idx2wd->new_file.oid)) {
/* if OIDs don't match, we might need to calculate them now to
* discern between RENAMED vs RENAMED+MODIFED
*/
if (git_oid_iszero(&idx2wd->old_file.oid) &&
diff->old_src == GIT_ITERATOR_TYPE_WORKDIR &&
!git_diff__oid_for_file(
diff->repo, idx2wd->old_file.path, idx2wd->old_file.mode,
idx2wd->old_file.size, &idx2wd->old_file.oid))
idx2wd->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
if (git_oid_iszero(&idx2wd->new_file.oid) &&
diff->new_src == GIT_ITERATOR_TYPE_WORKDIR &&
!git_diff__oid_for_file(
diff->repo, idx2wd->new_file.path, idx2wd->new_file.mode,
idx2wd->new_file.size, &idx2wd->new_file.oid))
idx2wd->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
if (!git_oid_equal(&idx2wd->old_file.oid, &idx2wd->new_file.oid))
st |= GIT_STATUS_WT_MODIFIED;
}
break; break;
case GIT_DELTA_TYPECHANGE: case GIT_DELTA_TYPECHANGE:
st = GIT_STATUS_WT_TYPECHANGE; st = GIT_STATUS_WT_TYPECHANGE;
...@@ -111,18 +137,19 @@ static bool status_is_included( ...@@ -111,18 +137,19 @@ static bool status_is_included(
} }
static git_status_t status_compute( static git_status_t status_compute(
git_status_list *status,
git_diff_delta *head2idx, git_diff_delta *head2idx,
git_diff_delta *idx2wd) git_diff_delta *idx2wd)
{ {
git_status_t status = 0; git_status_t st = GIT_STATUS_CURRENT;
if (head2idx) if (head2idx)
status |= index_delta2status(head2idx->status); st |= index_delta2status(head2idx);
if (idx2wd) if (idx2wd)
status |= workdir_delta2status(idx2wd->status); st |= workdir_delta2status(status->idx2wd, idx2wd);
return status; return st;
} }
static int status_collect( static int status_collect(
...@@ -139,7 +166,7 @@ static int status_collect( ...@@ -139,7 +166,7 @@ static int status_collect(
status_entry = git__malloc(sizeof(git_status_entry)); status_entry = git__malloc(sizeof(git_status_entry));
GITERR_CHECK_ALLOC(status_entry); GITERR_CHECK_ALLOC(status_entry);
status_entry->status = status_compute(head2idx, idx2wd); status_entry->status = status_compute(status, head2idx, idx2wd);
status_entry->head_to_index = head2idx; status_entry->head_to_index = head2idx;
status_entry->index_to_workdir = idx2wd; status_entry->index_to_workdir = idx2wd;
......
...@@ -61,13 +61,13 @@ static void test_status( ...@@ -61,13 +61,13 @@ static void test_status(
const char *oldname, *newname; const char *oldname, *newname;
size_t i; size_t i;
cl_assert(expected_len == git_status_list_entrycount(status_list)); cl_assert_equal_sz(expected_len, git_status_list_entrycount(status_list));
for (i = 0; i < expected_len; i++) { for (i = 0; i < expected_len; i++) {
actual = git_status_byindex(status_list, i); actual = git_status_byindex(status_list, i);
expected = &expected_list[i]; expected = &expected_list[i];
cl_assert(actual->status == expected->status); cl_assert_equal_i((int)expected->status, (int)actual->status);
oldname = actual->head_to_index ? actual->head_to_index->old_file.path : oldname = actual->head_to_index ? actual->head_to_index->old_file.path :
actual->index_to_workdir ? actual->index_to_workdir->old_file.path : NULL; actual->index_to_workdir ? actual->index_to_workdir->old_file.path : NULL;
...@@ -119,8 +119,10 @@ void test_status_renames__head2index_two(void) ...@@ -119,8 +119,10 @@ void test_status_renames__head2index_two(void)
git_status_list *statuslist; git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
struct status_entry expected[] = { struct status_entry expected[] = {
{ GIT_STATUS_INDEX_RENAMED, "sixserving.txt", "aaa.txt" }, { GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED,
{ GIT_STATUS_INDEX_RENAMED, "untimely.txt", "bbb.txt" }, "sixserving.txt", "aaa.txt" },
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED,
"untimely.txt", "bbb.txt" },
{ GIT_STATUS_INDEX_RENAMED, "songof7cities.txt", "ccc.txt" }, { GIT_STATUS_INDEX_RENAMED, "songof7cities.txt", "ccc.txt" },
{ GIT_STATUS_INDEX_RENAMED, "ikeepsix.txt", "ddd.txt" }, { GIT_STATUS_INDEX_RENAMED, "ikeepsix.txt", "ddd.txt" },
}; };
...@@ -174,8 +176,10 @@ void test_status_renames__index2workdir_two(void) ...@@ -174,8 +176,10 @@ void test_status_renames__index2workdir_two(void)
git_status_list *statuslist; git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
struct status_entry expected[] = { struct status_entry expected[] = {
{ GIT_STATUS_WT_RENAMED, "sixserving.txt", "aaa.txt" }, { GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
{ GIT_STATUS_WT_RENAMED, "untimely.txt", "bbb.txt" }, "sixserving.txt", "aaa.txt" },
{ GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
"untimely.txt", "bbb.txt" },
{ GIT_STATUS_WT_RENAMED, "songof7cities.txt", "ccc.txt" }, { GIT_STATUS_WT_RENAMED, "songof7cities.txt", "ccc.txt" },
{ GIT_STATUS_WT_RENAMED, "ikeepsix.txt", "ddd.txt" }, { GIT_STATUS_WT_RENAMED, "ikeepsix.txt", "ddd.txt" },
}; };
...@@ -199,7 +203,8 @@ void test_status_renames__both_one(void) ...@@ -199,7 +203,8 @@ void test_status_renames__both_one(void)
git_status_list *statuslist; git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
struct status_entry expected[] = { struct status_entry expected[] = {
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED, "ikeepsix.txt", "newname-workdir.txt" }, { GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
"ikeepsix.txt", "newname-workdir.txt" },
}; };
opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED; opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
...@@ -229,10 +234,15 @@ void test_status_renames__both_two(void) ...@@ -229,10 +234,15 @@ void test_status_renames__both_two(void)
git_status_list *statuslist; git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
struct status_entry expected[] = { struct status_entry expected[] = {
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED, "ikeepsix.txt", "ikeepsix-both.txt" }, { GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED |
{ GIT_STATUS_INDEX_RENAMED, "sixserving.txt", "sixserving-index.txt" }, GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
{ GIT_STATUS_WT_RENAMED, "songof7cities.txt", "songof7cities-workdir.txt" }, "ikeepsix.txt", "ikeepsix-both.txt" },
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED, "untimely.txt", "untimely-both.txt" }, { GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED,
"sixserving.txt", "sixserving-index.txt" },
{ GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
"songof7cities.txt", "songof7cities-workdir.txt" },
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
"untimely.txt", "untimely-both.txt" },
}; };
opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED; opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
...@@ -263,3 +273,113 @@ void test_status_renames__both_two(void) ...@@ -263,3 +273,113 @@ void test_status_renames__both_two(void)
git_index_free(index); git_index_free(index);
} }
void test_status_renames__both_casechange_one(void)
{
git_index *index;
git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
int index_caps;
struct status_entry expected_icase[] = {
{ GIT_STATUS_INDEX_RENAMED,
"ikeepsix.txt", "IKeepSix.txt" },
};
struct status_entry expected_case[] = {
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
"ikeepsix.txt", "IKEEPSIX.txt" },
};
opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
opts.flags |= GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
opts.flags |= GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
cl_git_pass(git_repository_index(&index, g_repo));
index_caps = git_index_caps(index);
rename_file(g_repo, "ikeepsix.txt", "IKeepSix.txt");
cl_git_pass(git_index_remove_bypath(index, "ikeepsix.txt"));
cl_git_pass(git_index_add_bypath(index, "IKeepSix.txt"));
cl_git_pass(git_index_write(index));
/* on a case-insensitive file system, this change won't matter.
* on a case-sensitive one, it will.
*/
rename_file(g_repo, "IKeepSix.txt", "IKEEPSIX.txt");
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
test_status(statuslist, (index_caps & GIT_INDEXCAP_IGNORE_CASE) ?
expected_icase : expected_case, 1);
git_status_list_free(statuslist);
git_index_free(index);
}
void test_status_renames__both_casechange_two(void)
{
git_index *index;
git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
int index_caps;
struct status_entry expected_icase[] = {
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED |
GIT_STATUS_WT_MODIFIED,
"ikeepsix.txt", "IKeepSix.txt" },
{ GIT_STATUS_INDEX_MODIFIED,
"sixserving.txt", "sixserving.txt" },
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_MODIFIED,
"songof7cities.txt", "songof7.txt" },
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
"untimely.txt", "untimeliest.txt" }
};
struct status_entry expected_case[] = {
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_INDEX_MODIFIED |
GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED,
"ikeepsix.txt", "ikeepsix.txt" },
{ GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_RENAMED,
"sixserving.txt", "SixServing.txt" },
{ GIT_STATUS_INDEX_RENAMED |
GIT_STATUS_WT_MODIFIED | GIT_STATUS_WT_RENAMED,
"songof7cities.txt", "SONGOF7.txt" },
{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED,
"untimely.txt", "untimeliest.txt" }
};
opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
opts.flags |= GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
opts.flags |= GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
cl_git_pass(git_repository_index(&index, g_repo));
index_caps = git_index_caps(index);
rename_and_edit_file(g_repo, "ikeepsix.txt", "IKeepSix.txt");
rename_and_edit_file(g_repo, "sixserving.txt", "sixserving.txt");
rename_file(g_repo, "songof7cities.txt", "songof7.txt");
rename_file(g_repo, "untimely.txt", "untimelier.txt");
cl_git_pass(git_index_remove_bypath(index, "ikeepsix.txt"));
cl_git_pass(git_index_remove_bypath(index, "sixserving.txt"));
cl_git_pass(git_index_remove_bypath(index, "songof7cities.txt"));
cl_git_pass(git_index_remove_bypath(index, "untimely.txt"));
cl_git_pass(git_index_add_bypath(index, "IKeepSix.txt"));
cl_git_pass(git_index_add_bypath(index, "sixserving.txt"));
cl_git_pass(git_index_add_bypath(index, "songof7.txt"));
cl_git_pass(git_index_add_bypath(index, "untimelier.txt"));
cl_git_pass(git_index_write(index));
rename_and_edit_file(g_repo, "IKeepSix.txt", "ikeepsix.txt");
rename_file(g_repo, "sixserving.txt", "SixServing.txt");
rename_and_edit_file(g_repo, "songof7.txt", "SONGOF7.txt");
rename_file(g_repo, "untimelier.txt", "untimeliest.txt");
cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
test_status(statuslist, (index_caps & GIT_INDEXCAP_IGNORE_CASE) ?
expected_icase : expected_case, 4);
git_status_list_free(statuslist);
git_index_free(index);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment