16
#include "packfile.h"
17
#include "object-store.h"
18
#include "promisor-remote.h"
19
+#include "mailmap.h"
20
21
enum batch_mode {
22
BATCH_MODE_CONTENTS,
37
38
static const char *force_path;
39
40
+static struct string_list mailmap = STRING_LIST_INIT_NODUP;
41
+static int use_mailmap;
42
+
43
+static char *replace_idents_using_mailmap(char *, size_t *);
44
+
45
+static char *replace_idents_using_mailmap(char *object_buf, size_t *size)
46
+{
47
+ struct strbuf sb = STRBUF_INIT;
48
+ const char *headers[] = { "author ", "committer ", "tagger ", NULL };
49
+
50
+ strbuf_attach(&sb, object_buf, *size, *size + 1);
51
+ apply_mailmap_to_header(&sb, headers, &mailmap);
52
+ *size = sb.len;
53
+ return strbuf_detach(&sb, NULL);
54
+}
55
+
56
static int filter_object(const char *path, unsigned mode,
57
const struct object_id *oid,
58
char **buf, unsigned long *size)
169
if (!buf)
170
die("Cannot read object %s", obj_name);
171
172
+ if (use_mailmap) {
173
+ size_t s = size;
174
+ buf = replace_idents_using_mailmap(buf, &s);
175
+ size = cast_size_t_to_ulong(s);
176
+ }
177
+
178
/* otherwise just spit out the data */
179
break;
180
206
}
207
buf = read_object_with_reference(the_repository, &oid,
208
exp_type_id, &size, NULL);
209
+
210
+ if (use_mailmap) {
211
+ size_t s = size;
212
+ buf = replace_idents_using_mailmap(buf, &s);
213
+ size = cast_size_t_to_ulong(s);
214
+ }
215
break;
216
}
217
default:
377
void *contents;
378
379
contents = read_object_file(oid, &type, &size);
380
+
381
+ if (use_mailmap) {
382
+ size_t s = size;
383
+ contents = replace_idents_using_mailmap(contents, &s);
384
+ size = cast_size_t_to_ulong(s);
385
+ }
386
+
387
if (!contents)
388
die("object %s disappeared", oid_to_hex(oid));
389
if (type != data->type)
390
die("object %s changed type!?", oid_to_hex(oid));
355
- if (data->info.sizep && size != data->size)
391
+ if (data->info.sizep && size != data->size && !use_mailmap)
392
die("object %s changed size!?", oid_to_hex(oid));
393
394
batch_write(opt, contents, size);
879
OPT_CMDMODE('s', NULL, &opt, N_("show object size"), 's'),
880
OPT_BOOL(0, "allow-unknown-type", &unknown_type,
881
N_("allow -s and -t to work with broken/corrupt objects")),
882
+ OPT_BOOL(0, "use-mailmap", &use_mailmap, N_("use mail map file")),
883
+ OPT_ALIAS(0, "mailmap", "use-mailmap"),
884
/* Batch mode */
885
OPT_GROUP(N_("Batch objects requested on stdin (or --batch-all-objects)")),
886
OPT_CALLBACK_F(0, "batch", &batch, N_("format"),
923
opt_cw = (opt == 'c' || opt == 'w');
924
opt_epts = (opt == 'e' || opt == 'p' || opt == 't' || opt == 's');
925
926
+ if (use_mailmap)
927
+ read_mailmap(&mailmap);
928
+
929
/* --batch-all-objects? */
930
if (opt == 'b')
931
batch.all_objects = 1;