Merge branch 'tb/repack-fix-renames' (early part)
authorJunio C Hamano <gitster@pobox.com>
Wed, 5 Feb 2014 20:02:29 +0000 (12:02 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Feb 2014 20:02:29 +0000 (12:02 -0800)
Finishing touches to the "rewrite repack in C" series.

* 'tb/repack-fix-renames' (early part):
repack.c: rename and unlink pack file if it exists

1  2 
builtin/repack.c
diff --combined builtin/repack.c
index 6284846d82653ed170a16b12988b133f681fdd01,fe315772d80fd0c1d22b0401a3f62799e0a09617..bb2314c9cb0ce3e01372c6c3a27396931c0143ab
@@@ -78,7 -78,7 +78,7 @@@ static void get_non_kept_pack_filenames
                return;
  
        while ((e = readdir(dir)) != NULL) {
 -              if (suffixcmp(e->d_name, ".pack"))
 +              if (!ends_with(e->d_name, ".pack"))
                        continue;
  
                len = strlen(e->d_name) - strlen(".pack");
@@@ -123,7 -123,7 +123,7 @@@ int cmd_repack(int argc, const char **a
        struct string_list rollback = STRING_LIST_INIT_NODUP;
        struct string_list existing_packs = STRING_LIST_INIT_DUP;
        struct strbuf line = STRBUF_INIT;
 -      int nr_packs, ext, ret, failed;
 +      int ext, ret, failed;
        FILE *out;
  
        /* variables to be filled by option parsing */
        if (ret)
                return ret;
  
 -      nr_packs = 0;
        out = xfdopen(cmd.out, "r");
        while (strbuf_getline(&line, out, '\n') != EOF) {
                if (line.len != 40)
                        die("repack: Expecting 40 character sha1 lines only from pack-objects.");
                string_list_append(&names, line.buf);
 -              nr_packs++;
        }
        fclose(out);
        ret = finish_command(&cmd);
                return ret;
        argv_array_clear(&cmd_args);
  
 -      if (!nr_packs && !quiet)
 +      if (!names.nr && !quiet)
                printf("Nothing new to pack.\n");
  
        /*
        for_each_string_list_item(item, &names) {
                for (ext = 0; ext < 2; ext++) {
                        char *fname, *fname_old;
-                       fname = mkpathdup("%s/%s%s", packdir,
+                       fname = mkpathdup("%s/pack-%s%s", packdir,
                                                item->string, exts[ext]);
                        if (!file_exists(fname)) {
                                free(fname);
        for_each_string_list_item(item, &names) {
                for (ext = 0; ext < 2; ext++) {
                        char *fname;
-                       fname = mkpath("%s/old-pack-%s%s",
+                       fname = mkpath("%s/old-%s%s",
                                        packdir,
                                        item->string,
                                        exts[ext]);