@matheusbsbs / matheus-bagliano / commits / dc01f59d21
Fork 0

fast-import: treat SIGUSR1 as a request to access objects early

It can be tedious to wait for a multi-million-revision import. Unfortunately it is hard to spy on the import because fast-import works by continuously streaming out objects, without updating the pack index or refs until a checkpoint command or the end of the stream. So allow the impatient operator to request checkpoints by sending a signal, like so: killall -USR1 git-fast-import When receiving such a signal, fast-import would schedule a checkpoint to take place after the current top-level command (usually a "commit" or "blob" request) finishes. Caveats: just like ordinary checkpoint commands, such requests slow down the import. Switching to a new pack at a suboptimal moment is also likely to result in a less dense initial collection of packs. That's the price. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 22, 2010 at 02:16 UTC dc01f59d21fca9ade97f1433ca4cee17b5ce59a7
2 files changed +47 -1
Documentation/git-fast-import.txt
+7
@@ -1233,6 +1233,13 @@ and lazy loading of subtrees, allows fast-import to efficiently import
1233 projects with 2,000+ branches and 45,114+ files in a very limited
1234 memory footprint (less than 2.7 MiB per active branch).
1235
1236 +Signals
1237 +-------
1238 +Sending *SIGUSR1* to the 'git fast-import' process ends the current
1239 +packfile early, simulating a `checkpoint` command. The impatient
1240 +operator can use this facility to peek at the objects and refs from an
1241 +import in progress, at the cost of some added running time and worse
1242 +compression.
1243
1244 Author
1245 ------
fast-import.c
+40 -1
@@ -361,6 +361,9 @@ static uintmax_t next_mark;
361 static struct strbuf new_data = STRBUF_INIT;
362 static int seen_data_command;
363
364 +/* Signal handling */
365 +static volatile sig_atomic_t checkpoint_requested;
366 +
367 static void parse_argv(void);
368
369 static void write_branch_report(FILE *rpt, struct branch *b)
@@ -500,6 +503,32 @@ static NORETURN void die_nicely(const char *err, va_list params)
503 exit(128);
504 }
505
506 +#ifndef SIGUSR1 /* Windows, for example */
507 +
508 +static void set_checkpoint_signal(void)
509 +{
510 +}
511 +
512 +#else
513 +
514 +static void checkpoint_signal(int signo)
515 +{
516 + checkpoint_requested = 1;
517 +}
518 +
519 +static void set_checkpoint_signal(void)
520 +{
521 + struct sigaction sa;
522 +
523 + memset(&sa, 0, sizeof(sa));
524 + sa.sa_handler = checkpoint_signal;
525 + sigemptyset(&sa.sa_mask);
526 + sa.sa_flags = SA_RESTART;
527 + sigaction(SIGUSR1, &sa, NULL);
528 +}
529 +
530 +#endif
531 +
532 static void alloc_objects(unsigned int cnt)
533 {
534 struct object_entry_pool *b;
@@ -2689,14 +2718,20 @@ static void parse_reset_branch(void)
2718 unread_command_buf = 1;
2719 }
2720
2692 -static void parse_checkpoint(void)
2721 +static void checkpoint(void)
2722 {
2723 + checkpoint_requested = 0;
2724 if (object_count) {
2725 cycle_packfile();
2726 dump_branches();
2727 dump_tags();
2728 dump_marks();
2729 }
2730 +}
2731 +
2732 +static void parse_checkpoint(void)
2733 +{
2734 + checkpoint_requested = 1;
2735 skip_optional_lf();
2736 }
2737
@@ -2953,6 +2988,7 @@ int main(int argc, const char **argv)
2988 prepare_packed_git();
2989 start_packfile();
2990 set_die_routine(die_nicely);
2991 + set_checkpoint_signal();
2992 while (read_next_command() != EOF) {
2993 if (!strcmp("blob", command_buf.buf))
2994 parse_new_blob();
@@ -2974,6 +3010,9 @@ int main(int argc, const char **argv)
3010 /* ignore non-git options*/;
3011 else
3012 die("Unsupported command: %s", command_buf.buf);
3013 +
3014 + if (checkpoint_requested)
3015 + checkpoint();
3016 }
3017
3018 /* argv hasn't been parsed yet, do so */