Skip to content

Commit 8fd79a7

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]>
1 parent bb408ac commit 8fd79a7

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

builtin/name-rev.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "refs.h"
77
#include "parse-options.h"
88
#include "sha1-lookup.h"
9+
#include "commit-slab.h"
910

1011
#define CUTOFF_DATE_SLOP 86400 /* one day */
1112

@@ -17,11 +18,26 @@ typedef struct rev_name {
1718
int from_tag;
1819
} rev_name;
1920

21+
define_commit_slab(commit_rev_name, struct rev_name *);
22+
2023
static timestamp_t cutoff = TIME_MAX;
24+
static struct commit_rev_name rev_names;
2125

2226
/* How many generations are maximally preferred over _one_ merge traversal? */
2327
#define MERGE_TRAVERSAL_WEIGHT 65535
2428

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+
2541
static int is_better_name(struct rev_name *name,
2642
const char *tip_name,
2743
timestamp_t taggerdate,
@@ -65,7 +81,7 @@ static void name_rev(struct commit *commit,
6581
int generation, int distance, int from_tag,
6682
int deref)
6783
{
68-
struct rev_name *name = (struct rev_name *)commit->util;
84+
struct rev_name *name = get_commit_rev_name(commit);
6985
struct commit_list *parents;
7086
int parent_number = 1;
7187
char *to_free = NULL;
@@ -84,7 +100,7 @@ static void name_rev(struct commit *commit,
84100

85101
if (name == NULL) {
86102
name = xmalloc(sizeof(rev_name));
87-
commit->util = name;
103+
set_commit_rev_name(commit, name);
88104
goto copy_data;
89105
} else if (is_better_name(name, tip_name, taggerdate,
90106
generation, distance, from_tag)) {
@@ -296,7 +312,7 @@ static const char *get_rev_name(const struct object *o, struct strbuf *buf)
296312
if (o->type != OBJ_COMMIT)
297313
return get_exact_ref_match(o);
298314
c = (struct commit *) o;
299-
n = c->util;
315+
n = get_commit_rev_name(c);
300316
if (!n)
301317
return NULL;
302318

@@ -413,6 +429,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
413429
OPT_END(),
414430
};
415431

432+
init_commit_rev_name(&rev_names);
416433
git_config(git_default_config, NULL);
417434
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
418435
if (all + transform_stdin + !!argc > 1) {

0 commit comments

Comments
 (0)