Skip to content

Commit b3b2aaf

Browse files
committed
Merge branch 'nd/commit-util-to-slab'
The in-core "commit" object had an all-purpose "void *util" field, which was tricky to use especially in library-ish part of the code. All of the existing uses of the field has been migrated to a more dedicated "commit-slab" mechanism and the field is eliminated. * nd/commit-util-to-slab: commit.h: delete 'util' field in struct commit merge: use commit-slab in merge remote desc instead of commit->util log: use commit-slab in prepare_bases() instead of commit->util show-branch: note about its object flags usage show-branch: use commit-slab for commit-name instead of commit->util name-rev: use commit-slab for rev-name instead of commit->util bisect.c: use commit-slab for commit weight instead of commit->util revision.c: use commit-slab for show_source sequencer.c: use commit-slab to associate todo items to commits sequencer.c: use commit-slab to mark seen commits shallow.c: use commit-slab for commit depth instead of commit->util describe: use commit-slab for commit names instead of commit->util blame: use commit-slab for blame suspects instead of commit->util commit-slab: support shared commit-slab commit-slab.h: code split
2 parents ea27893 + 9d2c970 commit b3b2aaf

22 files changed

+382
-195
lines changed

bisect.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "bisect.h"
1313
#include "sha1-array.h"
1414
#include "argv-array.h"
15+
#include "commit-slab.h"
1516

1617
static struct oid_array good_revs;
1718
static struct oid_array skipped_revs;
@@ -70,16 +71,19 @@ static void clear_distance(struct commit_list *list)
7071
}
7172
}
7273

74+
define_commit_slab(commit_weight, int *);
75+
static struct commit_weight commit_weight;
76+
7377
#define DEBUG_BISECT 0
7478

7579
static inline int weight(struct commit_list *elem)
7680
{
77-
return *((int*)(elem->item->util));
81+
return **commit_weight_at(&commit_weight, elem->item);
7882
}
7983

8084
static inline void weight_set(struct commit_list *elem, int weight)
8185
{
82-
*((int*)(elem->item->util)) = weight;
86+
**commit_weight_at(&commit_weight, elem->item) = weight;
8387
}
8488

8589
static int count_interesting_parents(struct commit *commit)
@@ -265,7 +269,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
265269
struct commit *commit = p->item;
266270
unsigned flags = commit->object.flags;
267271

