summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar René Scharfe <l.s.r@web.de>2020-02-04 22:23:29 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-02-05 10:24:15 -0800
commitddc42ec786ab2b64ef70bbd1e456db423dae031e (patch)
treec3bf2f0e6af827f6dc962ccf7ea7290313f44dfd
parentname-rev: put struct rev_name into commit slab (diff)
downloadtgif-ddc42ec786ab2b64ef70bbd1e456db423dae031e.tar.xz
name-rev: factor out get_parent_name()
Reduce nesting by moving code to come up with a name for the parent into its own function. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/name-rev.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 14381a3c64..6701fb1569 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -101,6 +101,19 @@ static struct rev_name *create_or_update_name(struct commit *commit,
return name;
}
+static char *get_parent_name(const struct rev_name *name, int parent_number)
+{
+ size_t len;
+
+ strip_suffix(name->tip_name, "^0", &len);
+ if (name->generation > 0)
+ return xstrfmt("%.*s~%d^%d", (int)len, name->tip_name,
+ name->generation, parent_number);
+ else
+ return xstrfmt("%.*s^%d", (int)len, name->tip_name,
+ parent_number);
+}
+
static void name_rev(struct commit *start_commit,
const char *tip_name, timestamp_t taggerdate,
int from_tag, int deref)
@@ -148,19 +161,7 @@ static void name_rev(struct commit *start_commit,
continue;
if (parent_number > 1) {
- size_t len;
-
- strip_suffix(name->tip_name, "^0", &len);
- if (name->generation > 0)
- new_name = xstrfmt("%.*s~%d^%d",
- (int)len,
- name->tip_name,
- name->generation,
- parent_number);
- else
- new_name = xstrfmt("%.*s^%d", (int)len,
- name->tip_name,
- parent_number);
+ new_name = get_parent_name(name, parent_number);
generation = 0;
distance = name->distance + MERGE_TRAVERSAL_WEIGHT;
} else {