Merge branch 'jc/index-pack' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 15 Apr 2016 01:37:15 +0000 (18:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 15 Apr 2016 01:37:16 +0000 (18:37 -0700)
Code clean-up.

* jc/index-pack:
index-pack: add a helper function to derive .idx/.keep filename
index-pack: correct --keep[=<msg>]

1  2 
builtin/index-pack.c
diff --combined builtin/index-pack.c
index 45245199aebafc7fdb8eb96197dacd86c422c413,a5588a24d1c528d5b4e69aece48ead4aee9e3355..2d1eb8bb8a433e6bda50e93e3001ae6d43db093f
@@@ -1514,7 -1514,6 +1514,7 @@@ static void read_v2_anomalous_offsets(s
                if (!(off & 0x80000000))
                        continue;
                off = off & 0x7fffffff;
 +              check_pack_index_ptr(p, &idx2[off * 2]);
                if (idx2[off * 2])
                        continue;
                /*
@@@ -1599,6 -1598,18 +1599,18 @@@ static void show_pack_info(int stat_onl
        }
  }
  
+ static const char *derive_filename(const char *pack_name, const char *suffix,
+                                  struct strbuf *buf)
+ {
+       size_t len;
+       if (!strip_suffix(pack_name, ".pack", &len))
+               die(_("packfile name '%s' does not end with '.pack'"),
+                   pack_name);
+       strbuf_add(buf, pack_name, len);
+       strbuf_addstr(buf, suffix);
+       return buf->buf;
+ }
  int cmd_index_pack(int argc, const char **argv, const char *prefix)
  {
        int i, fix_thin_pack = 0, verify = 0, stat_only = 0;
                usage(index_pack_usage);
        if (fix_thin_pack && !from_stdin)
                die(_("--fix-thin cannot be used without --stdin"));
-       if (!index_name && pack_name) {
-               size_t len;
-               if (!strip_suffix(pack_name, ".pack", &len))
-                       die(_("packfile name '%s' does not end with '.pack'"),
-                           pack_name);
-               strbuf_add(&index_name_buf, pack_name, len);
-               strbuf_addstr(&index_name_buf, ".idx");
-               index_name = index_name_buf.buf;
-       }
-       if (keep_msg && !keep_name && pack_name) {
-               size_t len;
-               if (!strip_suffix(pack_name, ".pack", &len))
-                       die(_("packfile name '%s' does not end with '.pack'"),
-                           pack_name);
-               strbuf_add(&keep_name_buf, pack_name, len);
-               strbuf_addstr(&keep_name_buf, ".idx");
-               keep_name = keep_name_buf.buf;
-       }
+       if (!index_name && pack_name)
+               index_name = derive_filename(pack_name, ".idx", &index_name_buf);
+       if (keep_msg && !keep_name && pack_name)
+               keep_name = derive_filename(pack_name, ".keep", &keep_name_buf);
        if (verify) {
                if (!index_name)
                        die(_("--verify with no packfile name given"));