268-
p->item->util = &weights[n++];
272+
*commit_weight_at(&commit_weight, p->item) = &weights[n++];
269273
switch (count_interesting_parents(commit)) {
270274
case 0:
271275
if (!(flags & TREESAME)) {
@@ -372,6 +376,7 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
372376
int *weights;
373377

374378
show_list("bisection 2 entry", 0, 0, *commit_list);
379+
init_commit_weight(&commit_weight);
375380

376381
/*
377382
* Count the number of total and tree-changing items on the
@@ -412,6 +417,7 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
412417
}
413418
free(weights);
414419
*commit_list = best;
420+
clear_commit_weight(&commit_weight);
415421
}
416422

417423
static int register_ref(const char *refname, const struct object_id *oid,

blame.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
#include "diffcore.h"
77
#include "tag.h"
88
#include "blame.h"
9+
#include "commit-slab.h"
10+
11+
define_commit_slab(blame_suspects, struct blame_origin *);
12+
static struct blame_suspects blame_suspects;
13+
14+
struct blame_origin *get_blame_suspects(struct commit *commit)
15+
{
16+
struct blame_origin **result;
17+
18+
result = blame_suspects_peek(&blame_suspects, commit);
19+
20+
return result ? *result : NULL;
21+
}
22+
23+
static void set_blame_suspects(struct commit *commit, struct blame_origin *origin)
24+
{
25+
*blame_suspects_at(&blame_suspects, commit) = origin;
26+
}
927

1028
void blame_origin_decref(struct blame_origin *o)
1129
{
@@ -15,12 +33,12 @@ void blame_origin_decref(struct blame_origin *o)
1533
blame_origin_decref(o->previous);
1634
free(o->file.ptr);
1735
/* Should be present exactly once in commit chain */
18-
for (p = o->commit->util; p; l = p, p = p->next) {
36+
for (p = get_blame_suspects(o->commit); p; l = p, p = p->next) {
1937
if (p == o) {
2038
if (l)
2139
l->next = p->next;
2240
else
23-
o->commit->util = p->next;
41+
set_blame_suspects(o->commit, p->next);
2442
free(o);
2543
return;
2644
}
@@ -41,8 +59,8 @@ static struct blame_origin *make_origin(struct commit *commit, const char *path)
4159
FLEX_ALLOC_STR(o, path, path);
4260
o->commit = commit;
4361
o->refcnt = 1;
44-
o->next = commit->util;
45-
commit->util = o;
62+
o->next = get_blame_suspects(commit);
63+
set_blame_suspects(commit, o);
4664
return o;
4765
}
4866

@@ -54,13 +72,13 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
5472
{
5573
struct blame_origin *o, *l;
5674

57-
for (o = commit->util, l = NULL; o; l = o, o = o->next) {
75+
for (o = get_blame_suspects(commit), l = NULL; o; l = o, o = o->next) {
5876
if (!strcmp(o->path, path)) {
5977
/* bump to front */
6078
if (l) {
6179
l->next = o->next;
62-
o->next = commit->util;
63-
commit->util = o;
80+
o->next = get_blame_suspects(commit);
81+
set_blame_suspects(commit, o);
6482
}
6583
return blame_origin_incref(o);
6684
}
@@ -478,7 +496,7 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
478496
porigin->suspects = blame_merge(porigin->suspects, sorted);
479497
else {
480498
struct blame_origin *o;
481-
for (o = porigin->commit->util; o; o = o->next) {
499+
for (o = get_blame_suspects(porigin->commit); o; o = o->next) {
482500
if (o->suspects) {
483501
porigin->suspects = sorted;
484502
return;
@@ -525,7 +543,7 @@ static struct blame_origin *find_origin(struct commit *parent,
525543
const char *paths[2];
526544

527545
/* First check any existing origins */
528-
for (porigin = parent->util; porigin; porigin = porigin->next)
546+
for (porigin = get_blame_suspects(parent); porigin; porigin = porigin->next)
529547
if (!strcmp(porigin->path, origin->path)) {
530548
/*
531549
* The same path between origin and its parent
@@ -1550,7 +1568,7 @@ void assign_blame(struct blame_scoreboard *sb, int opt)
15501568

15511569
while (commit) {
15521570
struct blame_entry *ent;
1553-
struct blame_origin *suspect = commit->util;
1571+
struct blame_origin *suspect = get_blame_suspects(commit);
15541572

15551573
/* find one suspect to break down */
15561574
while (suspect && !suspect->suspects)
@@ -1752,6 +1770,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
17521770
struct commit *final_commit = NULL;
17531771
enum object_type type;
17541772

1773+
init_blame_suspects(&blame_suspects);
1774+
17551775
if (sb->reverse && sb->contents_from)
17561776
die(_("--contents and --reverse do not blend well."));
17571777

@@ -1815,7 +1835,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
18151835
}
18161836

18171837
if (is_null_oid(&sb->final->object.oid)) {
1818-
o = sb->final->util;
1838+
o = get_blame_suspects(sb->final);
18191839
sb->final_buf = xmemdupz(o->file.ptr, o->file.size);
18201840
sb->final_buf_size = o->file.size;
18211841
}

blame.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,6 @@ extern void setup_scoreboard(struct blame_scoreboard *sb, const char *path, stru
172172

173173
extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long start, long end, struct blame_origin *o);
174174

175+
extern struct blame_origin *get_blame_suspects(struct commit *commit);
176+
175177
#endif /* BLAME_H */

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ static void output(struct blame_scoreboard *sb, int option)
543543
struct commit *commit = ent->suspect->commit;
544544
if (commit->object.flags & MORE_THAN_ONE_PATH)
545545
continue;
546-
for (suspect = commit->util; suspect; suspect = suspect->next) {
546+
for (suspect = get_blame_suspects(commit); suspect; suspect = suspect->next) {
547547
if (suspect->guilty && count++) {
548548
commit->object.flags |= MORE_THAN_ONE_PATH;
549549
break;

builtin/describe.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
#include "run-command.h"
1616
#include "revision.h"
1717
#include "list-objects.h"
18+
#include "commit-slab.h"
1819

1920
#define MAX_TAGS (FLAG_BITS - 1)
2021

22+
define_commit_slab(commit_names, struct commit_name *);
23+
2124
static const char * const describe_usage[] = {
2225
N_("git describe [<options>] [<commit-ish>...]"),
2326
N_("git describe [<options>] --dirty"),
@@ -37,6 +40,7 @@ static struct string_list patterns = STRING_LIST_INIT_NODUP;
3740
static struct string_list exclude_patterns = STRING_LIST_INIT_NODUP;
3841
static int always;
3942
static const char *suffix, *dirty, *broken;
43+
static struct commit_names commit_names;
4044

4145
/* diff-index command arguments to check if working tree is dirty. */
4246
static const char *diff_index_args[] = {
@@ -321,11 +325,14 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
321325
if (!have_util) {
322326
struct hashmap_iter iter;
323327
struct commit *c;
324-
struct commit_name *n = hashmap_iter_first(&names, &iter);
328+
struct commit_name *n;
329+
330+
init_commit_names(&commit_names);
331+
n = hashmap_iter_first(&names, &iter);
325332
for (; n; n = hashmap_iter_next(&iter)) {
326333
c = lookup_commit_reference_gently(&n->peeled, 1);
327334
if (c)
328-
c->util = n;
335+
*commit_names_at(&commit_names, c) = n;
329336
}
330337
have_util = 1;
331338
}
@@ -336,8 +343,11 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
336343
while (list) {
337344
struct commit *c = pop_commit(&list);
338345
struct commit_list *parents = c->parents;
346+
struct commit_name **slot;
347+
339348
seen_commits++;
340-
n = c->util;
349+
slot = commit_names_peek(&commit_names, c);
350+
n = slot ? *slot : NULL;
341351
if (n) {
342352
if (!tags && !all && n->prio < 2) {
343353
unannotated_cnt++;

builtin/fast-export.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "quote.h"
2323
#include "remote.h"
2424
#include "blob.h"
25+
#include "commit-slab.h"
2526

2627
static const char *fast_export_usage[] = {
2728
N_("git fast-export [rev-list-opts]"),
@@ -38,6 +39,7 @@ static int full_tree;
3839
static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
3940
static struct refspec refspecs = REFSPEC_INIT_FETCH;
4041
static int anonymize;
42+
static struct revision_sources revision_sources;
4143

4244
static int parse_opt_signed_tag_mode(const struct option *opt,
4345
const char *arg, int unset)
@@ -589,7 +591,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
589591
if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
590592
export_blob(&diff_queued_diff.queue[i]->two->oid);
591593

592-
refname = commit->util;
594+
refname = *revision_sources_at(&revision_sources, commit);
593595
if (anonymize) {
594596
refname = anonymize_refname(refname);
595597
anonymize_ident_line(&committer, &committer_end);
@@ -861,10 +863,11 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
861863
* This ref will not be updated through a commit, lets make
862864
* sure it gets properly updated eventually.
863865
*/
864-
if (commit->util || commit->object.flags & SHOWN)
866+
if (*revision_sources_at(&revision_sources, commit) ||
867+
commit->object.flags & SHOWN)
865868
string_list_append(&extra_refs, full_name)->util = commit;
866-
if (!commit->util)
867-
commit->util = full_name;
869+
if (!*revision_sources_at(&revision_sources, commit))
870+
*revision_sources_at(&revision_sources, commit) = full_name;
868871
}
869872
}
870873

@@ -1028,8 +1031,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
10281031
git_config(git_default_config, NULL);
10291032

10301033
init_revisions(&revs, prefix);
1034+
init_revision_sources(&revision_sources);
10311035
revs.topo_order = 1;
1032-
revs.show_source = 1;
1036+
revs.sources = &revision_sources;
10331037
revs.rewrite_parents = 1;
10341038
argc = parse_options(argc, argv, prefix, options, fast_export_usage,
10351039
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);

builtin/log.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "mailmap.h"
2929
#include "gpg-interface.h"
3030
#include "progress.h"
31+
#include "commit-slab.h"
3132

3233
#define MAIL_DEFAULT_WRAP 72
3334

@@ -148,6 +149,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
148149
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
149150
struct decoration_filter decoration_filter = {&decorate_refs_include,
150151
&decorate_refs_exclude};
152+
static struct revision_sources revision_sources;
151153

152154
const struct option builtin_log_options[] = {
153155
OPT__QUIET(&quiet, N_("suppress diff output")),
@@ -194,8 +196,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
194196
rev->diffopt.filter || rev->diffopt.flags.follow_renames)
195197
rev->always_show_header = 0;
196198

197-
if (source)
198-
rev->show_source = 1;
199+
if (source) {
200+
init_revision_sources(&revision_sources);
201+
rev->sources = &revision_sources;
202+
}
199203

200204
if (mailmap) {
201205
rev->mailmap = xcalloc(1, sizeof(struct string_list));
@@ -1337,6 +1341,8 @@ static struct commit *get_base_commit(const char *base_commit,
13371341
return base;
13381342
}
13391343

1344+
define_commit_slab(commit_base, int);
1345+
13401346
static void prepare_bases(struct base_tree_info *bases,
13411347
struct commit *base,
13421348
struct commit **list,
@@ -1345,11 +1351,13 @@ static void prepare_bases(struct base_tree_info *bases,
13451351
struct commit *commit;
13461352
struct rev_info revs;
13471353
struct diff_options diffopt;
1354+
struct commit_base commit_base;
13481355
int i;
13491356

13501357
if (!base)
13511358
return;
13521359

1360+
init_commit_base(&commit_base);
13531361
diff_setup(&diffopt);
13541362
diffopt.flags.recursive = 1;
13551363
diff_setup_done(&diffopt);
@@ -1362,7 +1370,7 @@ static void prepare_bases(struct base_tree_info *bases,
13621370
for (i = 0; i < total; i++) {
13631371
list[i]->object.flags &= ~UNINTERESTING;
13641372
add_pending_object(&revs, &list[i]->object, "rev_list");
1365-
list[i]->util = (void *)1;
1373+
*commit_base_at(&commit_base, list[i]) = 1;
13661374
}
13671375
base->object.flags |= UNINTERESTING;
13681376
add_pending_object(&revs, &base->object, "base");
@@ -1376,7 +1384,7 @@ static void prepare_bases(struct base_tree_info *bases,
13761384
while ((commit = get_revision(&revs)) != NULL) {
13771385
struct object_id oid;
13781386
struct object_id *patch_id;
1379-
if (commit->util)
1387+
if (*commit_base_at(&commit_base, commit))
13801388
continue;
13811389
if (commit_patch_id(commit, &diffopt, &oid, 0))
13821390
die(_("cannot get patch id"));
@@ -1385,6 +1393,7 @@ static void prepare_bases(struct base_tree_info *bases,
13851393
oidcpy(patch_id, &oid);
13861394
bases->nr_patch_id++;
13871395
}
1396+
clear_commit_base(&commit_base);
13881397
}
13891398

13901399
static void print_bases(struct base_tree_info *bases, FILE *file)

0 commit comments

Comments
 (0)