/src/git/diffcore-rotate.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2021, Google LLC. |
3 | | * Based on diffcore-order.c, which is Copyright (C) 2005, Junio C Hamano |
4 | | */ |
5 | | #include "git-compat-util.h" |
6 | | #include "gettext.h" |
7 | | #include "diff.h" |
8 | | #include "diffcore.h" |
9 | | |
10 | | void diffcore_rotate(struct diff_options *opt) |
11 | 0 | { |
12 | 0 | struct diff_queue_struct *q = &diff_queued_diff; |
13 | 0 | struct diff_queue_struct outq; |
14 | 0 | int rotate_to, i; |
15 | |
|
16 | 0 | if (!q->nr) |
17 | 0 | return; |
18 | | |
19 | 0 | for (i = 0; i < q->nr; i++) { |
20 | 0 | int cmp = strcmp(opt->rotate_to, q->queue[i]->two->path); |
21 | 0 | if (!cmp) |
22 | 0 | break; /* exact match */ |
23 | 0 | if (!opt->rotate_to_strict && cmp < 0) |
24 | 0 | break; /* q->queue[i] is now past the target pathname */ |
25 | 0 | } |
26 | |
|
27 | 0 | if (q->nr <= i) { |
28 | | /* we did not find the specified path */ |
29 | 0 | if (opt->rotate_to_strict) |
30 | 0 | die(_("No such path '%s' in the diff"), opt->rotate_to); |
31 | 0 | return; |
32 | 0 | } |
33 | | |
34 | 0 | DIFF_QUEUE_CLEAR(&outq); |
35 | 0 | rotate_to = i; |
36 | |
|
37 | 0 | for (i = rotate_to; i < q->nr; i++) |
38 | 0 | diff_q(&outq, q->queue[i]); |
39 | 0 | for (i = 0; i < rotate_to; i++) { |
40 | 0 | if (opt->skip_instead_of_rotate) |
41 | 0 | diff_free_filepair(q->queue[i]); |
42 | 0 | else |
43 | 0 | diff_q(&outq, q->queue[i]); |
44 | 0 | } |
45 | 0 | free(q->queue); |
46 | 0 | *q = outq; |
47 | 0 | } |