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 <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
May 19, 2018 at 07:28 UTC
87be252333bac84d425973627266dfa20511224d
5 files changed
+39
-14
builtin/fast-export.c
+9
-5
@@ -21,6 +21,7 @@
21
#include "quote.h"
22
#include "remote.h"
23
#include "blob.h"
24
+#include "commit-slab.h"
25
26
static const char *fast_export_usage[] = {
27
N_("git fast-export [rev-list-opts]"),
@@ -38,6 +39,7 @@ static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
39
static struct refspec *refspecs;
40
static int refspecs_nr;
41
static int anonymize;
42
+static struct revision_sources revision_sources;
43
44
static int parse_opt_signed_tag_mode(const struct option *opt,
45
const char *arg, int unset)
@@ -590,7 +592,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
592
if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
593
export_blob(&diff_queued_diff.queue[i]->two->oid);
594
593
- refname = commit->util;
595
+ refname = *revision_sources_at(&revision_sources, commit);
596
if (anonymize) {
597
refname = anonymize_refname(refname);
598
anonymize_ident_line(&committer, &committer_end);
@@ -862,10 +864,11 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
864
* This ref will not be updated through a commit, lets make
865
* sure it gets properly updated eventually.
866
*/
865
- if (commit->util || commit->object.flags & SHOWN)
867
+ if (*revision_sources_at(&revision_sources, commit) ||
868
+ commit->object.flags & SHOWN)
869
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;
872
}
873
}
874
@@ -1029,8 +1032,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
1032
git_config(git_default_config, NULL);
1033
1034
init_revisions(&revs, prefix);
1035
+ init_revision_sources(&revision_sources);
1036
revs.topo_order = 1;
1033
- revs.show_source = 1;
1037
+ revs.sources = &revision_sources;
1038
revs.rewrite_parents = 1;
1039
argc = parse_options(argc, argv, prefix, options, fast_export_usage,
1040
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);
builtin/log.c
+5
-2
@@ -148,6 +148,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
148
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
149
struct decoration_filter decoration_filter = {&decorate_refs_include,
150
&decorate_refs_exclude};
151
+ static struct revision_sources revision_sources;
152
153
const struct option builtin_log_options[] = {
154
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,
195
rev->diffopt.filter || rev->diffopt.flags.follow_renames)
196
rev->always_show_header = 0;
197
197
- if (source)
198
- rev->show_source = 1;
198
+ if (source) {
199
+ init_revision_sources(&revision_sources);
200
+ rev->sources = &revision_sources;
201
+ }
202
203
if (mailmap) {
204
rev->mailmap = xcalloc(1, sizeof(struct string_list));
log-tree.c
+6
-2
@@ -295,8 +295,12 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
295
{
296
struct strbuf sb = STRBUF_INIT;
297
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
+ }
304
if (!opt->show_decorations)
305
return;
306
format_decorations(&sb, commit, opt->diffopt.use_color);
revision.c
+15
-4
@@ -29,6 +29,8 @@ volatile show_early_output_fn_t show_early_output;
29
static const char *term_bad;
30
static const char *term_good;
31
32
+implement_shared_commit_slab(revision_sources, char *);
33
+
34
void show_object_with_name(FILE *out, struct object *obj, const char *name)
35
{
36
const char *p;
@@ -255,14 +257,19 @@ static struct commit *handle_commit(struct rev_info *revs,
257
*/
258
if (object->type == OBJ_COMMIT) {
259
struct commit *commit = (struct commit *)object;
260
+
261
if (parse_commit(commit) < 0)
262
die("unable to parse commit %s", name);
263
if (flags & UNINTERESTING) {
264
mark_parents_uninteresting(commit);
265
revs->limited = 1;
266
}
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
+ }
273
return commit;
274
}
275
@@ -814,8 +821,12 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
821
}
822
return -1;
823
}
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
+ }
830
p->object.flags |= left_flag;
831
if (!(p->object.flags & SEEN)) {
832
p->object.flags |= SEEN;
revision.h
+4
-1
@@ -6,6 +6,7 @@
6
#include "notes.h"
7
#include "pretty.h"
8
#include "diff.h"
9
+#include "commit-slab-decl.h"
10
11
/* Remember to update object flag allocation in object.h */
12
#define SEEN (1u<<0)
@@ -29,6 +30,7 @@ struct rev_info;
30
struct log_info;
31
struct string_list;
32
struct saved_parents;
33
+define_shared_commit_slab(revision_sources, char *);
34
35
struct rev_cmdline_info {
36
unsigned int nr;
@@ -111,7 +113,6 @@ struct rev_info {
113
right_only:1,
114
rewrite_parents:1,
115
print_parents:1,
114
- show_source:1,
116
show_decorations:1,
117
reverse:1,
118
reverse_output_stage:1,
@@ -224,6 +225,8 @@ struct rev_info {
225
226
struct commit_list *previous_parents;
227
const char *break_bar;
228
+
229
+ struct revision_sources *sources;
230
};
231
232
extern int ref_excluded(struct string_list *, const char *path);