269
WHENSPEC_NOW,
270
} whenspec_type;
271
272
+struct recent_command
273
+{
274
+ struct recent_command *prev;
275
+ struct recent_command *next;
276
+ char *buf;
277
+};
278
+
279
/* Configured limits on output */
280
static unsigned long max_depth = 10;
281
static off_t max_packsize = (1LL << 32) - 1;
342
static whenspec_type whenspec = WHENSPEC_RAW;
343
static struct strbuf command_buf;
344
static int unread_command_buf;
345
+static struct recent_command cmd_hist = {&cmd_hist, &cmd_hist, NULL};
346
+static struct recent_command *cmd_tail = &cmd_hist;
347
+static struct recent_command *rc_free;
348
+static unsigned int cmd_save = 100;
349
static uintmax_t next_mark;
350
static struct dbuf new_data;
351
381
FILE *rpt = fopen(loc, "w");
382
struct branch *b;
383
unsigned long lu;
384
+ struct recent_command *rc;
385
386
if (!rpt) {
387
error("can't write crash report %s: %s", loc, strerror(errno));
400
vfprintf(rpt, err, params);
401
fputc('\n', rpt);
402
403
+ fputc('\n', rpt);
404
+ fputs("Most Recent Commands Before Crash\n", rpt);
405
+ fputs("---------------------------------\n", rpt);
406
+ for (rc = cmd_hist.next; rc != &cmd_hist; rc = rc->next) {
407
+ if (rc->next == &cmd_hist)
408
+ fputs("* ", rpt);
409
+ else
410
+ fputs(" ", rpt);
411
+ fputs(rc->buf, rpt);
412
+ fputc('\n', rpt);
413
+ }
414
+
415
fputc('\n', rpt);
416
fputs("Active Branch LRU\n", rpt);
417
fputs("-----------------\n", rpt);
1587
static void read_next_command(void)
1588
{
1589
do {
1566
- if (unread_command_buf)
1590
+ if (unread_command_buf) {
1591
unread_command_buf = 0;
1568
- else
1592
+ if (command_buf.eof)
1593
+ return;
1594
+ } else {
1595
+ struct recent_command *rc;
1596
+
1597
+ command_buf.buf = NULL;
1598
read_line(&command_buf, stdin, '\n');
1570
- } while (!command_buf.eof && command_buf.buf[0] == '#');
1599
+ if (command_buf.eof)
1600
+ return;
1601
+
1602
+ rc = rc_free;
1603
+ if (rc)
1604
+ rc_free = rc->next;
1605
+ else {
1606
+ rc = cmd_hist.next;
1607
+ cmd_hist.next = rc->next;
1608
+ cmd_hist.next->prev = &cmd_hist;
1609
+ free(rc->buf);
1610
+ }
1611
+
1612
+ rc->buf = command_buf.buf;
1613
+ rc->prev = cmd_tail;
1614
+ rc->next = cmd_hist.prev;
1615
+ rc->prev->next = rc;
1616
+ cmd_tail = rc;
1617
+ }
1618
+ } while (command_buf.buf[0] == '#');
1619
}
1620
1621
static void skip_optional_lf()
1648
size_t sz = 8192, term_len = command_buf.len - 5 - 2;
1649
length = 0;
1650
buffer = xmalloc(sz);
1651
+ command_buf.buf = NULL;
1652
for (;;) {
1653
read_line(&command_buf, stdin, '\n');
1654
if (command_buf.eof)
2318
2319
int main(int argc, const char **argv)
2320
{
2272
- int i, show_stats = 1;
2321
+ unsigned int i, show_stats = 1;
2322
2323
git_config(git_default_config);
2324
alloc_objects(object_entry_alloc);
2372
if (i != argc)
2373
usage(fast_import_usage);
2374
2375
+ rc_free = pool_alloc(cmd_save * sizeof(*rc_free));
2376
+ for (i = 0; i < (cmd_save - 1); i++)
2377
+ rc_free[i].next = &rc_free[i + 1];
2378
+ rc_free[cmd_save - 1].next = NULL;
2379
+
2380
prepare_packed_git();
2381
start_packfile();
2382
set_die_routine(die_nicely);