summaryrefslogtreecommitdiff
path: root/builtin/name-rev.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2020-02-04 21:23:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-02-05 18:24:15 (GMT)
commitddc42ec786ab2b64ef70bbd1e456db423dae031e (patch)
treec3bf2f0e6af827f6dc962ccf7ea7290313f44dfd /builtin/name-rev.c
parentf13ca7cef51cc709c645f9da97f09a150bdb2cac (diff)
downloadgit-ddc42ec786ab2b64ef70bbd1e456db423dae031e.zip
git-ddc42ec786ab2b64ef70bbd1e456db423dae031e.tar.gz
git-ddc42ec786ab2b64ef70bbd1e456db423dae031e.tar.bz2
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>
Diffstat (limited to 'builtin/name-rev.c')
-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 14381a3..6701fb1 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 {