Converted fast-import to accept standard command line parameters.
authorShawn O. Pearce <spearce@spearce.org>
Wed, 23 Aug 2006 06:00:31 +0000 (02:00 -0400)
committerShawn O. Pearce <spearce@spearce.org>
Sun, 14 Jan 2007 07:15:05 +0000 (02:15 -0500)
The following command line options are now accepted before the
pack name:

--objects=n # replaces the object count after the pack name
--depth=n # delta chain depth to use (default is 10)
--active-branches=n # maximum number of branches to keep in memory

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
fast-import.c
index 4c2431f0b0b7ee017d108e6bd2af8e4f52bffdbb..8598493651d8ead3a586c2be1eca0fe27fdb3348 100644 (file)
@@ -178,7 +178,7 @@ struct branch
 
 
 /* Stats and misc. counters */
-static int max_depth = 10;
+static unsigned long max_depth = 10;
 static unsigned long alloc_count;
 static unsigned long branch_count;
 static unsigned long object_count;
@@ -216,9 +216,9 @@ static unsigned int avail_tree_table_sz = 100;
 static struct avail_tree_content **avail_tree_table;
 
 /* Branch data */
-static unsigned int max_active_branches = 5;
-static unsigned int cur_active_branches;
-static unsigned int branch_table_sz = 1039;
+static unsigned long max_active_branches = 5;
+static unsigned long cur_active_branches;
+static unsigned long branch_table_sz = 1039;
 static struct branch **branch_table;
 static struct branch *active_branches;
 
@@ -1236,10 +1236,14 @@ static void cmd_new_branch()
                die("An lf did not terminate the branch command as expected.");
 }
 
+static const char fast_import_usage[] =
+"git-fast-import [--objects=n] [--depth=n] [--active-branches=n] temp.pack";
+
 int main(int argc, const char **argv)
 {
-       const char *base_name = argv[1];
-       int est_obj_cnt = atoi(argv[2]);
+       const char *base_name;
+       int i;
+       unsigned long est_obj_cnt = 1000;
        char *pack_name;
        char *idx_name;
        struct stat sb;
@@ -1247,6 +1251,24 @@ int main(int argc, const char **argv)
        setup_ident();
        git_config(git_default_config);
 
+       for (i = 1; i < argc; i++) {
+               const char *a = argv[i];
+
+               if (*a != '-' || !strcmp(a, "--"))
+                       break;
+               else if (!strncmp(a, "--objects=", 10))
+                       est_obj_cnt = strtoul(a + 10, NULL, 0);
+               else if (!strncmp(a, "--depth=", 8))
+                       max_depth = strtoul(a + 8, NULL, 0);
+               else if (!strncmp(a, "--active-branches=", 18))
+                       max_active_branches = strtoul(a + 18, NULL, 0);
+               else
+                       die("unknown option %s", a);
+       }
+       if ((i+1) != argc)
+               usage(fast_import_usage);
+       base_name = argv[i];
+
        pack_name = xmalloc(strlen(base_name) + 6);
        sprintf(pack_name, "%s.pack", base_name);
        idx_name = xmalloc(strlen(base_name) + 5);