Commit 71a3d27e by Russell Belfer

Replace diff delta binary with flags

Previously the git_diff_delta recorded if the delta was binary.
This replaces that (with no net change in structure size) with
a full set of flags.  The flag values that were already in use
for individual git_diff_file objects are reused for the delta
flags, too (along with renaming those flags to make it clear that
they are used more generally).

This (a) makes things somewhat more consistent (because I was
using a -1 value in the "boolean" binary field to indicate unset,
whereas now I can just use the flags that are easier to understand),
and (b) will make it easier for me to add some additional flags to
the delta object in the future, such as marking the results of a
copy/rename detection or other deltas that might want a special
indicator.

While making this change, I officially moved some of the flags that
were internal only into the private diff header.

This also allowed me to remove a gross hack in rename/copy detect
code where I was overwriting the status field with an internal
value.
parent 9bc8be3d
......@@ -88,10 +88,9 @@ typedef enum {
GIT_DIFF_INCLUDE_UNTRACKED = (1 << 8),
/** Include unmodified files in the diff list */
GIT_DIFF_INCLUDE_UNMODIFIED = (1 << 9),
/** Even with the GIT_DIFF_INCLUDE_UNTRACKED flag, when an untracked
* directory is found, only a single entry for the directory is added
* to the diff list; with this flag, all files under the directory will
* be included, too.
/** Even with GIT_DIFF_INCLUDE_UNTRACKED, an entire untracked directory
* will be marked with only a single entry in the diff list; this flag
* adds all files under the directory as UNTRACKED entries, too.
*/
GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1 << 10),
/** If the pathspec is set in the diff options, this flags means to
......@@ -120,6 +119,11 @@ typedef enum {
GIT_DIFF_INCLUDE_TYPECHANGE_TREES = (1 << 16),
/** Ignore file mode changes */
GIT_DIFF_IGNORE_FILEMODE = (1 << 17),
/** Even with GIT_DIFF_INCLUDE_IGNORED, an entire ignored directory
* will be marked with only a single entry in the diff list; this flag
* adds all files under the directory as IGNORED entries, too.
*/
GIT_DIFF_RECURSE_IGNORED_DIRS = (1 << 10),
} git_diff_option_t;
/**
......@@ -133,20 +137,18 @@ typedef enum {
typedef struct git_diff_list git_diff_list;
/**
* Flags for the file object on each side of a diff.
* Flags for the delta object and the file objects on each side.
*
* Note: most of these flags are just for **internal** consumption by
* libgit2, but some of them may be interesting to external users.
* These flags are used for both the `flags` value of the `git_diff_delta`
* and the flags for the `git_diff_file` objects representing the old and
* new sides of the delta. Values outside of this public range should be
* considered reserved for internal or future use.
*/
typedef enum {
GIT_DIFF_FILE_VALID_OID = (1 << 0), /** `oid` value is known correct */
GIT_DIFF_FILE_FREE_PATH = (1 << 1), /** `path` is allocated memory */
GIT_DIFF_FILE_BINARY = (1 << 2), /** should be considered binary data */
GIT_DIFF_FILE_NOT_BINARY = (1 << 3), /** should be considered text data */
GIT_DIFF_FILE_FREE_DATA = (1 << 4), /** internal file data is allocated */
GIT_DIFF_FILE_UNMAP_DATA = (1 << 5), /** internal file data is mmap'ed */
GIT_DIFF_FILE_NO_DATA = (1 << 6), /** file data should not be loaded */
} git_diff_file_flag_t;
GIT_DIFF_FLAG_BINARY = (1 << 0), /** file(s) treated as binary data */
GIT_DIFF_FLAG_NOT_BINARY = (1 << 1), /** file(s) treated as text data */
GIT_DIFF_FLAG_VALID_OID = (1 << 2), /** `oid` value is known correct */
} git_diff_flag_t;
/**
* What type of change is described by a git_diff_delta?
......@@ -186,8 +188,7 @@ typedef enum {
*
* `size` is the size of the entry in bytes.
*
* `flags` is a combination of the `git_diff_file_flag_t` types, but those
* are largely internal values.
* `flags` is a combination of the `git_diff_flag_t` types
*
* `mode` is, roughly, the stat() `st_mode` value for the item. This will
* be restricted to one of the `git_filemode_t` values.
......@@ -196,7 +197,7 @@ typedef struct {
git_oid oid;
const char *path;
git_off_t size;
unsigned int flags;
uint32_t flags;
uint16_t mode;
} git_diff_file;
......@@ -219,16 +220,17 @@ typedef struct {
*
* Under some circumstances, in the name of efficiency, not all fields will
* be filled in, but we generally try to fill in as much as possible. One
* example is that the "binary" field will not examine file contents if you
* do not pass in hunk and/or line callbacks to the diff foreach iteration
* function. It will just use the git attributes for those files.
* example is that the "flags" field may not have either the `BINARY` or the
* `NOT_BINARY` flag set to avoid examining file contents if you do not pass
* in hunk and/or line callbacks to the diff foreach iteration function. It
* will just use the git attributes for those files.
*/
typedef struct {
git_diff_file old_file;
git_diff_file new_file;
git_delta_t status;
unsigned int similarity; /**< for RENAMED and COPIED, value 0-100 */
int binary;
uint32_t similarity; /**< for RENAMED and COPIED, value 0-100 */
uint32_t flags;
} git_diff_delta;
/**
......
......@@ -78,7 +78,7 @@ static int checkout_notify(
git_oid_cpy(&wdfile.oid, &wditem->oid);
wdfile.path = wditem->path;
wdfile.size = wditem->file_size;
wdfile.flags = GIT_DIFF_FILE_VALID_OID;
wdfile.flags = GIT_DIFF_FLAG_VALID_OID;
wdfile.mode = wditem->mode;
workdir = &wdfile;
......
......@@ -92,11 +92,11 @@ static int diff_delta__from_one(
git_oid_cpy(&delta->new_file.oid, &entry->oid);
}
delta->old_file.flags |= GIT_DIFF_FILE_VALID_OID;
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
if (delta->status == GIT_DELTA_DELETED ||
!git_oid_iszero(&delta->new_file.oid))
delta->new_file.flags |= GIT_DIFF_FILE_VALID_OID;
delta->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
notify_res = diff_notify(diff, delta, matched_pathspec);
......@@ -142,7 +142,7 @@ static int diff_delta__from_two(
git_oid_cpy(&delta->old_file.oid, &old_entry->oid);
delta->old_file.size = old_entry->file_size;
delta->old_file.mode = old_mode;
delta->old_file.flags |= GIT_DIFF_FILE_VALID_OID;
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
git_oid_cpy(&delta->new_file.oid, &new_entry->oid);
delta->new_file.size = new_entry->file_size;
......@@ -156,7 +156,7 @@ static int diff_delta__from_two(
}
if (new_oid || !git_oid_iszero(&new_entry->oid))
delta->new_file.flags |= GIT_DIFF_FILE_VALID_OID;
delta->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
notify_res = diff_notify(diff, delta, matched_pathspec);
......
......@@ -28,8 +28,14 @@ enum {
GIT_DIFFCAPS_USE_DEV = (1 << 4), /* use st_dev? */
};
#define GIT_DELTA__TO_DELETE 10
#define GIT_DELTA__TO_SPLIT 11
enum {
GIT_DIFF_FLAG__FREE_PATH = (1 << 7), /* `path` is allocated memory */
GIT_DIFF_FLAG__FREE_DATA = (1 << 8), /* internal file data is allocated */
GIT_DIFF_FLAG__UNMAP_DATA = (1 << 9), /* internal file data is mmap'ed */
GIT_DIFF_FLAG__NO_DATA = (1 << 10), /* file data should not be loaded */
GIT_DIFF_FLAG__TO_DELETE = (1 << 11), /* delete entry during rename det. */
GIT_DIFF_FLAG__TO_SPLIT = (1 << 12), /* split entry during rename det. */
};
struct git_diff_list {
git_refcount rc;
......
......@@ -52,8 +52,8 @@ static int parse_hunk_header(git_diff_range *range, const char *header)
return 0;
}
#define KNOWN_BINARY_FLAGS (GIT_DIFF_FILE_BINARY|GIT_DIFF_FILE_NOT_BINARY)
#define NOT_BINARY_FLAGS (GIT_DIFF_FILE_NOT_BINARY|GIT_DIFF_FILE_NO_DATA)
#define KNOWN_BINARY_FLAGS (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)
#define NOT_BINARY_FLAGS (GIT_DIFF_FLAG_NOT_BINARY|GIT_DIFF_FLAG__NO_DATA)
static int update_file_is_binary_by_attr(
git_repository *repo, git_diff_file *file)
......@@ -68,9 +68,9 @@ static int update_file_is_binary_by_attr(
return -1;
if (GIT_ATTR_FALSE(value))
file->flags |= GIT_DIFF_FILE_BINARY;
file->flags |= GIT_DIFF_FLAG_BINARY;
else if (GIT_ATTR_TRUE(value))
file->flags |= GIT_DIFF_FILE_NOT_BINARY;
file->flags |= GIT_DIFF_FLAG_NOT_BINARY;
/* otherwise leave file->flags alone */
return 0;
......@@ -78,15 +78,15 @@ static int update_file_is_binary_by_attr(
static void update_delta_is_binary(git_diff_delta *delta)
{
if ((delta->old_file.flags & GIT_DIFF_FILE_BINARY) != 0 ||
(delta->new_file.flags & GIT_DIFF_FILE_BINARY) != 0)
delta->binary = 1;
if ((delta->old_file.flags & GIT_DIFF_FLAG_BINARY) != 0 ||
(delta->new_file.flags & GIT_DIFF_FLAG_BINARY) != 0)
delta->flags |= GIT_DIFF_FLAG_BINARY;
else if ((delta->old_file.flags & NOT_BINARY_FLAGS) != 0 &&
(delta->new_file.flags & NOT_BINARY_FLAGS) != 0)
delta->binary = 0;
delta->flags |= GIT_DIFF_FLAG_NOT_BINARY;
/* otherwise leave delta->binary value untouched */
/* otherwise leave delta->flags binary value untouched */
}
/* returns if we forced binary setting (and no further checks needed) */
......@@ -95,24 +95,24 @@ static bool diff_delta_is_binary_forced(
git_diff_delta *delta)
{
/* return true if binary-ness has already been settled */
if (delta->binary != -1)
if ((delta->flags & KNOWN_BINARY_FLAGS) != 0)
return true;
/* make sure files are conceivably mmap-able */
if ((git_off_t)((size_t)delta->old_file.size) != delta->old_file.size ||
(git_off_t)((size_t)delta->new_file.size) != delta->new_file.size)
{
delta->old_file.flags |= GIT_DIFF_FILE_BINARY;
delta->new_file.flags |= GIT_DIFF_FILE_BINARY;
delta->binary = 1;
delta->old_file.flags |= GIT_DIFF_FLAG_BINARY;
delta->new_file.flags |= GIT_DIFF_FLAG_BINARY;
delta->flags |= GIT_DIFF_FLAG_BINARY;
return true;
}
/* check if user is forcing us to text diff these files */
if (ctxt->opts && (ctxt->opts->flags & GIT_DIFF_FORCE_TEXT) != 0) {
delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
delta->binary = 0;
delta->old_file.flags |= GIT_DIFF_FLAG_NOT_BINARY;
delta->new_file.flags |= GIT_DIFF_FLAG_NOT_BINARY;
delta->flags |= GIT_DIFF_FLAG_NOT_BINARY;
return true;
}
......@@ -125,8 +125,6 @@ static int diff_delta_is_binary_by_attr(
int error = 0, mirror_new;
git_diff_delta *delta = patch->delta;
delta->binary = -1;
if (diff_delta_is_binary_forced(ctxt, delta))
return 0;
......@@ -152,12 +150,11 @@ static int diff_delta_is_binary_by_content(
git_diff_file *file,
const git_map *map)
{
const git_buf search = { map->data, 0, min(map->len, 4000) };
if (diff_delta_is_binary_forced(ctxt, delta))
return 0;
if ((file->flags & KNOWN_BINARY_FLAGS) == 0) {
const git_buf search = { map->data, 0, min(map->len, 4000) };
/* TODO: provide encoding / binary detection callbacks that can
* be UTF-8 aware, etc. For now, instead of trying to be smart,
* let's just use the simple NUL-byte detection that core git uses.
......@@ -165,10 +162,9 @@ static int diff_delta_is_binary_by_content(
/* previously was: if (git_buf_text_is_binary(&search)) */
if (git_buf_text_contains_nul(&search))
file->flags |= GIT_DIFF_FILE_BINARY;
file->flags |= GIT_DIFF_FLAG_BINARY;
else
file->flags |= GIT_DIFF_FILE_NOT_BINARY;
}
file->flags |= GIT_DIFF_FLAG_NOT_BINARY;
update_delta_is_binary(delta);
......@@ -192,7 +188,7 @@ static int diff_delta_is_binary_by_size(
}
if (file->size > threshold)
file->flags |= GIT_DIFF_FILE_BINARY;
file->flags |= GIT_DIFF_FLAG_BINARY;
update_delta_is_binary(delta);
......@@ -247,7 +243,7 @@ static int get_blob_content(
map->data = git_buf_detach(&content);
map->len = strlen(map->data);
file->flags |= GIT_DIFF_FILE_FREE_DATA;
file->flags |= GIT_DIFF_FLAG__FREE_DATA;
return 0;
}
......@@ -270,7 +266,7 @@ static int get_blob_content(
/* if blob is too large to diff, mark as binary */
if ((error = diff_delta_is_binary_by_size(ctxt, delta, file)) < 0)
return error;
if (delta->binary == 1)
if ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
return 0;
if (odb_obj != NULL) {
......@@ -306,14 +302,14 @@ static int get_workdir_sm_content(
return error;
/* update OID if we didn't have it previously */
if ((file->flags & GIT_DIFF_FILE_VALID_OID) == 0) {
if ((file->flags & GIT_DIFF_FLAG_VALID_OID) == 0) {
const git_oid* sm_head;
if ((sm_head = git_submodule_wd_id(sm)) != NULL ||
(sm_head = git_submodule_head_id(sm)) != NULL)
{
git_oid_cpy(&file->oid, sm_head);
file->flags |= GIT_DIFF_FILE_VALID_OID;
file->flags |= GIT_DIFF_FLAG_VALID_OID;
}
}
......@@ -329,7 +325,7 @@ static int get_workdir_sm_content(
map->data = git_buf_detach(&content);
map->len = strlen(map->data);
file->flags |= GIT_DIFF_FILE_FREE_DATA;
file->flags |= GIT_DIFF_FLAG__FREE_DATA;
return 0;
}
......@@ -356,8 +352,8 @@ static int get_workdir_content(
if (S_ISLNK(file->mode)) {
ssize_t alloc_len, read_len;
file->flags |= GIT_DIFF_FILE_FREE_DATA;
file->flags |= GIT_DIFF_FILE_BINARY;
file->flags |= GIT_DIFF_FLAG__FREE_DATA;
file->flags |= GIT_DIFF_FLAG_BINARY;
/* link path on disk could be UTF-16, so prepare a buffer that is
* big enough to handle some UTF-8 data expansion
......@@ -389,7 +385,7 @@ static int get_workdir_content(
file->size = git_futils_filesize(fd);
if ((error = diff_delta_is_binary_by_size(ctxt, delta, file)) < 0 ||
delta->binary == 1)
(delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
goto close_and_cleanup;
error = git_filters_load(
......@@ -402,7 +398,7 @@ static int get_workdir_content(
goto close_and_cleanup;
error = git_futils_mmap_ro(map, fd, 0, (size_t)file->size);
file->flags |= GIT_DIFF_FILE_UNMAP_DATA;
file->flags |= GIT_DIFF_FLAG__UNMAP_DATA;
} else {
git_buf raw = GIT_BUF_INIT, filtered = GIT_BUF_INIT;
......@@ -412,7 +408,7 @@ static int get_workdir_content(
map->len = git_buf_len(&filtered);
map->data = git_buf_detach(&filtered);
file->flags |= GIT_DIFF_FILE_FREE_DATA;
file->flags |= GIT_DIFF_FLAG__FREE_DATA;
}
git_buf_free(&raw);
......@@ -425,11 +421,11 @@ close_and_cleanup:
}
/* once data is loaded, update OID if we didn't have it previously */
if (!error && (file->flags & GIT_DIFF_FILE_VALID_OID) == 0) {
if (!error && (file->flags & GIT_DIFF_FLAG_VALID_OID) == 0) {
error = git_odb_hash(
&file->oid, map->data, map->len, GIT_OBJ_BLOB);
if (!error)
file->flags |= GIT_DIFF_FILE_VALID_OID;
file->flags |= GIT_DIFF_FLAG_VALID_OID;
}
if (!error)
......@@ -445,17 +441,17 @@ static void release_content(git_diff_file *file, git_map *map, git_blob *blob)
if (blob != NULL)
git_blob_free(blob);
if (file->flags & GIT_DIFF_FILE_FREE_DATA) {
if (file->flags & GIT_DIFF_FLAG__FREE_DATA) {
git__free(map->data);
map->data = "";
map->len = 0;
file->flags &= ~GIT_DIFF_FILE_FREE_DATA;
file->flags &= ~GIT_DIFF_FLAG__FREE_DATA;
}
else if (file->flags & GIT_DIFF_FILE_UNMAP_DATA) {
else if (file->flags & GIT_DIFF_FLAG__UNMAP_DATA) {
git_futils_mmap_free(map);
map->data = "";
map->len = 0;
file->flags &= ~GIT_DIFF_FILE_UNMAP_DATA;
file->flags &= ~GIT_DIFF_FLAG__UNMAP_DATA;
}
}
......@@ -555,7 +551,7 @@ static int diff_patch_load(
patch->new_data.len = 0;
patch->new_blob = NULL;
if (delta->binary == 1)
if ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
goto cleanup;
if (!ctxt->hunk_cb &&
......@@ -565,25 +561,25 @@ static int diff_patch_load(
switch (delta->status) {
case GIT_DELTA_ADDED:
delta->old_file.flags |= GIT_DIFF_FILE_NO_DATA;
delta->old_file.flags |= GIT_DIFF_FLAG__NO_DATA;
break;
case GIT_DELTA_DELETED:
delta->new_file.flags |= GIT_DIFF_FILE_NO_DATA;
delta->new_file.flags |= GIT_DIFF_FLAG__NO_DATA;
break;
case GIT_DELTA_MODIFIED:
break;
case GIT_DELTA_UNTRACKED:
delta->old_file.flags |= GIT_DIFF_FILE_NO_DATA;
delta->old_file.flags |= GIT_DIFF_FLAG__NO_DATA;
if ((ctxt->opts->flags & GIT_DIFF_INCLUDE_UNTRACKED_CONTENT) == 0)
delta->new_file.flags |= GIT_DIFF_FILE_NO_DATA;
delta->new_file.flags |= GIT_DIFF_FLAG__NO_DATA;
break;
default:
delta->new_file.flags |= GIT_DIFF_FILE_NO_DATA;
delta->old_file.flags |= GIT_DIFF_FILE_NO_DATA;
delta->new_file.flags |= GIT_DIFF_FLAG__NO_DATA;
delta->old_file.flags |= GIT_DIFF_FLAG__NO_DATA;
break;
}
#define CHECK_UNMODIFIED (GIT_DIFF_FILE_NO_DATA | GIT_DIFF_FILE_VALID_OID)
#define CHECK_UNMODIFIED (GIT_DIFF_FLAG__NO_DATA | GIT_DIFF_FLAG_VALID_OID)
check_if_unmodified =
(delta->old_file.flags & CHECK_UNMODIFIED) == 0 &&
......@@ -594,41 +590,41 @@ static int diff_patch_load(
* memory footprint during diff.
*/
if ((delta->old_file.flags & GIT_DIFF_FILE_NO_DATA) == 0 &&
if ((delta->old_file.flags & GIT_DIFF_FLAG__NO_DATA) == 0 &&
patch->old_src == GIT_ITERATOR_TYPE_WORKDIR) {
if ((error = get_workdir_content(
ctxt, delta, &delta->old_file, &patch->old_data)) < 0)
goto cleanup;
if (delta->binary == 1)
if ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
goto cleanup;
}
if ((delta->new_file.flags & GIT_DIFF_FILE_NO_DATA) == 0 &&
if ((delta->new_file.flags & GIT_DIFF_FLAG__NO_DATA) == 0 &&
patch->new_src == GIT_ITERATOR_TYPE_WORKDIR) {
if ((error = get_workdir_content(
ctxt, delta, &delta->new_file, &patch->new_data)) < 0)
goto cleanup;
if (delta->binary == 1)
if ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
goto cleanup;
}
if ((delta->old_file.flags & GIT_DIFF_FILE_NO_DATA) == 0 &&
if ((delta->old_file.flags & GIT_DIFF_FLAG__NO_DATA) == 0 &&
patch->old_src != GIT_ITERATOR_TYPE_WORKDIR) {
if ((error = get_blob_content(
ctxt, delta, &delta->old_file,
&patch->old_data, &patch->old_blob)) < 0)
goto cleanup;
if (delta->binary == 1)
if ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
goto cleanup;
}
if ((delta->new_file.flags & GIT_DIFF_FILE_NO_DATA) == 0 &&
if ((delta->new_file.flags & GIT_DIFF_FLAG__NO_DATA) == 0 &&
patch->new_src != GIT_ITERATOR_TYPE_WORKDIR) {
if ((error = get_blob_content(
ctxt, delta, &delta->new_file,
&patch->new_data, &patch->new_blob)) < 0)
goto cleanup;
if (delta->binary == 1)
if ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
goto cleanup;
}
......@@ -646,13 +642,13 @@ static int diff_patch_load(
}
cleanup:
if (delta->binary == -1)
if ((delta->flags & KNOWN_BINARY_FLAGS) == 0)
update_delta_is_binary(delta);
if (!error) {
patch->flags |= GIT_DIFF_PATCH_LOADED;
if (delta->binary != 1 &&
if ((delta->flags & GIT_DIFF_FLAG_BINARY) == 0 &&
delta->status != GIT_DELTA_UNMODIFIED &&
(patch->old_data.len || patch->new_data.len) &&
!git_oid_equal(&delta->old_file.oid, &delta->new_file.oid))
......@@ -1138,7 +1134,7 @@ static int print_patch_file(
newpath = "/dev/null";
}
if (delta->binary != 1) {
if ((delta->flags & GIT_DIFF_FLAG_BINARY) == 0) {
git_buf_printf(pi->buf, "--- %s%s\n", oldpfx, oldpath);
git_buf_printf(pi->buf, "+++ %s%s\n", newpfx, newpath);
}
......@@ -1153,7 +1149,7 @@ static int print_patch_file(
return GIT_EUSER;
}
if (delta->binary != 1)
if ((delta->flags & GIT_DIFF_FLAG_BINARY) == 0)
return 0;
git_buf_clear(pi->buf);
......@@ -1268,7 +1264,7 @@ static void set_data_from_blob(
map->data = (char *)git_blob_rawcontent(blob);
} else {
file->size = 0;
file->flags |= GIT_DIFF_FILE_NO_DATA;
file->flags |= GIT_DIFF_FLAG__NO_DATA;
map->len = 0;
map->data = "";
......@@ -1283,7 +1279,7 @@ static void set_data_from_buffer(
map->len = buffer_len;
if (!buffer) {
file->flags |= GIT_DIFF_FILE_NO_DATA;
file->flags |= GIT_DIFF_FLAG__NO_DATA;
map->data = NULL;
} else {
map->data = (char *)buffer;
......@@ -1322,13 +1318,13 @@ static int diff_single_apply(diff_single_data *data)
{
int error;
git_diff_delta *delta = &data->delta;
bool has_old = ((delta->old_file.flags & GIT_DIFF_FILE_NO_DATA) == 0);
bool has_new = ((delta->new_file.flags & GIT_DIFF_FILE_NO_DATA) == 0);
bool has_old = ((delta->old_file.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
bool has_new = ((delta->new_file.flags & GIT_DIFF_FLAG__NO_DATA) == 0);
/* finish setting up fake git_diff_delta record and loaded data */
data->patch.delta = delta;
delta->binary = -1;
delta->flags = delta->flags & ~KNOWN_BINARY_FLAGS;
delta->status = has_new ?
(has_old ? GIT_DELTA_MODIFIED : GIT_DELTA_ADDED) :
......@@ -1345,7 +1341,8 @@ static int diff_single_apply(diff_single_data *data)
data->patch.flags |= GIT_DIFF_PATCH_LOADED;
if (delta->binary != 1 && delta->status != GIT_DELTA_UNMODIFIED)
if ((delta->flags & GIT_DIFF_FLAG_BINARY) == 0 &&
delta->status != GIT_DELTA_UNMODIFIED)
data->patch.flags |= GIT_DIFF_PATCH_DIFFABLE;
/* do diffs */
......@@ -1469,7 +1466,7 @@ int git_diff_get_patch(
*delta_ptr = delta;
if (!patch_ptr &&
(delta->binary != -1 ||
((delta->flags & KNOWN_BINARY_FLAGS) != 0 ||
(diff->opts.flags & GIT_DIFF_SKIP_BINARY_CHECK) != 0))
return 0;
......
......@@ -315,10 +315,10 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
/* build new delta list without TO_DELETE and splitting TO_SPLIT */
git_vector_foreach(&diff->deltas, i, delta) {
if (delta->status == GIT_DELTA__TO_DELETE)
if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0)
continue;
if (delta->status == GIT_DELTA__TO_SPLIT) {
if ((delta->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0) {
git_diff_delta *deleted = diff_delta__dup(delta, &diff->pool);
if (!deleted)
goto on_error;
......@@ -326,7 +326,7 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
deleted->status = GIT_DELTA_DELETED;
memset(&deleted->new_file, 0, sizeof(deleted->new_file));
deleted->new_file.path = deleted->old_file.path;
deleted->new_file.flags |= GIT_DIFF_FILE_VALID_OID;
deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
if (git_vector_insert(&onto, deleted) < 0)
goto on_error;
......@@ -334,7 +334,7 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
delta->status = GIT_DELTA_ADDED;
memset(&delta->old_file, 0, sizeof(delta->old_file));
delta->old_file.path = delta->new_file.path;
delta->old_file.flags |= GIT_DIFF_FILE_VALID_OID;
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
}
if (git_vector_insert(&onto, delta) < 0)
......@@ -343,7 +343,7 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
/* cannot return an error past this point */
git_vector_foreach(&diff->deltas, i, delta)
if (delta->status == GIT_DELTA__TO_DELETE)
if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0)
git__free(delta);
/* swap new delta list into place */
......@@ -411,7 +411,7 @@ int git_diff_find_similar(
/* calc_similarity(NULL, &from->old_file, from->new_file); */
if (similarity < opts.break_rewrite_threshold) {
from->status = GIT_DELTA__TO_SPLIT;
from->flags |= GIT_DIFF_FLAG__TO_SPLIT;
num_changes++;
}
}
......@@ -502,7 +502,7 @@ int git_diff_find_similar(
to->status = GIT_DELTA_RENAMED;
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
from->status = GIT_DELTA__TO_DELETE;
from->flags |= GIT_DIFF_FLAG__TO_DELETE;
num_changes++;
continue;
......@@ -522,7 +522,7 @@ int git_diff_find_similar(
from->status = GIT_DELTA_ADDED;
memset(&from->old_file, 0, sizeof(from->old_file));
from->old_file.path = to->old_file.path;
from->old_file.flags |= GIT_DIFF_FILE_VALID_OID;
from->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
continue;
}
......
......@@ -32,7 +32,7 @@ int diff_file_cb(
e->files++;
if (delta->binary)
if ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0)
e->files_binary++;
cl_assert(delta->status <= GIT_DELTA_TYPECHANGE);
......@@ -126,7 +126,8 @@ int diff_foreach_via_iterator(
/* if there are no changes, then the patch will be NULL */
if (!patch) {
cl_assert(delta->status == GIT_DELTA_UNMODIFIED || delta->binary == 1);
cl_assert(delta->status == GIT_DELTA_UNMODIFIED ||
(delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
continue;
}
......
......@@ -152,8 +152,8 @@ void test_diff_diffiter__max_size_threshold(void)
file_count++;
hunk_count += (int)git_diff_patch_num_hunks(patch);
assert(delta->binary == 0 || delta->binary == 1);
binary_count += delta->binary;
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
git_diff_patch_free(patch);
}
......@@ -185,8 +185,8 @@ void test_diff_diffiter__max_size_threshold(void)
file_count++;
hunk_count += (int)git_diff_patch_num_hunks(patch);
assert(delta->binary == 0 || delta->binary == 1);
binary_count += delta->binary;
assert((delta->flags & (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)) != 0);
binary_count += ((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
git_diff_patch_free(patch);
}
......
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