338
static uintmax_t next_mark;
339
static struct dbuf new_data;
340
341
+static void write_branch_report(FILE *rpt, struct branch *b)
342
+{
343
+ fprintf(rpt, "%s:\n", b->name);
344
+
345
+ fprintf(rpt, " status :");
346
+ if (b->active)
347
+ fputs(" active", rpt);
348
+ if (b->branch_tree.tree)
349
+ fputs(" loaded", rpt);
350
+ if (is_null_sha1(b->branch_tree.versions[1].sha1))
351
+ fputs(" dirty", rpt);
352
+ fputc('\n', rpt);
353
+
354
+ fprintf(rpt, " tip commit : %s\n", sha1_to_hex(b->sha1));
355
+ fprintf(rpt, " old tree : %s\n", sha1_to_hex(b->branch_tree.versions[0].sha1));
356
+ fprintf(rpt, " cur tree : %s\n", sha1_to_hex(b->branch_tree.versions[1].sha1));
357
+ fprintf(rpt, " commit clock: %" PRIuMAX "\n", b->last_commit);
358
+
359
+ fputs(" last pack : ", rpt);
360
+ if (b->pack_id < MAX_PACK_ID)
361
+ fprintf(rpt, "%u", b->pack_id);
362
+ fputc('\n', rpt);
363
+
364
+ fputc('\n', rpt);
365
+}
366
+
367
+static void write_crash_report(const char *err, va_list params)
368
+{
369
+ char *loc = git_path("fast_import_crash_%d", getpid());
370
+ FILE *rpt = fopen(loc, "w");
371
+ struct branch *b;
372
+ unsigned long lu;
373
+
374
+ if (!rpt) {
375
+ error("can't write crash report %s: %s", loc, strerror(errno));
376
+ return;
377
+ }
378
+
379
+ fprintf(stderr, "fast-import: dumping crash report to %s\n", loc);
380
+
381
+ fprintf(rpt, "fast-import crash report:\n");
382
+ fprintf(rpt, " fast-import process: %d\n", getpid());
383
+ fprintf(rpt, " parent process : %d\n", getppid());
384
+ fprintf(rpt, " at %s\n", show_date(time(NULL), 0, DATE_LOCAL));
385
+ fputc('\n', rpt);
386
+
387
+ fputs("fatal: ", rpt);
388
+ vfprintf(rpt, err, params);
389
+ fputc('\n', rpt);
390
+
391
+ fputc('\n', rpt);
392
+ fputs("Active Branch LRU\n", rpt);
393
+ fputs("-----------------\n", rpt);
394
+ fprintf(rpt, " active_branches = %lu cur, %lu max\n",
395
+ cur_active_branches,
396
+ max_active_branches);
397
+ fputc('\n', rpt);
398
+ fputs(" pos clock name\n", rpt);
399
+ fputs(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", rpt);
400
+ for (b = active_branches, lu = 0; b; b = b->active_next_branch)
401
+ fprintf(rpt, " %2lu) %6" PRIuMAX" %s\n",
402
+ ++lu, b->last_commit, b->name);
403
+
404
+ fputc('\n', rpt);
405
+ fputs("Inactive Branches\n", rpt);
406
+ fputs("-----------------\n", rpt);
407
+ for (lu = 0; lu < branch_table_sz; lu++) {
408
+ for (b = branch_table[lu]; b; b = b->table_next_branch)
409
+ write_branch_report(rpt, b);
410
+ }
411
+
412
+ fputc('\n', rpt);
413
+ fputs("-------------------\n", rpt);
414
+ fputs("END OF CRASH REPORT\n", rpt);
415
+ fclose(rpt);
416
+}
417
+
418
+static NORETURN void die_nicely(const char *err, va_list params)
419
+{
420
+ static int zombie;
421
+
422
+ fputs("fatal: ", stderr);
423
+ vfprintf(stderr, err, params);
424
+ fputc('\n', stderr);
425
+
426
+ if (!zombie) {
427
+ zombie = 1;
428
+ write_crash_report(err, params);
429
+ }
430
+
431
+ exit(128);
432
+}
433
434
static void alloc_objects(unsigned int cnt)
435
{
2325
2326
prepare_packed_git();
2327
start_packfile();
2328
+ set_die_routine(die_nicely);
2329
for (;;) {
2330
read_next_command();
2331
if (command_buf.eof)