| 129 | } |
| 130 | |
| 131 | void diffcore_break(struct repository *r, int break_score) |
| 132 | { |
| 133 | struct diff_queue_struct *q = &diff_queued_diff; |
| 134 | struct diff_queue_struct outq = DIFF_QUEUE_INIT; |
| 135 | |
| 136 | /* When the filepair has this much edit (insert and delete), |
| 137 | * it is first considered to be a rewrite and broken into a |
| 138 | * create and delete filepair. This is to help breaking a |
| 139 | * file that had too much new stuff added, possibly from |
| 140 | * moving contents from another file, so that rename/copy can |
| 141 | * match it with the other file. |
| 142 | * |
| 143 | * int break_score; we reuse incoming parameter for this. |
| 144 | */ |
| 145 | |
| 146 | /* After a pair is broken according to break_score and |
| 147 | * subjected to rename/copy, both of them may survive intact, |
| 148 | * due to lack of suitable rename/copy peer. Or, the caller |
| 149 | * may be calling us without using rename/copy. When that |
| 150 | * happens, we merge the broken pieces back into one |
| 151 | * modification together if the pair did not have more than |
| 152 | * this much delete. For this computation, we do not take |
| 153 | * insert into account at all. If you start from a 100-line |
| 154 | * file and delete 97 lines of it, it does not matter if you |
| 155 | * add 27 lines to it to make a new 30-line file or if you add |
| 156 | * 997 lines to it to make a 1000-line file. Either way what |
| 157 | * you did was a rewrite of 97%. On the other hand, if you |
| 158 | * delete 3 lines, keeping 97 lines intact, it does not matter |
| 159 | * if you add 3 lines to it to make a new 100-line file or if |
| 160 | * you add 903 lines to it to make a new 1000-line file. |
| 161 | * Either way you did a lot of additions and not a rewrite. |
| 162 | * This merge happens to catch the latter case. A merge_score |
| 163 | * of 80% would be a good default value (a broken pair that |
| 164 | * has score lower than merge_score will be merged back |
| 165 | * together). |
| 166 | */ |
| 167 | int merge_score; |
| 168 | int i; |
| 169 | |
| 170 | /* See comment on DEFAULT_BREAK_SCORE and |
| 171 | * DEFAULT_MERGE_SCORE in diffcore.h |
| 172 | */ |
| 173 | merge_score = (break_score >> 16) & 0xFFFF; |
| 174 | break_score = (break_score & 0xFFFF); |
| 175 | |
| 176 | if (!break_score) |
| 177 | break_score = DEFAULT_BREAK_SCORE; |
| 178 | if (!merge_score) |
| 179 | merge_score = DEFAULT_MERGE_SCORE; |
| 180 | |
| 181 | for (i = 0; i < q->nr; i++) { |
| 182 | struct diff_filepair *p = q->queue[i]; |
| 183 | int score; |
| 184 | |
| 185 | /* |
| 186 | * We deal only with in-place edit of blobs. |
| 187 | * We do not break anything else. |
| 188 | */ |
no test coverage detected