summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorSZEDER Gábor <szeder.dev@gmail.com>2019-11-12 10:38:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-12-06 21:29:04 (GMT)
commit766f9e39c007f527c5ab63d65a0d8ff9d36e2a2e (patch)
tree9d8507e79dac4db5d0b62b94716f3dae06ece41e /builtin
parentd59fc8369703eda30e02943d0e4884df90061af8 (diff)
downloadgit-766f9e39c007f527c5ab63d65a0d8ff9d36e2a2e.zip
git-766f9e39c007f527c5ab63d65a0d8ff9d36e2a2e.tar.gz
git-766f9e39c007f527c5ab63d65a0d8ff9d36e2a2e.tar.bz2
name-rev: extract creating/updating a 'struct name_rev' into a helper
In a later patch in this series we'll want to do this in two places. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/name-rev.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 7e003c2..e43df19 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -79,12 +79,36 @@ static int is_better_name(struct rev_name *name,
return 0;
}
+static struct rev_name *create_or_update_name(struct commit *commit,
+ const char *tip_name,
+ timestamp_t taggerdate,
+ int generation, int distance,
+ int from_tag)
+{
+ struct rev_name *name = get_commit_rev_name(commit);
+
+ if (name == NULL) {
+ name = xmalloc(sizeof(*name));
+ set_commit_rev_name(commit, name);
+ goto copy_data;
+ } else if (is_better_name(name, taggerdate, distance, from_tag)) {
+copy_data:
+ name->tip_name = tip_name;
+ name->taggerdate = taggerdate;
+ name->generation = generation;
+ name->distance = distance;
+ name->from_tag = from_tag;
+
+ return name;
+ } else
+ return NULL;
+}
+
static void name_rev(struct commit *commit,
const char *tip_name, timestamp_t taggerdate,
int generation, int distance, int from_tag,
int deref)
{
- struct rev_name *name = get_commit_rev_name(commit);
struct commit_list *parents;
int parent_number = 1;
char *to_free = NULL;
@@ -101,18 +125,8 @@ static void name_rev(struct commit *commit,
die("generation: %d, but deref?", generation);
}
- if (name == NULL) {
- name = xmalloc(sizeof(*name));
- set_commit_rev_name(commit, name);
- goto copy_data;
- } else if (is_better_name(name, taggerdate, distance, from_tag)) {
-copy_data:
- name->tip_name = tip_name;
- name->taggerdate = taggerdate;
- name->generation = generation;
- name->distance = distance;
- name->from_tag = from_tag;
- } else {
+ if (!create_or_update_name(commit, tip_name, taggerdate, generation,
+ distance, from_tag)) {
free(to_free);
return;
}