Skip to content

Commit

Permalink
rev-parse: add --shared-index-path to get shared index path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Jun 13, 2014
1 parent a0a9675 commit a76295d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Documentation/git-rev-parse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ print a message to stderr and exit with nonzero status.
--show-toplevel::
Show the absolute path of the top-level directory.

--shared-index-path::
Show the path to the shared index file in split index mode, or
empty if not in split-index mode.

Other Options
~~~~~~~~~~~~~

Expand Down
10 changes: 10 additions & 0 deletions builtin/rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "parse-options.h"
#include "diff.h"
#include "revision.h"
#include "split-index.h"

#define DO_REVS 1
#define DO_NOREV 2
Expand Down Expand Up @@ -775,6 +776,15 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
: "false");
continue;
}
if (!strcmp(arg, "--shared-index-path")) {
if (read_cache() < 0)
die(_("Could not read the index"));
if (the_index.split_index) {
const unsigned char *sha1 = the_index.split_index->base_sha1;
puts(git_path("sharedindex.%s", sha1_to_hex(sha1)));
}
continue;
}
if (starts_with(arg, "--since=")) {
show_datestring("--max-age=", arg+8);
continue;
Expand Down

0 comments on commit a76295d

Please sign in to comment.