rev-parse: add --shared-index-path to get shared index path
Normally scripts do not have to be aware about split indexes because all shared indexes are in $GIT_DIR. A simple "mv $tmp_index $GIT_DIR/somewhere" is enough. Scripts that generate temporary indexes and move them across repos must be aware about split index and copy the shared file as well. This option enables that. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jun 13, 2014 at 19:19 UTC
a76295da784501f74803053606112f62ccff3828
2 files changed
+14
Documentation/git-rev-parse.txt
+4
@@ -245,6 +245,10 @@ print a message to stderr and exit with nonzero status.
245
--show-toplevel::
246
Show the absolute path of the top-level directory.
247
248
+--shared-index-path::
249
+ Show the path to the shared index file in split index mode, or
250
+ empty if not in split-index mode.
251
+
252
Other Options
253
~~~~~~~~~~~~~
254
builtin/rev-parse.c
+10
@@ -11,6 +11,7 @@
11
#include "parse-options.h"
12
#include "diff.h"
13
#include "revision.h"
14
+#include "split-index.h"
15
16
#define DO_REVS 1
17
#define DO_NOREV 2
@@ -775,6 +776,15 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
776
: "false");
777
continue;
778
}
779
+ if (!strcmp(arg, "--shared-index-path")) {
780
+ if (read_cache() < 0)
781
+ die(_("Could not read the index"));
782
+ if (the_index.split_index) {
783
+ const unsigned char *sha1 = the_index.split_index->base_sha1;
784
+ puts(git_path("sharedindex.%s", sha1_to_hex(sha1)));
785
+ }
786
+ continue;
787
+ }
788
if (starts_with(arg, "--since=")) {
789
show_datestring("--max-age=", arg+8);
790
continue;