| 11 | #include "promisor-remote.h" |
| 12 | |
| 13 | static int should_break(struct repository *r, |
| 14 | struct diff_filespec *src, |
| 15 | struct diff_filespec *dst, |
| 16 | int break_score, |
| 17 | int *merge_score_p) |
| 18 | { |
| 19 | /* dst is recorded as a modification of src. Are they so |
| 20 | * different that we are better off recording this as a pair |
| 21 | * of delete and create? |
| 22 | * |
| 23 | * There are two criteria used in this algorithm. For the |
| 24 | * purposes of helping later rename/copy, we take both delete |
| 25 | * and insert into account and estimate the amount of "edit". |
| 26 | * If the edit is very large, we break this pair so that |
| 27 | * rename/copy can pick the pieces up to match with other |
| 28 | * files. |
| 29 | * |
| 30 | * On the other hand, we would want to ignore inserts for the |
| 31 | * pure "complete rewrite" detection. As long as most of the |
| 32 | * existing contents were removed from the file, it is a |
| 33 | * complete rewrite, and if sizable chunk from the original |
| 34 | * still remains in the result, it is not a rewrite. It does |
| 35 | * not matter how much or how little new material is added to |
| 36 | * the file. |
| 37 | * |
| 38 | * The score we leave for such a broken filepair uses the |
| 39 | * latter definition so that later clean-up stage can find the |
| 40 | * pieces that should not have been broken according to the |
| 41 | * latter definition after rename/copy runs, and merge the |
| 42 | * broken pair that have a score lower than given criteria |
| 43 | * back together. The break operation itself happens |
| 44 | * according to the former definition. |
| 45 | * |
| 46 | * The minimum_edit parameter tells us when to break (the |
| 47 | * amount of "edit" required for us to consider breaking the |
| 48 | * pair). We leave the amount of deletion in *merge_score_p |
| 49 | * when we return. |
| 50 | * |
| 51 | * The value we return is 1 if we want the pair to be broken, |
| 52 | * or 0 if we do not. |
| 53 | */ |
| 54 | unsigned long delta_size, max_size; |
| 55 | unsigned long src_copied, literal_added, src_removed; |
| 56 | |
| 57 | struct diff_populate_filespec_options options = { 0 }; |
| 58 | |
| 59 | *merge_score_p = 0; /* assume no deletion --- "do not break" |
| 60 | * is the default. |
| 61 | */ |
| 62 | |
| 63 | if (S_ISREG(src->mode) != S_ISREG(dst->mode)) { |
| 64 | *merge_score_p = (int)MAX_SCORE; |
| 65 | return 1; /* even their types are different */ |
| 66 | } |
| 67 | |
| 68 | if (src->oid_valid && dst->oid_valid && |
| 69 | oideq(&src->oid, &dst->oid)) |
| 70 | return 0; /* they are the same */ |
no test coverage detected