зеркало из https://github.com/microsoft/git.git
range-diff: improve the order of the shown commits
This patch lets `git range-diff` use the same order as tbdiff. The idea is simple: for left-to-right readers, it is natural to assume that the `git range-diff` is performed between an older vs a newer version of the branch. As such, the user is probably more interested in the question "where did this come from?" rather than "where did that one go?". To that end, we list the commits in the order of the second commit range ("the newer version"), inserting the unmatched commits of the first commit range as soon as all their predecessors have been shown. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
d9c66f0b5b
Коммит
9dc46e0268
57
range-diff.c
57
range-diff.c
|
@ -12,7 +12,7 @@ struct patch_util {
|
||||||
struct hashmap_entry e;
|
struct hashmap_entry e;
|
||||||
const char *diff, *patch;
|
const char *diff, *patch;
|
||||||
|
|
||||||
int i;
|
int i, shown;
|
||||||
int diffsize;
|
int diffsize;
|
||||||
size_t diff_offset;
|
size_t diff_offset;
|
||||||
/* the index of the matching item in the other branch, or -1 */
|
/* the index of the matching item in the other branch, or -1 */
|
||||||
|
@ -260,28 +260,49 @@ static const char *short_oid(struct patch_util *util)
|
||||||
|
|
||||||
static void output(struct string_list *a, struct string_list *b)
|
static void output(struct string_list *a, struct string_list *b)
|
||||||
{
|
{
|
||||||
int i;
|
int i = 0, j = 0;
|
||||||
|
|
||||||
for (i = 0; i < b->nr; i++) {
|
/*
|
||||||
struct patch_util *util = b->items[i].util, *prev;
|
* We assume the user is really more interested in the second argument
|
||||||
|
* ("newer" version). To that end, we print the output in the order of
|
||||||
|
* the RHS (the `b` parameter). To put the LHS (the `a` parameter)
|
||||||
|
* commits that are no longer in the RHS into a good place, we place
|
||||||
|
* them once we have shown all of their predecessors in the LHS.
|
||||||
|
*/
|
||||||
|
|
||||||
if (util->matching < 0)
|
while (i < a->nr || j < b->nr) {
|
||||||
printf("-: -------- > %d: %s\n",
|
struct patch_util *a_util, *b_util;
|
||||||
i + 1, short_oid(util));
|
a_util = i < a->nr ? a->items[i].util : NULL;
|
||||||
else {
|
b_util = j < b->nr ? b->items[j].util : NULL;
|
||||||
prev = a->items[util->matching].util;
|
|
||||||
printf("%d: %s ! %d: %s\n",
|
|
||||||
util->matching + 1, short_oid(prev),
|
|
||||||
i + 1, short_oid(util));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < a->nr; i++) {
|
/* Skip all the already-shown commits from the LHS. */
|
||||||
struct patch_util *util = a->items[i].util;
|
while (i < a->nr && a_util->shown)
|
||||||
|
a_util = ++i < a->nr ? a->items[i].util : NULL;
|
||||||
|
|
||||||
if (util->matching < 0)
|
/* Show unmatched LHS commit whose predecessors were shown. */
|
||||||
|
if (i < a->nr && a_util->matching < 0) {
|
||||||
printf("%d: %s < -: --------\n",
|
printf("%d: %s < -: --------\n",
|
||||||
i + 1, short_oid(util));
|
i + 1, short_oid(a_util));
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Show unmatched RHS commits. */
|
||||||
|
while (j < b->nr && b_util->matching < 0) {
|
||||||
|
printf("-: -------- > %d: %s\n",
|
||||||
|
j + 1, short_oid(b_util));
|
||||||
|
b_util = ++j < b->nr ? b->items[j].util : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Show matching LHS/RHS pair. */
|
||||||
|
if (j < b->nr) {
|
||||||
|
a_util = a->items[b_util->matching].util;
|
||||||
|
printf("%d: %s ! %d: %s\n",
|
||||||
|
b_util->matching + 1, short_oid(a_util),
|
||||||
|
j + 1, short_oid(b_util));
|
||||||
|
a_util->shown = 1;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче