name-rev: use commit-slab for rev-name instead of commit->util
It's done so that commit->util can be removed. See more explanation in the commit that removes commit->util. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
May 19, 2018 at 07:28 UTC
8fd79a73042c6baf6216b2dd301012cbc6d8de03
1 file changed
+20
-3
builtin/name-rev.c
+20
-3
@@ -6,6 +6,7 @@
6
#include "refs.h"
7
#include "parse-options.h"
8
#include "sha1-lookup.h"
9
+#include "commit-slab.h"
10
11
#define CUTOFF_DATE_SLOP 86400 /* one day */
12
@@ -17,11 +18,26 @@ typedef struct rev_name {
18
int from_tag;
19
} rev_name;
20
21
+define_commit_slab(commit_rev_name, struct rev_name *);
22
+
23
static timestamp_t cutoff = TIME_MAX;
24
+static struct commit_rev_name rev_names;
25
26
/* How many generations are maximally preferred over _one_ merge traversal? */
27
#define MERGE_TRAVERSAL_WEIGHT 65535
28
29
+static struct rev_name *get_commit_rev_name(struct commit *commit)
30
+{
31
+ struct rev_name **slot = commit_rev_name_peek(&rev_names, commit);
32
+
33
+ return slot ? *slot : NULL;
34
+}
35
+
36
+static void set_commit_rev_name(struct commit *commit, struct rev_name *name)
37
+{
38
+ *commit_rev_name_at(&rev_names, commit) = name;
39
+}
40
+
41
static int is_better_name(struct rev_name *name,
42
const char *tip_name,
43
timestamp_t taggerdate,
@@ -65,7 +81,7 @@ static void name_rev(struct commit *commit,
81
int generation, int distance, int from_tag,
82
int deref)
83
{
68
- struct rev_name *name = (struct rev_name *)commit->util;
84
+ struct rev_name *name = get_commit_rev_name(commit);
85
struct commit_list *parents;
86
int parent_number = 1;
87
char *to_free = NULL;
@@ -84,7 +100,7 @@ static void name_rev(struct commit *commit,
100
101
if (name == NULL) {
102
name = xmalloc(sizeof(rev_name));
87
- commit->util = name;
103
+ set_commit_rev_name(commit, name);
104
goto copy_data;
105
} else if (is_better_name(name, tip_name, taggerdate,
106
generation, distance, from_tag)) {
@@ -296,7 +312,7 @@ static const char *get_rev_name(const struct object *o, struct strbuf *buf)
312
if (o->type != OBJ_COMMIT)
313
return get_exact_ref_match(o);
314
c = (struct commit *) o;
299
- n = c->util;
315
+ n = get_commit_rev_name(c);
316
if (!n)
317
return NULL;
318
@@ -413,6 +429,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
429
OPT_END(),
430
};
431
432
+ init_commit_rev_name(&rev_names);
433
git_config(git_default_config, NULL);
434
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
435
if (all + transform_stdin + !!argc > 1) {