summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 975bf9c)
raw | patch | inline | side by side (parent: 975bf9c)
author | Sean <seanlkml@sympatico.ca> | |
Sun, 14 May 2006 01:43:00 +0000 (21:43 -0400) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 14 May 2006 23:21:02 +0000 (16:21 -0700) |
"git branch" uses "rev-parse --all" and becomes much too slow when
there are many tags (it scans all refs). Use the new "--branches"
option of rev-parse to speed things up.
Signed-off-by: Sean Estabrooks <seanlkml@sympatico.ca>
Signed-off-by: Junio C Hamano <junkio@cox.net>
there are many tags (it scans all refs). Use the new "--branches"
option of rev-parse to speed things up.
Signed-off-by: Sean Estabrooks <seanlkml@sympatico.ca>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/git-rev-parse.txt | patch | blob | history | |
git-branch.sh | patch | blob | history | |
refs.c | patch | blob | history | |
refs.h | patch | blob | history | |
rev-parse.c | patch | blob | history |
index 8b95df0c6e2a147cd89fdb20605896852085cbc5..ab896fcf8353475ae3bf14b2c442ce49f1720530 100644 (file)
--all::
Show all refs found in `$GIT_DIR/refs`.
+--branches::
+ Show branch refs found in `$GIT_DIR/refs/heads`.
+
+--tags::
+ Show tag refs found in `$GIT_DIR/refs/tags`.
+
+--remotes::
+ Show tag refs found in `$GIT_DIR/refs/remotes`.
+
--show-prefix::
When the command is invoked from a subdirectory, show the
path of the current directory relative to the top-level
diff --git a/git-branch.sh b/git-branch.sh
index ebcc8989d8cfd9d64f0e4cacd0a0ff76f50d1345..134e68cf7f0389d73af000c4303c4dda27f89d57 100755 (executable)
--- a/git-branch.sh
+++ b/git-branch.sh
case "$#" in
0)
- git-rev-parse --symbolic --all |
- sed -ne 's|^refs/heads/||p' |
+ git-rev-parse --symbolic --branches |
sort |
while read ref
do
index 275b914b2b4cd17f26e85ab1ca5b32ea573acab4..6c91ae6468f859897a358ebd97f4143e44cda874 100644 (file)
--- a/refs.c
+++ b/refs.c
return -1;
}
-static int do_for_each_ref(const char *base, int (*fn)(const char *path, const unsigned char *sha1))
+static int do_for_each_ref(const char *base, int (*fn)(const char *path, const unsigned char *sha1), int trim)
{
int retval = 0;
DIR *dir = opendir(git_path("%s", base));
@@ -146,7 +146,7 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u
if (stat(git_path("%s", path), &st) < 0)
continue;
if (S_ISDIR(st.st_mode)) {
- retval = do_for_each_ref(path, fn);
+ retval = do_for_each_ref(path, fn, trim);
if (retval)
break;
continue;
@@ -160,7 +160,7 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u
"commit object!", path);
continue;
}
- retval = fn(path, sha1);
+ retval = fn(path + trim, sha1);
if (retval)
break;
}
int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1))
{
- return do_for_each_ref("refs", fn);
+ return do_for_each_ref("refs", fn, 0);
+}
+
+int for_each_tag_ref(int (*fn)(const char *path, const unsigned char *sha1))
+{
+ return do_for_each_ref("refs/tags", fn, 10);
+}
+
+int for_each_branch_ref(int (*fn)(const char *path, const unsigned char *sha1))
+{
+ return do_for_each_ref("refs/heads", fn, 11);
+}
+
+int for_each_remote_ref(int (*fn)(const char *path, const unsigned char *sha1))
+{
+ return do_for_each_ref("refs/remotes", fn, 13);
}
static char *ref_file_name(const char *ref)
index 26255967013c7fa4086681bba7636efb4b0157ec..fa816c1e9f58ca1ab1c1b434b01786a0f3b0a41e 100644 (file)
--- a/refs.h
+++ b/refs.h
*/
extern int head_ref(int (*fn)(const char *path, const unsigned char *sha1));
extern int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1));
+extern int for_each_tag_ref(int (*fn)(const char *path, const unsigned char *sha1));
+extern int for_each_branch_ref(int (*fn)(const char *path, const unsigned char *sha1));
+extern int for_each_remote_ref(int (*fn)(const char *path, const unsigned char *sha1));
/** Reads the refs file specified into sha1 **/
extern int get_ref_sha1(const char *ref, unsigned char *sha1);
diff --git a/rev-parse.c b/rev-parse.c
index 62e16af33c29ddd6a9c8b2d9755dc11804d86bc4..4e2d9fbdf6f86e5d2ff28984861d443ca4cdc656 100644 (file)
--- a/rev-parse.c
+++ b/rev-parse.c
"--all",
"--bisect",
"--dense",
+ "--branches",
"--header",
"--max-age=",
"--max-count=",
"--objects-edge",
"--parents",
"--pretty",
+ "--remotes",
"--sparse",
+ "--tags",
"--topo-order",
"--date-order",
"--unpacked",
int i, as_is = 0, verify = 0;
unsigned char sha1[20];
const char *prefix = setup_git_directory();
-
+
git_config(git_default_config);
for (i = 1; i < argc; i++) {
for_each_ref(show_reference);
continue;
}
+ if (!strcmp(arg, "--branches")) {
+ for_each_branch_ref(show_reference);
+ continue;
+ }
+ if (!strcmp(arg, "--tags")) {
+ for_each_tag_ref(show_reference);
+ continue;
+ }
+ if (!strcmp(arg, "--remotes")) {
+ for_each_remote_ref(show_reference);
+ continue;
+ }
if (!strcmp(arg, "--show-prefix")) {
if (prefix)
puts(prefix);