Skip to content

Commit fea24c5

Browse files
committed
PERF: In MERGE, lazily compute is_binary
1 parent d675982 commit fea24c5

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/merge.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ struct merge_diff_df_data {
6161
git_merge_diff *prev_conflict;
6262
};
6363

64+
GIT_INLINE(int) merge_diff_detect_binary(
65+
bool *binary_out,
66+
git_repository *repo,
67+
const git_merge_diff *conflict);
68+
6469

6570
/* Merge base computation */
6671

@@ -662,6 +667,7 @@ static int merge_conflict_resolve_automerge(
662667
git_odb *odb = NULL;
663668
git_oid automerge_oid;
664669
int error = 0;
670+
bool binary = false;
665671

666672
assert(resolved && diff_list && conflict);
667673

@@ -697,7 +703,9 @@ static int merge_conflict_resolve_automerge(
697703
return 0;
698704

699705
/* Reject binary conflicts */
700-
if (conflict->binary)
706+
if ((error = merge_diff_detect_binary(&binary, diff_list->repo, conflict)) < 0)
707+
return error;
708+
if (binary)
701709
return 0;
702710

703711
ancestor = GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry) ?
@@ -1303,35 +1311,39 @@ GIT_INLINE(int) merge_diff_detect_type(
13031311
}
13041312

13051313
GIT_INLINE(int) merge_diff_detect_binary(
1314+
bool *binary_out,
13061315
git_repository *repo,
1307-
git_merge_diff *conflict)
1316+
const git_merge_diff *conflict)
13081317
{
13091318
git_blob *ancestor_blob = NULL, *our_blob = NULL, *their_blob = NULL;
13101319
int error = 0;
1320+
bool binary = false;
13111321

13121322
if (GIT_MERGE_INDEX_ENTRY_ISFILE(conflict->ancestor_entry)) {
13131323
if ((error = git_blob_lookup(&ancestor_blob, repo, &conflict->ancestor_entry.id)) < 0)
13141324
goto done;
13151325

1316-
conflict->binary = git_blob_is_binary(ancestor_blob);
1326+
binary = git_blob_is_binary(ancestor_blob);
13171327
}
13181328

1319-
if (!conflict->binary &&
1329+
if (!binary &&
13201330
GIT_MERGE_INDEX_ENTRY_ISFILE(conflict->our_entry)) {
13211331
if ((error = git_blob_lookup(&our_blob, repo, &conflict->our_entry.id)) < 0)
13221332
goto done;
13231333

1324-
conflict->binary = git_blob_is_binary(our_blob);
1334+
binary = git_blob_is_binary(our_blob);
13251335
}
13261336

1327-
if (!conflict->binary &&
1337+
if (!binary &&
13281338
GIT_MERGE_INDEX_ENTRY_ISFILE(conflict->their_entry)) {
13291339
if ((error = git_blob_lookup(&their_blob, repo, &conflict->their_entry.id)) < 0)
13301340
goto done;
13311341

1332-
conflict->binary = git_blob_is_binary(their_blob);
1342+
binary = git_blob_is_binary(their_blob);
13331343
}
13341344

1345+
*binary_out = binary;
1346+
13351347
done:
13361348
git_blob_free(ancestor_blob);
13371349
git_blob_free(our_blob);
@@ -1411,7 +1423,6 @@ static int merge_diff_list_insert_conflict(
14111423
if ((conflict = merge_diff_from_index_entries(diff_list, tree_items)) == NULL ||
14121424
merge_diff_detect_type(conflict) < 0 ||
14131425
merge_diff_detect_df_conflict(merge_df_data, conflict) < 0 ||
1414-
merge_diff_detect_binary(diff_list->repo, conflict) < 0 ||
14151426
git_vector_insert(&diff_list->conflicts, conflict) < 0)
14161427
return -1;
14171428

src/merge.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ typedef struct {
107107
git_index_entry their_entry;
108108
git_delta_t their_status;
109109

110-
int binary:1;
111110
} git_merge_diff;
112111

113112
int git_merge__bases_many(

0 commit comments

Comments
 (0)