Skip to content

Commit a76295d

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0a9675 commit a76295d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Documentation/git-rev-parse.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ print a message to stderr and exit with nonzero status.
245245
--show-toplevel::
246246
Show the absolute path of the top-level directory.
247247

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+
248252
Other Options
249253
~~~~~~~~~~~~~
250254

builtin/rev-parse.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "parse-options.h"
1212
#include "diff.h"
1313
#include "revision.h"
14+
#include "split-index.h"
1415

1516
#define DO_REVS 1
1617
#define DO_NOREV 2
@@ -775,6 +776,15 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
775776
: "false");
776777
continue;
777778
}
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+
}
778788
if (starts_with(arg, "--since=")) {
779789
show_datestring("--max-age=", arg+8);
780790
continue;

0 commit comments

Comments
 (0)