data/MergePlan.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "MergePlan.h" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | |||
| 5 | namespace Merge { | ||
| 6 | |||
| 7 | namespace { | ||
| 8 | |||
| 9 | 391 | TextMerge::Pick pickOf(Choice choice) { | |
| 10 |
4/6✓ Branch 2 → 3 taken 262 times.
✓ Branch 2 → 4 taken 126 times.
✓ Branch 2 → 5 taken 2 times.
✗ Branch 2 → 6 not taken.
✓ Branch 2 → 7 taken 1 time.
✗ Branch 2 → 8 not taken.
|
391 | switch (choice) { |
| 11 | 262 | case Choice::Local: | |
| 12 | 262 | return TextMerge::Pick::Local; | |
| 13 | 126 | case Choice::Server: | |
| 14 | 126 | return TextMerge::Pick::Server; | |
| 15 | 2 | case Choice::Both: | |
| 16 | 2 | return TextMerge::Pick::Both; | |
| 17 | ✗ | case Choice::Base: | |
| 18 | ✗ | return TextMerge::Pick::Base; | |
| 19 | 1 | case Choice::None: | |
| 20 | case Choice::Edited: | ||
| 21 | 1 | break; | |
| 22 | } | ||
| 23 | 1 | return TextMerge::Pick::Open; | |
| 24 | } | ||
| 25 | |||
| 26 | 742 | Choice choiceOf(TextMerge::Pick pick) { | |
| 27 |
3/6✓ Branch 2 → 3 taken 511 times.
✓ Branch 2 → 4 taken 177 times.
✗ Branch 2 → 5 not taken.
✗ Branch 2 → 6 not taken.
✓ Branch 2 → 7 taken 54 times.
✗ Branch 2 → 8 not taken.
|
742 | switch (pick) { |
| 28 | 511 | case TextMerge::Pick::Local: | |
| 29 | 511 | return Choice::Local; | |
| 30 | 177 | case TextMerge::Pick::Server: | |
| 31 | 177 | return Choice::Server; | |
| 32 | ✗ | case TextMerge::Pick::Both: | |
| 33 | ✗ | return Choice::Both; | |
| 34 | ✗ | case TextMerge::Pick::Base: | |
| 35 | ✗ | return Choice::Base; | |
| 36 | 54 | case TextMerge::Pick::Open: | |
| 37 | 54 | break; | |
| 38 | } | ||
| 39 | 54 | return Choice::None; | |
| 40 | } | ||
| 41 | |||
| 42 | 129 | QList<TextMerge::Pick> picksOf(const Item &item) { | |
| 43 | 129 | QList<TextMerge::Pick> picks; | |
| 44 |
2/2✓ Branch 9 → 4 taken 391 times.
✓ Branch 9 → 10 taken 129 times.
|
520 | for (const Choice choice : item.hunkChoices) |
| 45 |
1/1✓ Branch 6 → 7 taken 391 times.
|
391 | picks.append(pickOf(choice)); |
| 46 | 129 | return picks; | |
| 47 | ✗ | } | |
| 48 | |||
| 49 | 1410 | bool offers(const Item &item, Choice choice) { | |
| 50 |
3/6✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 1408 times.
✓ Branch 2 → 5 taken 1 time.
✗ Branch 2 → 11 not taken.
✗ Branch 2 → 12 not taken.
✗ Branch 2 → 13 not taken.
|
1410 | switch (choice) { |
| 51 | 1 | case Choice::None: | |
| 52 | 1 | return false; | |
| 53 | 1408 | case Choice::Local: | |
| 54 | case Choice::Server: | ||
| 55 | 1408 | return true; | |
| 56 | 1 | case Choice::Base: | |
| 57 |
1/6✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 1 time.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
|
1 | return item.base.present || item.kind == Kind::SetValue || item.kind == Kind::Component; |
| 58 | ✗ | case Choice::Both: | |
| 59 | ✗ | return false; // set values are kept or not; text "both" is per hunk | |
| 60 | ✗ | case Choice::Edited: | |
| 61 | ✗ | return item.kind == Kind::Text; | |
| 62 | } | ||
| 63 | ✗ | return false; | |
| 64 | } | ||
| 65 | |||
| 66 | 292 | void resetHunks(Item *item) { | |
| 67 | 292 | item->hunkChoices.clear(); | |
| 68 |
5/5✓ Branch 3 → 4 taken 292 times.
✓ Branch 4 → 5 taken 292 times.
✓ Branch 5 → 6 taken 292 times.
✓ Branch 12 → 7 taken 742 times.
✓ Branch 12 → 13 taken 292 times.
|
1034 | for (const TextMerge::Pick pick : TextMerge::defaultPicks(item->hunks)) |
| 69 |
1/1✓ Branch 9 → 10 taken 742 times.
|
1034 | item->hunkChoices.append(choiceOf(pick)); |
| 70 | 292 | item->edited = QString(); | |
| 71 | 292 | } | |
| 72 | |||
| 73 | } // namespace | ||
| 74 | |||
| 75 | 1638 | int Plan::indexOf(const QString &id) const { | |
| 76 |
2/2✓ Branch 9 → 3 taken 18153 times.
✓ Branch 9 → 10 taken 171 times.
|
18324 | for (int index = 0; index < items.size(); ++index) |
| 77 |
2/2✓ Branch 5 → 6 taken 1467 times.
✓ Branch 5 → 7 taken 16686 times.
|
18153 | if (items.at(index).id == id) |
| 78 | 1467 | return index; | |
| 79 | 171 | return -1; | |
| 80 | } | ||
| 81 | |||
| 82 | 1121 | const Item *Plan::item(const QString &id) const { | |
| 83 | 1121 | const int index = indexOf(id); | |
| 84 |
2/2✓ Branch 3 → 4 taken 963 times.
✓ Branch 3 → 5 taken 158 times.
|
1121 | return index < 0 ? nullptr : &items.at(index); |
| 85 | } | ||
| 86 | |||
| 87 | 59673 | bool itemOpen(const Plan &plan, const Item &item) { | |
| 88 | Q_UNUSED(plan); | ||
| 89 |
2/2✓ Branch 2 → 3 taken 1027 times.
✓ Branch 2 → 4 taken 58646 times.
|
59673 | if (item.choice == Choice::None) |
| 90 | 1027 | return item.state == State::Conflict; | |
| 91 |
8/8✓ Branch 4 → 5 taken 291 times.
✓ Branch 4 → 9 taken 58355 times.
✓ Branch 5 → 6 taken 107 times.
✓ Branch 5 → 9 taken 184 times.
✓ Branch 7 → 8 taken 95 times.
✓ Branch 7 → 9 taken 12 times.
✓ Branch 10 → 11 taken 95 times.
✓ Branch 10 → 16 taken 58551 times.
|
58646 | if (item.kind == Kind::Text && item.choice == Choice::Edited && item.edited.isNull()) { |
| 92 | 95 | bool open = false; | |
| 93 |
2/2✓ Branch 11 → 12 taken 95 times.
✓ Branch 12 → 13 taken 95 times.
|
95 | TextMerge::apply(item.hunks, picksOf(item), &open); |
| 94 | 95 | return open; | |
| 95 | } | ||
| 96 | 58551 | return false; | |
| 97 | } | ||
| 98 | |||
| 99 | 5444 | int Plan::openConflicts() const { | |
| 100 | 5444 | QStringList countedGroups; | |
| 101 | 5444 | int open = 0; | |
| 102 |
2/2✓ Branch 38 → 4 taken 29461 times.
✓ Branch 38 → 39 taken 5444 times.
|
34905 | for (const Item &entry : items) { |
| 103 |
3/3✓ Branch 5 → 6 taken 29461 times.
✓ Branch 6 → 7 taken 28805 times.
✓ Branch 6 → 8 taken 656 times.
|
29461 | if (!itemOpen(*this, entry)) |
| 104 | 28805 | continue; | |
| 105 |
6/6✓ Branch 9 → 10 taken 471 times.
✓ Branch 9 → 13 taken 185 times.
✓ Branch 11 → 12 taken 378 times.
✓ Branch 11 → 13 taken 93 times.
✓ Branch 14 → 15 taken 378 times.
✓ Branch 14 → 35 taken 278 times.
|
656 | if (!entry.group.isEmpty() && !groupSeparated(entry.group)) { |
| 106 |
5/5✓ Branch 17 → 18 taken 378 times.
✓ Branch 18 → 19 taken 20 times.
✓ Branch 18 → 20 taken 358 times.
✓ Branch 21 → 22 taken 378 times.
✓ Branch 22 → 23 taken 378 times.
|
378 | const QString key = (Plan::crossParentGroup(entry.group) ? QString() : entry.parent) + QLatin1Char('\n') + entry.group; |
| 107 |
2/2✓ Branch 26 → 27 taken 188 times.
✓ Branch 26 → 28 taken 190 times.
|
378 | if (countedGroups.contains(key)) |
| 108 | 188 | continue; | |
| 109 |
1/1✓ Branch 28 → 29 taken 190 times.
|
190 | countedGroups.append(key); |
| 110 | 378 | } | |
| 111 | 468 | ++open; | |
| 112 | } | ||
| 113 | 5444 | return open; | |
| 114 | 5444 | } | |
| 115 | |||
| 116 | 11 | int Plan::combinedCount() const { | |
| 117 | 11 | return int(std::count_if(items.cbegin(), items.cend(), [](const Item &entry) { | |
| 118 |
5/6✓ Branch 2 → 3 taken 31 times.
✓ Branch 2 → 5 taken 1 time.
✓ Branch 3 → 4 taken 23 times.
✓ Branch 3 → 5 taken 8 times.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 23 times.
|
32 | return entry.state == State::LocalOnly || entry.state == State::ServerOnly || entry.state == State::BothSame; |
| 119 | 11 | })); | |
| 120 | } | ||
| 121 | |||
| 122 | 15 | int Plan::conflictCount() const { | |
| 123 | 15 | return int(std::count_if(items.cbegin(), items.cend(), | |
| 124 | 69 | [](const Item &entry) { return entry.state == State::Conflict; })); | |
| 125 | } | ||
| 126 | |||
| 127 | 39226 | Choice defaultChoice(State state) { | |
| 128 |
3/4✓ Branch 2 → 3 taken 533 times.
✓ Branch 2 → 4 taken 643 times.
✓ Branch 2 → 5 taken 38050 times.
✗ Branch 2 → 6 not taken.
|
39226 | switch (state) { |
| 129 | 533 | case State::ServerOnly: | |
| 130 | 533 | return Choice::Server; | |
| 131 | 643 | case State::Conflict: | |
| 132 | 643 | return Choice::None; | |
| 133 | 38050 | case State::Same: | |
| 134 | case State::LocalOnly: | ||
| 135 | case State::BothSame: | ||
| 136 | 38050 | break; | |
| 137 | } | ||
| 138 | 38050 | return Choice::Local; | |
| 139 | } | ||
| 140 | |||
| 141 | 531 | State stateOf(const Value &base, const Value &local, const Value &server) { | |
| 142 | 1166 | const auto same = [](const Value &a, const Value &b) { | |
| 143 |
6/6✓ Branch 2 → 3 taken 919 times.
✓ Branch 2 → 7 taken 247 times.
✓ Branch 3 → 4 taken 704 times.
✓ Branch 3 → 6 taken 215 times.
✓ Branch 5 → 6 taken 384 times.
✓ Branch 5 → 7 taken 320 times.
|
1166 | return a.present == b.present && (!a.present || a.text == b.text); |
| 144 | }; | ||
| 145 | 531 | const bool localChanged = !same(local, base); | |
| 146 | 531 | const bool serverChanged = !same(server, base); | |
| 147 |
4/4✓ Branch 4 → 5 taken 317 times.
✓ Branch 4 → 7 taken 214 times.
✓ Branch 5 → 6 taken 162 times.
✓ Branch 5 → 7 taken 155 times.
|
531 | if (!localChanged && !serverChanged) |
| 148 | 162 | return State::Same; | |
| 149 |
2/2✓ Branch 7 → 8 taken 110 times.
✓ Branch 7 → 9 taken 259 times.
|
369 | if (!serverChanged) |
| 150 | 110 | return State::LocalOnly; | |
| 151 |
2/2✓ Branch 9 → 10 taken 155 times.
✓ Branch 9 → 11 taken 104 times.
|
259 | if (!localChanged) |
| 152 | 155 | return State::ServerOnly; | |
| 153 |
2/2✓ Branch 12 → 13 taken 10 times.
✓ Branch 12 → 14 taken 94 times.
|
104 | return same(local, server) ? State::BothSame : State::Conflict; |
| 154 | } | ||
| 155 | |||
| 156 | 948 | void applyDefaults(Plan *plan) { | |
| 157 |
4/4✓ Branch 2 → 3 taken 948 times.
✓ Branch 3 → 4 taken 948 times.
✓ Branch 11 → 5 taken 39221 times.
✓ Branch 11 → 12 taken 948 times.
|
40169 | for (Item &entry : plan->items) { |
| 158 | 39221 | entry.choice = defaultChoice(entry.state); | |
| 159 | 39221 | entry.touched = false; | |
| 160 |
2/2✓ Branch 7 → 8 taken 233 times.
✓ Branch 7 → 9 taken 38988 times.
|
39221 | if (entry.kind == Kind::Text) |
| 161 |
1/1✓ Branch 8 → 9 taken 233 times.
|
233 | resetHunks(&entry); |
| 162 | } | ||
| 163 | 948 | } | |
| 164 | |||
| 165 | 436 | bool choose(Plan *plan, const QString &id, Choice choice) { | |
| 166 | 436 | const int index = plan->indexOf(id); | |
| 167 |
6/6✓ Branch 3 → 4 taken 435 times.
✓ Branch 3 → 7 taken 1 time.
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 434 times.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 11 taken 434 times.
|
436 | if (index < 0 || !offers(plan->items.at(index), choice)) |
| 168 | 2 | return false; | |
| 169 |
1/1✓ Branch 11 → 12 taken 434 times.
|
434 | Item &target = plan->items[index]; |
| 170 | 434 | const QString group = target.group; | |
| 171 | 434 | const QString parent = target.parent; | |
| 172 | 594 | const auto set = [choice](Item *entry) { | |
| 173 | 594 | entry->choice = choice; | |
| 174 | 594 | entry->touched = true; | |
| 175 |
3/4✓ Branch 2 → 3 taken 22 times.
✓ Branch 2 → 5 taken 572 times.
✓ Branch 3 → 4 taken 22 times.
✗ Branch 3 → 5 not taken.
|
594 | if (entry->kind == Kind::Text && choice != Choice::Edited) |
| 176 | 22 | resetHunks(entry); | |
| 177 | 1028 | }; | |
| 178 |
6/6✓ Branch 15 → 16 taken 191 times.
✓ Branch 15 → 18 taken 243 times.
✓ Branch 17 → 18 taken 32 times.
✓ Branch 17 → 19 taken 159 times.
✓ Branch 20 → 21 taken 275 times.
✓ Branch 20 → 23 taken 159 times.
|
434 | if (group.isEmpty() || plan->groupSeparated(group)) { |
| 179 |
1/1✓ Branch 21 → 22 taken 275 times.
|
275 | set(&target); |
| 180 | 275 | return true; | |
| 181 | } | ||
| 182 |
4/4✓ Branch 23 → 24 taken 159 times.
✓ Branch 24 → 25 taken 159 times.
✓ Branch 41 → 26 taken 823 times.
✓ Branch 41 → 42 taken 159 times.
|
982 | for (Item &member : plan->items) |
| 183 |
10/11✓ Branch 28 → 29 taken 327 times.
✓ Branch 28 → 36 taken 496 times.
✓ Branch 30 → 31 taken 14 times.
✓ Branch 30 → 33 taken 313 times.
✓ Branch 31 → 32 taken 14 times.
✓ Branch 32 → 33 taken 6 times.
✓ Branch 32 → 36 taken 8 times.
✓ Branch 34 → 35 taken 319 times.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 319 times.
✓ Branch 37 → 39 taken 504 times.
|
823 | if (member.group == group && (member.parent == parent || Plan::crossParentGroup(group)) && offers(member, choice)) |
| 184 |
1/1✓ Branch 38 → 39 taken 319 times.
|
319 | set(&member); |
| 185 | 159 | return true; | |
| 186 | 434 | } | |
| 187 | |||
| 188 | 151 | void chooseAll(Plan *plan, Choice side) { | |
| 189 |
4/4✓ Branch 2 → 3 taken 151 times.
✓ Branch 3 → 4 taken 151 times.
✓ Branch 13 → 5 taken 656 times.
✓ Branch 13 → 14 taken 151 times.
|
807 | for (Item &entry : plan->items) { |
| 190 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 656 times.
|
656 | if (!offers(entry, side)) |
| 191 | ✗ | continue; | |
| 192 | 656 | entry.choice = side; | |
| 193 | 656 | entry.touched = true; | |
| 194 |
2/2✓ Branch 9 → 10 taken 27 times.
✓ Branch 9 → 11 taken 629 times.
|
656 | if (entry.kind == Kind::Text) |
| 195 |
1/1✓ Branch 10 → 11 taken 27 times.
|
27 | resetHunks(&entry); |
| 196 | } | ||
| 197 | 151 | } | |
| 198 | |||
| 199 | 14 | bool chooseHunk(Plan *plan, const QString &id, int hunk, Choice choice) { | |
| 200 | 14 | const int index = plan->indexOf(id); | |
| 201 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 14 times.
|
14 | if (index < 0) |
| 202 | ✗ | return false; | |
| 203 | 14 | Item &entry = plan->items[index]; | |
| 204 |
8/10✓ Branch 6 → 7 taken 13 times.
✓ Branch 6 → 11 taken 1 time.
✓ Branch 7 → 8 taken 13 times.
✗ Branch 7 → 11 not taken.
✓ Branch 9 → 10 taken 11 times.
✓ Branch 9 → 11 taken 2 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 11 times.
✓ Branch 13 → 14 taken 3 times.
✓ Branch 13 → 15 taken 11 times.
|
14 | if (entry.kind != Kind::Text || hunk < 0 || hunk >= entry.hunks.hunks.size() || choice == Choice::Edited) |
| 205 | 3 | return false; | |
| 206 |
5/6✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 18 taken 10 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1 time.
✓ Branch 20 → 21 taken 10 times.
✓ Branch 20 → 23 taken 1 time.
|
11 | if (entry.choice != Choice::Edited || !entry.edited.isNull()) { |
| 207 | // Switching from a whole side (or a typed text) to hunk choices starts | ||
| 208 | // from the defaults: the user's earlier whole-side pick is not a hunk. | ||
| 209 | 10 | resetHunks(&entry); | |
| 210 | 10 | entry.choice = Choice::Edited; | |
| 211 | } | ||
| 212 |
1/2✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 11 times.
|
11 | if (entry.hunkChoices.size() != entry.hunks.hunks.size()) |
| 213 | ✗ | resetHunks(&entry); | |
| 214 | 11 | entry.hunkChoices[hunk] = choice; | |
| 215 | 11 | entry.touched = true; | |
| 216 | 11 | return true; | |
| 217 | } | ||
| 218 | |||
| 219 | 8 | bool editText(Plan *plan, const QString &id, const QString &text) { | |
| 220 | 8 | const int index = plan->indexOf(id); | |
| 221 |
5/6✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 6 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 7 times.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 10 taken 7 times.
|
8 | if (index < 0 || plan->items.at(index).kind != Kind::Text) |
| 222 | 1 | return false; | |
| 223 | 7 | Item &entry = plan->items[index]; | |
| 224 | 7 | entry.choice = Choice::Edited; | |
| 225 |
2/4✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 7 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 7 times.
|
7 | entry.edited = text.isNull() ? QStringLiteral("") : text; |
| 226 | 7 | entry.touched = true; | |
| 227 | 7 | return true; | |
| 228 | } | ||
| 229 | |||
| 230 | 1680 | QString resultText(const Item &item, bool *present) { | |
| 231 | 1635 | const auto from = [present](const Value &value) { | |
| 232 |
2/2✓ Branch 2 → 3 taken 1624 times.
✓ Branch 2 → 4 taken 11 times.
|
1635 | if (present) |
| 233 | 1624 | *present = value.present; | |
| 234 | 1635 | return value.text; | |
| 235 | 1680 | }; | |
| 236 |
3/5✓ Branch 2 → 3 taken 753 times.
✗ Branch 2 → 4 not taken.
✓ Branch 2 → 5 taken 45 times.
✓ Branch 2 → 15 taken 882 times.
✗ Branch 2 → 16 not taken.
|
1680 | switch (item.choice) { |
| 237 | 753 | case Choice::Server: | |
| 238 | 753 | return from(item.server); | |
| 239 | ✗ | case Choice::Base: | |
| 240 | ✗ | return from(item.base); | |
| 241 | 45 | case Choice::Edited: | |
| 242 |
2/2✓ Branch 5 → 6 taken 12 times.
✓ Branch 5 → 7 taken 33 times.
|
45 | if (present) |
| 243 | 12 | *present = true; | |
| 244 |
2/2✓ Branch 8 → 9 taken 11 times.
✓ Branch 8 → 10 taken 34 times.
|
45 | if (!item.edited.isNull()) |
| 245 | 11 | return item.edited; | |
| 246 |
2/2✓ Branch 10 → 11 taken 34 times.
✓ Branch 11 → 12 taken 34 times.
|
34 | return TextMerge::apply(item.hunks, picksOf(item)); |
| 247 | 882 | case Choice::Both: | |
| 248 | case Choice::None: | ||
| 249 | case Choice::Local: | ||
| 250 | 882 | break; | |
| 251 | } | ||
| 252 | 882 | return from(item.local); | |
| 253 | } | ||
| 254 | |||
| 255 | 179 | Choice uniformSide(const Plan &plan) { | |
| 256 | 179 | bool allLocal = true; | |
| 257 | 179 | bool allServer = true; | |
| 258 |
2/2✓ Branch 26 → 4 taken 773 times.
✓ Branch 26 → 27 taken 178 times.
|
951 | for (const Item &entry : plan.items) { |
| 259 |
3/3✓ Branch 5 → 6 taken 773 times.
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 772 times.
|
773 | if (itemOpen(plan, entry)) |
| 260 | 1 | return Choice::None; | |
| 261 | 772 | bool present = false; | |
| 262 |
1/1✓ Branch 8 → 9 taken 772 times.
|
772 | const QString text = resultText(entry, &present); |
| 263 |
4/4✓ Branch 9 → 10 taken 34 times.
✓ Branch 9 → 12 taken 738 times.
✓ Branch 10 → 11 taken 6 times.
✓ Branch 10 → 12 taken 28 times.
|
772 | const bool plain = entry.kind == Kind::Text && entry.choice == Choice::Edited; |
| 264 | 1139 | const auto equals = [&](const Value &value, const QString &valuePlain) { | |
| 265 |
8/8✓ Branch 2 → 3 taken 1080 times.
✓ Branch 2 → 10 taken 59 times.
✓ Branch 3 → 4 taken 1015 times.
✓ Branch 3 → 9 taken 65 times.
✓ Branch 4 → 5 taken 12 times.
✓ Branch 4 → 6 taken 1003 times.
✓ Branch 8 → 9 taken 882 times.
✓ Branch 8 → 10 taken 133 times.
|
1139 | return value.present == present && (!present || (plain ? valuePlain : value.text) == text); |
| 266 | 772 | }; | |
| 267 |
4/4✓ Branch 13 → 14 taken 573 times.
✓ Branch 13 → 17 taken 199 times.
✓ Branch 15 → 16 taken 475 times.
✓ Branch 15 → 17 taken 98 times.
|
772 | allLocal = allLocal && equals(entry.local, entry.localPlain); |
| 268 |
4/4✓ Branch 18 → 19 taken 566 times.
✓ Branch 18 → 22 taken 206 times.
✓ Branch 20 → 21 taken 472 times.
✓ Branch 20 → 22 taken 94 times.
|
772 | allServer = allServer && equals(entry.server, entry.serverPlain); |
| 269 | 772 | } | |
| 270 |
2/2✓ Branch 27 → 28 taken 80 times.
✓ Branch 27 → 29 taken 98 times.
|
178 | if (allLocal) |
| 271 | 80 | return Choice::Local; | |
| 272 |
2/2✓ Branch 29 → 30 taken 78 times.
✓ Branch 29 → 31 taken 20 times.
|
98 | return allServer ? Choice::Server : Choice::None; |
| 273 | } | ||
| 274 | |||
| 275 | 9 | int carryChoices(const Plan &previous, Plan *next) { | |
| 276 | 9 | int carried = 0; | |
| 277 |
4/4✓ Branch 2 → 3 taken 9 times.
✓ Branch 3 → 4 taken 9 times.
✓ Branch 31 → 5 taken 37 times.
✓ Branch 31 → 32 taken 9 times.
|
46 | for (Item &entry : next->items) { |
| 278 | 37 | const Item *old = previous.item(entry.id); | |
| 279 |
4/4✓ Branch 7 → 8 taken 36 times.
✓ Branch 7 → 9 taken 1 time.
✓ Branch 8 → 9 taken 21 times.
✓ Branch 8 → 10 taken 15 times.
|
37 | if (!old || !old->touched) |
| 280 | 24 | continue; | |
| 281 |
3/4✓ Branch 2 → 3 taken 30 times.
✗ Branch 2 → 6 not taken.
✓ Branch 4 → 5 taken 28 times.
✓ Branch 4 → 6 taken 2 times.
|
30 | const auto same = [](const Value &a, const Value &b) { return a.present == b.present && a.text == b.text; }; |
| 282 |
5/6✓ Branch 11 → 12 taken 15 times.
✗ Branch 11 → 14 not taken.
✓ Branch 13 → 14 taken 2 times.
✓ Branch 13 → 15 taken 13 times.
✓ Branch 16 → 17 taken 2 times.
✓ Branch 16 → 18 taken 13 times.
|
15 | if (!same(old->local, entry.local) || !same(old->server, entry.server)) |
| 283 | 2 | continue; | |
| 284 | 13 | entry.choice = old->choice; | |
| 285 | 13 | entry.edited = old->edited; | |
| 286 |
2/6✗ Branch 19 → 20 not taken.
✓ Branch 19 → 24 taken 13 times.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 13 times.
|
13 | if (entry.kind == Kind::Text && old->hunkChoices.size() == entry.hunks.hunks.size()) |
| 287 | ✗ | entry.hunkChoices = old->hunkChoices; | |
| 288 | 13 | entry.touched = true; | |
| 289 | 13 | ++carried; | |
| 290 | } | ||
| 291 |
2/2✓ Branch 40 → 34 taken 4 times.
✓ Branch 40 → 41 taken 9 times.
|
13 | for (const QString &group : previous.separatedGroups) |
| 292 |
1/2✓ Branch 36 → 37 taken 4 times.
✗ Branch 36 → 38 not taken.
|
4 | if (!next->separatedGroups.contains(group)) |
| 293 |
1/1✓ Branch 37 → 38 taken 4 times.
|
4 | next->separatedGroups.append(group); |
| 294 | 9 | return carried; | |
| 295 | } | ||
| 296 | |||
| 297 | ✗ | const char *kindName(Kind kind) { | |
| 298 | ✗ | switch (kind) { | |
| 299 | ✗ | case Kind::Scalar: | |
| 300 | ✗ | return "scalar"; | |
| 301 | ✗ | case Kind::SetValue: | |
| 302 | ✗ | return "set"; | |
| 303 | ✗ | case Kind::Text: | |
| 304 | ✗ | return "text"; | |
| 305 | ✗ | case Kind::Component: | |
| 306 | ✗ | return "component"; | |
| 307 | ✗ | case Kind::Order: | |
| 308 | ✗ | return "order"; | |
| 309 | ✗ | case Kind::Deletion: | |
| 310 | ✗ | return "deletion"; | |
| 311 | } | ||
| 312 | ✗ | return "scalar"; | |
| 313 | } | ||
| 314 | |||
| 315 | 349 | const char *stateName(State state) { | |
| 316 |
5/6✓ Branch 2 → 3 taken 69 times.
✓ Branch 2 → 4 taken 126 times.
✓ Branch 2 → 5 taken 127 times.
✓ Branch 2 → 6 taken 20 times.
✓ Branch 2 → 7 taken 7 times.
✗ Branch 2 → 8 not taken.
|
349 | switch (state) { |
| 317 | 69 | case State::Same: | |
| 318 | 69 | return "same"; | |
| 319 | 126 | case State::LocalOnly: | |
| 320 | 126 | return "local"; | |
| 321 | 127 | case State::ServerOnly: | |
| 322 | 127 | return "server"; | |
| 323 | 20 | case State::BothSame: | |
| 324 | 20 | return "both-same"; | |
| 325 | 7 | case State::Conflict: | |
| 326 | 7 | return "conflict"; | |
| 327 | } | ||
| 328 | ✗ | return "same"; | |
| 329 | } | ||
| 330 | |||
| 331 | 2732 | const char *choiceName(Choice choice) { | |
| 332 |
5/7✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 1527 times.
✓ Branch 2 → 5 taken 1179 times.
✓ Branch 2 → 6 taken 7 times.
✓ Branch 2 → 7 taken 10 times.
✓ Branch 2 → 8 taken 9 times.
✗ Branch 2 → 9 not taken.
|
2732 | switch (choice) { |
| 333 | ✗ | case Choice::None: | |
| 334 | ✗ | return "none"; | |
| 335 | 1527 | case Choice::Local: | |
| 336 | 1527 | return "local"; | |
| 337 | 1179 | case Choice::Server: | |
| 338 | 1179 | return "server"; | |
| 339 | 7 | case Choice::Both: | |
| 340 | 7 | return "both"; | |
| 341 | 10 | case Choice::Base: | |
| 342 | 10 | return "base"; | |
| 343 | 9 | case Choice::Edited: | |
| 344 | 9 | return "edited"; | |
| 345 | } | ||
| 346 | ✗ | return "none"; | |
| 347 | } | ||
| 348 | |||
| 349 | 633 | Choice choiceFromName(const QString &name) { | |
| 350 |
2/2✓ Branch 10 → 4 taken 967 times.
✓ Branch 10 → 11 taken 1 time.
|
968 | for (const Choice choice : {Choice::Local, Choice::Server, Choice::Both, Choice::Base, Choice::Edited}) |
| 351 |
2/2✓ Branch 7 → 8 taken 632 times.
✓ Branch 7 → 9 taken 335 times.
|
967 | if (name == QLatin1String(choiceName(choice))) |
| 352 | 632 | return choice; | |
| 353 | 1 | return Choice::None; | |
| 354 | } | ||
| 355 | |||
| 356 | } // namespace Merge | ||
| 357 |