Fossil SCM

Refactor the "repack" command to call extra_deltification() routine directly.

drh 2023-03-02 20:20 trunk
Commit 9c1f486f9da49fdf40791565bd12425c59dba2409b788e02d64e589b67c884cc
1 file changed +30 -13
+30 -13
--- src/rebuild.c
+++ src/rebuild.c
@@ -605,26 +605,43 @@
605605
**
606606
** The name for this command is stolen from the "git repack" command that
607607
** does approximately the same thing in Git.
608608
*/
609609
void repack_command(void){
610
- char *azNewArgv[5];
611
- char **azOldArgv = g.argv;
610
+ i64 nByte = 0;
611
+ int nDelta = 0;
612
+ int runVacuum = 0;
612613
verify_all_options();
613
- if( g.argc!=2 && g.argc!=3 ){
614
+ if( g.argc==3 ){
615
+ db_open_repository(g.argv[2]);
616
+ }else if( g.argc==2 ){
617
+ db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
618
+ if( g.argc!=2 ){
619
+ usage("?REPOSITORY-FILENAME?");
620
+ }
621
+ db_close(1);
622
+ db_open_repository(g.zRepositoryName);
623
+ }else{
614624
usage("?REPOSITORY-FILENAME?");
615625
}
616
- azNewArgv[0] = g.argv[0];
617
- azNewArgv[1] = "rebuild";
618
- azNewArgv[2] = "--compress-only";
619
- azNewArgv[3] = g.argv[2];
620
- azNewArgv[4] = 0;
621
- g.argc++;
622
- g.argv = azNewArgv;
623
- rebuild_database();
624
- g.argc--;
625
- g.argv = azOldArgv;
626
+ db_unprotect(PROTECT_ALL);
627
+ nByte = extra_deltification(&nDelta);
628
+ if( nDelta>0 ){
629
+ if( nDelta==1 ){
630
+ fossil_print("1 new delta saves %,lld bytes\n", nByte);
631
+ }else{
632
+ fossil_print("%d new deltas save %,lld bytes\n", nDelta, nByte);
633
+ }
634
+ runVacuum = 1;
635
+ }else{
636
+ fossil_print("no new compression opportunities found\n");
637
+ }
638
+ if( runVacuum ){
639
+ fossil_print("Vacuuming the database... "); fflush(stdout);
640
+ db_multi_exec("VACUUM");
641
+ fossil_print("done\n");
642
+ }
626643
}
627644
628645
629646
/*
630647
** COMMAND: rebuild
631648
--- src/rebuild.c
+++ src/rebuild.c
@@ -605,26 +605,43 @@
605 **
606 ** The name for this command is stolen from the "git repack" command that
607 ** does approximately the same thing in Git.
608 */
609 void repack_command(void){
610 char *azNewArgv[5];
611 char **azOldArgv = g.argv;
 
612 verify_all_options();
613 if( g.argc!=2 && g.argc!=3 ){
 
 
 
 
 
 
 
 
 
614 usage("?REPOSITORY-FILENAME?");
615 }
616 azNewArgv[0] = g.argv[0];
617 azNewArgv[1] = "rebuild";
618 azNewArgv[2] = "--compress-only";
619 azNewArgv[3] = g.argv[2];
620 azNewArgv[4] = 0;
621 g.argc++;
622 g.argv = azNewArgv;
623 rebuild_database();
624 g.argc--;
625 g.argv = azOldArgv;
 
 
 
 
 
 
 
626 }
627
628
629 /*
630 ** COMMAND: rebuild
631
--- src/rebuild.c
+++ src/rebuild.c
@@ -605,26 +605,43 @@
605 **
606 ** The name for this command is stolen from the "git repack" command that
607 ** does approximately the same thing in Git.
608 */
609 void repack_command(void){
610 i64 nByte = 0;
611 int nDelta = 0;
612 int runVacuum = 0;
613 verify_all_options();
614 if( g.argc==3 ){
615 db_open_repository(g.argv[2]);
616 }else if( g.argc==2 ){
617 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
618 if( g.argc!=2 ){
619 usage("?REPOSITORY-FILENAME?");
620 }
621 db_close(1);
622 db_open_repository(g.zRepositoryName);
623 }else{
624 usage("?REPOSITORY-FILENAME?");
625 }
626 db_unprotect(PROTECT_ALL);
627 nByte = extra_deltification(&nDelta);
628 if( nDelta>0 ){
629 if( nDelta==1 ){
630 fossil_print("1 new delta saves %,lld bytes\n", nByte);
631 }else{
632 fossil_print("%d new deltas save %,lld bytes\n", nDelta, nByte);
633 }
634 runVacuum = 1;
635 }else{
636 fossil_print("no new compression opportunities found\n");
637 }
638 if( runVacuum ){
639 fossil_print("Vacuuming the database... "); fflush(stdout);
640 db_multi_exec("VACUUM");
641 fossil_print("done\n");
642 }
643 }
644
645
646 /*
647 ** COMMAND: rebuild
648

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button