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>
This commit is contained in:

committed by
Junio C Hamano

parent
bb408ac95d
commit
8fd79a7304
@ -6,6 +6,7 @@
|
|||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
#include "parse-options.h"
|
#include "parse-options.h"
|
||||||
#include "sha1-lookup.h"
|
#include "sha1-lookup.h"
|
||||||
|
#include "commit-slab.h"
|
||||||
|
|
||||||
#define CUTOFF_DATE_SLOP 86400 /* one day */
|
#define CUTOFF_DATE_SLOP 86400 /* one day */
|
||||||
|
|
||||||
@ -17,11 +18,26 @@ typedef struct rev_name {
|
|||||||
int from_tag;
|
int from_tag;
|
||||||
} rev_name;
|
} rev_name;
|
||||||
|
|
||||||
|
define_commit_slab(commit_rev_name, struct rev_name *);
|
||||||
|
|
||||||
static timestamp_t cutoff = TIME_MAX;
|
static timestamp_t cutoff = TIME_MAX;
|
||||||
|
static struct commit_rev_name rev_names;
|
||||||
|
|
||||||
/* How many generations are maximally preferred over _one_ merge traversal? */
|
/* How many generations are maximally preferred over _one_ merge traversal? */
|
||||||
#define MERGE_TRAVERSAL_WEIGHT 65535
|
#define MERGE_TRAVERSAL_WEIGHT 65535
|
||||||
|
|
||||||
|
static struct rev_name *get_commit_rev_name(struct commit *commit)
|
||||||
|
{
|
||||||
|
struct rev_name **slot = commit_rev_name_peek(&rev_names, commit);
|
||||||
|
|
||||||
|
return slot ? *slot : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_commit_rev_name(struct commit *commit, struct rev_name *name)
|
||||||
|
{
|
||||||
|
*commit_rev_name_at(&rev_names, commit) = name;
|
||||||
|
}
|
||||||
|
|
||||||
static int is_better_name(struct rev_name *name,
|
static int is_better_name(struct rev_name *name,
|
||||||
const char *tip_name,
|
const char *tip_name,
|
||||||
timestamp_t taggerdate,
|
timestamp_t taggerdate,
|
||||||
@ -65,7 +81,7 @@ static void name_rev(struct commit *commit,
|
|||||||
int generation, int distance, int from_tag,
|
int generation, int distance, int from_tag,
|
||||||
int deref)
|
int deref)
|
||||||
{
|
{
|
||||||
struct rev_name *name = (struct rev_name *)commit->util;
|
struct rev_name *name = get_commit_rev_name(commit);
|
||||||
struct commit_list *parents;
|
struct commit_list *parents;
|
||||||
int parent_number = 1;
|
int parent_number = 1;
|
||||||
char *to_free = NULL;
|
char *to_free = NULL;
|
||||||
@ -84,7 +100,7 @@ static void name_rev(struct commit *commit,
|
|||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
name = xmalloc(sizeof(rev_name));
|
name = xmalloc(sizeof(rev_name));
|
||||||
commit->util = name;
|
set_commit_rev_name(commit, name);
|
||||||
goto copy_data;
|
goto copy_data;
|
||||||
} else if (is_better_name(name, tip_name, taggerdate,
|
} else if (is_better_name(name, tip_name, taggerdate,
|
||||||
generation, distance, from_tag)) {
|
generation, distance, from_tag)) {
|
||||||
@ -296,7 +312,7 @@ static const char *get_rev_name(const struct object *o, struct strbuf *buf)
|
|||||||
if (o->type != OBJ_COMMIT)
|
if (o->type != OBJ_COMMIT)
|
||||||
return get_exact_ref_match(o);
|
return get_exact_ref_match(o);
|
||||||
c = (struct commit *) o;
|
c = (struct commit *) o;
|
||||||
n = c->util;
|
n = get_commit_rev_name(c);
|
||||||
if (!n)
|
if (!n)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -413,6 +429,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_END(),
|
OPT_END(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
init_commit_rev_name(&rev_names);
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
|
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
|
||||||
if (all + transform_stdin + !!argc > 1) {
|
if (all + transform_stdin + !!argc > 1) {
|
||||||
|
Reference in New Issue
Block a user