@matheusbsbs / matheus-bagliano / commits / 07a7f8debf
Fork 0

format-patch: use 'origin' as start of current-series-range when known

When formatting a patch series over `origin..HEAD`, one would expect that range to be used as the current-series-range when computing a range-diff between the previous and current versions of a patch series. However, infer_range_diff_ranges() ignores `origin..HEAD` when --range-diff=<prev> specifies a single revision rather than a range, and instead unexpectedly computes the current-series-range based upon <prev>. Address this anomaly by unconditionally using `origin..HEAD` as the current-series-range regardless of <prev> as long as `origin` is known, and only fall back to basing current-series-range on <prev> when `origin` is not known. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Sep 8, 2020 at 03:16 UTC 07a7f8debfa43bd28537f475925776a92c30a678
1 file changed +11 -7
builtin/log.c
+11 -7
@@ -1595,16 +1595,20 @@ static void infer_range_diff_ranges(struct strbuf *r1,
1595 struct commit *head)
1596 {
1597 const char *head_oid = oid_to_hex(&head->object.oid);
1598 + int prev_is_range = !!strstr(prev, "..");
1599
1599 - if (!strstr(prev, "..")) {
1600 + if (prev_is_range)
1601 + strbuf_addstr(r1, prev);
1602 + else
1603 strbuf_addf(r1, "%s..%s", head_oid, prev);
1604 +
1605 + if (origin)
1606 + strbuf_addf(r2, "%s..%s", oid_to_hex(&origin->object.oid), head_oid);
1607 + else if (prev_is_range)
1608 + die(_("failed to infer range-diff origin of current series"));
1609 + else {
1610 + warning(_("using '%s' as range-diff origin of current series"), prev);
1611 strbuf_addf(r2, "%s..%s", prev, head_oid);
1602 - } else if (!origin) {
1603 - die(_("failed to infer range-diff ranges"));
1604 - } else {
1605 - strbuf_addstr(r1, prev);
1606 - strbuf_addf(r2, "%s..%s",
1607 - oid_to_hex(&origin->object.oid), head_oid);
1612 }
1613 }
1614