312
return result;
313
}
314
315
-static char *get_object_name(struct fsck_options *options, struct object *obj)
315
+void fsck_enable_object_names(struct fsck_options *options)
316
+{
317
+ if (!options->object_names)
318
+ options->object_names = xcalloc(1, sizeof(struct decoration));
319
+}
320
+
321
+const char *fsck_get_object_name(struct fsck_options *options, struct object *obj)
322
{
323
if (!options->object_names)
324
return NULL;
325
return lookup_decoration(options->object_names, obj);
326
}
327
322
-static void put_object_name(struct fsck_options *options, struct object *obj,
323
- const char *fmt, ...)
328
+void fsck_put_object_name(struct fsck_options *options, struct object *obj,
329
+ const char *fmt, ...)
330
{
331
va_list ap;
332
struct strbuf buf = STRBUF_INIT;
343
va_end(ap);
344
}
345
340
-static const char *describe_object(struct fsck_options *o, struct object *obj)
346
+const char *fsck_describe_object(struct fsck_options *options,
347
+ struct object *obj)
348
{
342
- static struct strbuf buf = STRBUF_INIT;
343
- char *name;
344
-
345
- strbuf_reset(&buf);
346
- strbuf_addstr(&buf, oid_to_hex(&obj->oid));
347
- if (o->object_names && (name = lookup_decoration(o->object_names, obj)))
348
- strbuf_addf(&buf, " (%s)", name);
349
+ static struct strbuf bufs[] = {
350
+ STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
351
+ };
352
+ static int b = 0;
353
+ struct strbuf *buf;
354
+ char *name = NULL;
355
+
356
+ if (options->object_names)
357
+ name = lookup_decoration(options->object_names, obj);
358
+
359
+ buf = bufs + b;
360
+ b = (b + 1) % ARRAY_SIZE(bufs);
361
+ strbuf_reset(buf);
362
+ strbuf_addstr(buf, oid_to_hex(&obj->oid));
363
+ if (name)
364
+ strbuf_addf(buf, " (%s)", name);
365
350
- return buf.buf;
366
+ return buf->buf;
367
}
368
369
static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *options)
376
if (parse_tree(tree))
377
return -1;
378
363
- name = get_object_name(options, &tree->object);
379
+ name = fsck_get_object_name(options, &tree->object);
380
if (init_tree_desc_gently(&desc, tree->buffer, tree->size))
381
return -1;
382
while (tree_entry_gently(&desc, &entry)) {
389
if (S_ISDIR(entry.mode)) {
390
obj = (struct object *)lookup_tree(the_repository, &entry.oid);
391
if (name && obj)
376
- put_object_name(options, obj, "%s%s/", name,
377
- entry.path);
392
+ fsck_put_object_name(options, obj, "%s%s/",
393
+ name, entry.path);
394
result = options->walk(obj, OBJ_TREE, data, options);
395
}
396
else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
397
obj = (struct object *)lookup_blob(the_repository, &entry.oid);
398
if (name && obj)
383
- put_object_name(options, obj, "%s%s", name,
384
- entry.path);
399
+ fsck_put_object_name(options, obj, "%s%s",
400
+ name, entry.path);
401
result = options->walk(obj, OBJ_BLOB, data, options);
402
}
403
else {
404
result = error("in tree %s: entry %s has bad mode %.6o",
389
- describe_object(options, &tree->object), entry.path, entry.mode);
405
+ fsck_describe_object(options, &tree->object),
406
+ entry.path, entry.mode);
407
}
408
if (result < 0)
409
return result;
424
if (parse_commit(commit))
425
return -1;
426
410
- name = get_object_name(options, &commit->object);
427
+ name = fsck_get_object_name(options, &commit->object);
428
if (name)
412
- put_object_name(options, &get_commit_tree(commit)->object,
413
- "%s:", name);
429
+ fsck_put_object_name(options, &get_commit_tree(commit)->object,
430
+ "%s:", name);
431
432
result = options->walk((struct object *)get_commit_tree(commit),
433
OBJ_TREE, data, options);
458
struct object *obj = &parents->item->object;
459
460
if (counter++)
444
- put_object_name(options, obj, "%s^%d",
445
- name, counter);
461
+ fsck_put_object_name(options, obj, "%s^%d",
462
+ name, counter);
463
else if (generation > 0)
447
- put_object_name(options, obj, "%.*s~%d",
448
- name_prefix_len, name, generation + 1);
464
+ fsck_put_object_name(options, obj, "%.*s~%d",
465
+ name_prefix_len, name,
466
+ generation + 1);
467
else
450
- put_object_name(options, obj, "%s^", name);
468
+ fsck_put_object_name(options, obj, "%s^",
469
+ name);
470
}
471
result = options->walk((struct object *)parents->item, OBJ_COMMIT, data, options);
472
if (result < 0)
480
481
static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *options)
482
{
464
- char *name = get_object_name(options, &tag->object);
483
+ const char *name = fsck_get_object_name(options, &tag->object);
484
485
if (parse_tag(tag))
486
return -1;
487
if (name)
469
- put_object_name(options, tag->tagged, "%s", name);
488
+ fsck_put_object_name(options, tag->tagged, "%s", name);
489
return options->walk(tag->tagged, OBJ_ANY, data, options);
490
}
491
507
case OBJ_TAG:
508
return fsck_walk_tag((struct tag *)obj, data, options);
509
default:
491
- error("Unknown object type for %s", describe_object(options, obj));
510
+ error("Unknown object type for %s",
511
+ fsck_describe_object(options, obj));
512
return -1;
513
}
514
}
982
struct object *obj, int msg_type, const char *message)
983
{
984
if (msg_type == FSCK_WARN) {
965
- warning("object %s: %s", describe_object(o, obj), message);
985
+ warning("object %s: %s", fsck_describe_object(o, obj), message);
986
return 0;
987
}
968
- error("object %s: %s", describe_object(o, obj), message);
988
+ error("object %s: %s", fsck_describe_object(o, obj), message);
989
return 1;
990
}
991