Skip to content

Commit 87be252

Browse files
pcloudsgitster
authored andcommitted
revision.c: use commit-slab for show_source
Instead of relying on commit->util to store the source string, let the user provide a commit-slab to store the source strings in. 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 3cc0287 commit 87be252

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

builtin/fast-export.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "quote.h"
2222
#include "remote.h"
2323
#include "blob.h"
24+
#include "commit-slab.h"
2425

2526
static const char *fast_export_usage[] = {
2627
N_("git fast-export [rev-list-opts]"),
@@ -38,6 +39,7 @@ static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
3839
static struct refspec *refspecs;
3940
static int refspecs_nr;
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)
@@ -590,7 +592,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
590592
if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
591593
export_blob(&diff_queued_diff.queue[i]->two->oid);
592594

593-
refname = commit->util;
595+
refname = *revision_sources_at(&revision_sources, commit);
594596
if (anonymize) {
595597
refname = anonymize_refname(refname);
596598
anonymize_ident_line(&committer, &committer_end);
@@ -862,10 +864,11 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
862864
* This ref will not be updated through a commit, lets make
863865
* sure it gets properly updated eventually.
864866
*/
865-
if (commit->util || commit->object.flags & SHOWN)
867+
if (*revision_sources_at(&revision_sources, commit) ||
868+
commit->object.flags & SHOWN)
866869
string_list_append(&extra_refs, full_name)->util = commit;
867-
if (!commit->util)
868-
commit->util = full_name;
870+
if (!*revision_sources_at(&revision_sources, commit))
871+
*revision_sources_at(&revision_sources, commit) = full_name;
869872
}
870873
}
871874

@@ -1029,8 +1032,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
10291032
git_config(git_default_config, NULL);
10301033

10311034
init_revisions(&revs, prefix);
1035+
init_revision_sources(&revision_sources);
10321036
revs.topo_order = 1;
1033-
revs.show_source = 1;
1037+
revs.sources = &revision_sources;
10341038
revs.rewrite_parents = 1;
10351039
argc = parse_options(argc, argv, prefix, options, fast_export_usage,
10361040
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);

builtin/log.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
148148
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
149149
struct decoration_filter decoration_filter = {&decorate_refs_include,
150150
&decorate_refs_exclude};
151+
static struct revision_sources revision_sources;
151152

152153
const struct option builtin_log_options[] = {
153154
OPT__QUIET(&quiet, N_("suppress diff output")),
@@ -194,8 +195,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
194195
rev->diffopt.filter || rev->diffopt.flags.follow_renames)
195196
rev->always_show_header = 0;
196197

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

200203
if (mailmap) {
201204
rev->mailmap = xcalloc(1, sizeof(struct string_list));

log-tree.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,12 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
295295
{
296296
struct strbuf sb = STRBUF_INIT;
297297

298-
if (opt->show_source && commit->util)
299-
fprintf(opt->diffopt.file, "\t%s", (char *) commit->util);
298+
if (opt->sources) {
299+
char **slot = revision_sources_peek(opt->sources, commit);
300+
301+
if (slot && *slot)
302+
fprintf(opt->diffopt.file, "\t%s", *slot);
303+
}
300304
if (!opt->show_decorations)
301305
return;
302306
format_decorations(&sb, commit, opt->diffopt.use_color);

revision.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ volatile show_early_output_fn_t show_early_output;
2929
static const char *term_bad;
3030
static const char *term_good;
3131

32+
implement_shared_commit_slab(revision_sources, char *);
33+
3234
void show_object_with_name(FILE *out, struct object *obj, const char *name)
3335
{
3436
const char *p;
@@ -255,14 +257,19 @@ static struct commit *handle_commit(struct rev_info *revs,
255257
*/
256258
if (object->type == OBJ_COMMIT) {
257259
struct commit *commit = (struct commit *)object;
260+
258261
if (parse_commit(commit) < 0)
259262
die("unable to parse commit %s", name);
260263
if (flags & UNINTERESTING) {
261264
mark_parents_uninteresting(commit);
262265
revs->limited = 1;
263266
}
264-
if (revs->show_source && !commit->util)
265-
commit->util = xstrdup(name);
267+
if (revs->sources) {
268+
char **slot = revision_sources_at(revs->sources, commit);
269+
270+
if (!*slot)
271+
*slot = xstrdup(name);
272+
}
266273
return commit;
267274
}
268275

@@ -814,8 +821,12 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
814821
}
815822
return -1;
816823
}
817-
if (revs->show_source && !p->util)
818-
p->util = commit->util;
824+
if (revs->sources) {
825+
char **slot = revision_sources_at(revs->sources, p);
826+
827+
if (!*slot)
828+
*slot = *revision_sources_at(revs->sources, commit);
829+
}
819830
p->object.flags |= left_flag;
820831
if (!(p->object.flags & SEEN)) {
821832
p->object.flags |= SEEN;

revision.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "notes.h"
77
#include "pretty.h"
88
#include "diff.h"
9+
#include "commit-slab-decl.h"
910

1011
/* Remember to update object flag allocation in object.h */
1112
#define SEEN (1u<<0)
@@ -29,6 +30,7 @@ struct rev_info;
2930
struct log_info;
3031
struct string_list;
3132
struct saved_parents;
33+
define_shared_commit_slab(revision_sources, char *);
3234

3335
struct rev_cmdline_info {
3436
unsigned int nr;
@@ -111,7 +113,6 @@ struct rev_info {
111113
right_only:1,
112114
rewrite_parents:1,
113115
print_parents:1,
114-
show_source:1,
115116
show_decorations:1,
116117
reverse:1,
117118
reverse_output_stage:1,
@@ -224,6 +225,8 @@ struct rev_info {
224225

225226
struct commit_list *previous_parents;
226227
const char *break_bar;
228+
229+
struct revision_sources *sources;
227230
};
228231

229232
extern int ref_excluded(struct string_list *, const char *path);

0 commit comments

Comments
 (0)