Merge branch 'se/rev-parse'
* se/rev-parse: Add "--branches", "--tags" and "--remotes" options to git-rev-parse.
This commit is contained in:
commit
3aece89fa2
@ -67,6 +67,15 @@ OPTIONS
|
|||||||
--all::
|
--all::
|
||||||
Show all refs found in `$GIT_DIR/refs`.
|
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::
|
--show-prefix::
|
||||||
When the command is invoked from a subdirectory, show the
|
When the command is invoked from a subdirectory, show the
|
||||||
path of the current directory relative to the top-level
|
path of the current directory relative to the top-level
|
||||||
|
@ -82,8 +82,7 @@ done
|
|||||||
|
|
||||||
case "$#" in
|
case "$#" in
|
||||||
0)
|
0)
|
||||||
git-rev-parse --symbolic --all |
|
git-rev-parse --symbolic --branches |
|
||||||
sed -ne 's|^refs/heads/||p' |
|
|
||||||
sort |
|
sort |
|
||||||
while read ref
|
while read ref
|
||||||
do
|
do
|
||||||
|
23
refs.c
23
refs.c
@ -114,7 +114,7 @@ int read_ref(const char *filename, unsigned char *sha1)
|
|||||||
return -1;
|
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;
|
int retval = 0;
|
||||||
DIR *dir = opendir(git_path("%s", base));
|
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)
|
if (stat(git_path("%s", path), &st) < 0)
|
||||||
continue;
|
continue;
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
retval = do_for_each_ref(path, fn);
|
retval = do_for_each_ref(path, fn, trim);
|
||||||
if (retval)
|
if (retval)
|
||||||
break;
|
break;
|
||||||
continue;
|
continue;
|
||||||
@ -160,7 +160,7 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u
|
|||||||
"commit object!", path);
|
"commit object!", path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
retval = fn(path, sha1);
|
retval = fn(path + trim, sha1);
|
||||||
if (retval)
|
if (retval)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -180,7 +180,22 @@ int head_ref(int (*fn)(const char *path, const unsigned char *sha1))
|
|||||||
|
|
||||||
int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1))
|
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)
|
static char *ref_file_name(const char *ref)
|
||||||
|
3
refs.h
3
refs.h
@ -7,6 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
extern int head_ref(int (*fn)(const char *path, const unsigned char *sha1));
|
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_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 **/
|
/** Reads the refs file specified into sha1 **/
|
||||||
extern int get_ref_sha1(const char *ref, unsigned char *sha1);
|
extern int get_ref_sha1(const char *ref, unsigned char *sha1);
|
||||||
|
17
rev-parse.c
17
rev-parse.c
@ -36,6 +36,7 @@ static int is_rev_argument(const char *arg)
|
|||||||
"--all",
|
"--all",
|
||||||
"--bisect",
|
"--bisect",
|
||||||
"--dense",
|
"--dense",
|
||||||
|
"--branches",
|
||||||
"--header",
|
"--header",
|
||||||
"--max-age=",
|
"--max-age=",
|
||||||
"--max-count=",
|
"--max-count=",
|
||||||
@ -45,7 +46,9 @@ static int is_rev_argument(const char *arg)
|
|||||||
"--objects-edge",
|
"--objects-edge",
|
||||||
"--parents",
|
"--parents",
|
||||||
"--pretty",
|
"--pretty",
|
||||||
|
"--remotes",
|
||||||
"--sparse",
|
"--sparse",
|
||||||
|
"--tags",
|
||||||
"--topo-order",
|
"--topo-order",
|
||||||
"--date-order",
|
"--date-order",
|
||||||
"--unpacked",
|
"--unpacked",
|
||||||
@ -165,7 +168,7 @@ int main(int argc, char **argv)
|
|||||||
int i, as_is = 0, verify = 0;
|
int i, as_is = 0, verify = 0;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
const char *prefix = setup_git_directory();
|
const char *prefix = setup_git_directory();
|
||||||
|
|
||||||
git_config(git_default_config);
|
git_config(git_default_config);
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
@ -255,6 +258,18 @@ int main(int argc, char **argv)
|
|||||||
for_each_ref(show_reference);
|
for_each_ref(show_reference);
|
||||||
continue;
|
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 (!strcmp(arg, "--show-prefix")) {
|
||||||
if (prefix)
|
if (prefix)
|
||||||
puts(prefix);
|
puts(prefix);
|
||||||
|
Loading…
Reference in New Issue
Block a user