11
#include "exec_cmd.h"
12
13
static const char index_pack_usage[] =
14
-"git index-pack [-v] [-o <index-file>] [ --keep | --keep=<msg> ] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
14
+"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
15
16
struct object_entry
17
{
891
return git_default_config(k, v, cb);
892
}
893
894
+static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
895
+{
896
+ struct packed_git *p = add_packed_git(pack_name, strlen(pack_name), 1);
897
+
898
+ if (!p)
899
+ die("Cannot open existing pack file '%s'", pack_name);
900
+ if (open_pack_index(p))
901
+ die("Cannot open existing pack idx file for '%s'", pack_name);
902
+
903
+ /* Read the attributes from the existing idx file */
904
+ opts->version = p->index_version;
905
+
906
+ /*
907
+ * Get rid of the idx file as we do not need it anymore.
908
+ * NEEDSWORK: extract this bit from free_pack_by_name() in
909
+ * sha1_file.c, perhaps? It shouldn't matter very much as we
910
+ * know we haven't installed this pack (hence we never have
911
+ * read anything from it).
912
+ */
913
+ close_pack_index(p);
914
+ free(p);
915
+}
916
+
917
int cmd_index_pack(int argc, const char **argv, const char *prefix)
918
{
896
- int i, fix_thin_pack = 0;
919
+ int i, fix_thin_pack = 0, verify = 0;
920
const char *curr_pack, *curr_index;
921
const char *index_name = NULL, *pack_name = NULL;
922
const char *keep_name = NULL, *keep_msg = NULL;
945
fix_thin_pack = 1;
946
} else if (!strcmp(arg, "--strict")) {
947
strict = 1;
948
+ } else if (!strcmp(arg, "--verify")) {
949
+ verify = 1;
950
} else if (!strcmp(arg, "--keep")) {
951
keep_msg = "";
952
} else if (!prefixcmp(arg, "--keep=")) {
1013
strcpy(keep_name_buf + len - 5, ".keep");
1014
keep_name = keep_name_buf;
1015
}
1016
+ if (verify) {
1017
+ if (!index_name)
1018
+ die("--verify with no packfile name given");
1019
+ read_idx_option(&opts, index_name);
1020
+ opts.flags |= WRITE_IDX_VERIFY;
1021
+ }
1022
1023
curr_pack = open_pack_file(pack_name);
1024
parse_pack_header();
1069
curr_index = write_idx_file(index_name, idx_objects, nr_objects, &opts, pack_sha1);
1070
free(idx_objects);
1071
1041
- final(pack_name, curr_pack,
1042
- index_name, curr_index,
1043
- keep_name, keep_msg,
1044
- pack_sha1);
1072
+ if (!verify)
1073
+ final(pack_name, curr_pack,
1074
+ index_name, curr_index,
1075
+ keep_name, keep_msg,
1076
+ pack_sha1);
1077
+ else
1078
+ close(input_fd);
1079
free(objects);
1080
free(index_name_buf);
1081
free(keep_name_buf);