ls-tree: work from subdirectory.
[gitweb.git] / rev-parse.c
index 6d723f902aaff806431d5e47916dadba7af18a37..bb4949ad70364abdf7c3bbca357e5ebc42880614 100644 (file)
@@ -6,6 +6,7 @@
 #include "cache.h"
 #include "commit.h"
 #include "refs.h"
+#include "quote.h"
 
 #define DO_REVS                1
 #define DO_NOREV       2
@@ -31,7 +32,9 @@ static int revs_count = 0;
 static int is_rev_argument(const char *arg)
 {
        static const char *rev_args[] = {
+               "--all",
                "--bisect",
+               "--dense",
                "--header",
                "--max-age=",
                "--max-count=",
@@ -42,6 +45,7 @@ static int is_rev_argument(const char *arg)
                "--parents",
                "--pretty",
                "--show-breaks",
+               "--sparse",
                "--topo-order",
                "--unpacked",
                NULL
@@ -125,6 +129,24 @@ static int show_reference(const char *refname, const unsigned char *sha1)
        return 0;
 }
 
+static void show_datestring(const char *flag, const char *datestr)
+{
+       static char buffer[100];
+
+       /* date handling requires both flags and revs */
+       if ((filter & (DO_FLAGS | DO_REVS)) != (DO_FLAGS | DO_REVS))
+               return;
+       snprintf(buffer, sizeof(buffer), "%s%lu", flag, approxidate(datestr));
+       show(buffer);
+}
+
+static void show_file(const char *arg)
+{
+       show_default();
+       if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV))
+               show(arg);
+}
+
 int main(int argc, char **argv)
 {
        int i, as_is = 0, verify = 0;
@@ -136,12 +158,15 @@ int main(int argc, char **argv)
                char *dotdot;
        
                if (as_is) {
-                       show(arg);
+                       show_file(arg);
                        continue;
                }
                if (*arg == '-') {
                        if (!strcmp(arg, "--")) {
                                as_is = 1;
+                               /* Pass on the "--" if we show anything but files.. */
+                               if (filter & (DO_FLAGS | DO_REVS))
+                                       show_file(arg);
                                continue;
                        }
                        if (!strcmp(arg, "--default")) {
@@ -191,6 +216,38 @@ int main(int argc, char **argv)
                                        puts(prefix);
                                continue;
                        }
+                       if (!strcmp(arg, "--git-dir")) {
+                               const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
+                               static char cwd[PATH_MAX];
+                               if (gitdir) {
+                                       puts(gitdir);
+                                       continue;
+                               }
+                               if (!prefix) {
+                                       puts(".git");
+                                       continue;
+                               }
+                               if (!getcwd(cwd, PATH_MAX))
+                                       die("unable to get current working directory");
+                               printf("%s/.git\n", cwd);
+                               continue;
+                       }
+                       if (!strncmp(arg, "--since=", 8)) {
+                               show_datestring("--max-age=", arg+8);
+                               continue;
+                       }
+                       if (!strncmp(arg, "--after=", 8)) {
+                               show_datestring("--max-age=", arg+8);
+                               continue;
+                       }
+                       if (!strncmp(arg, "--before=", 9)) {
+                               show_datestring("--min-age=", arg+9);
+                               continue;
+                       }
+                       if (!strncmp(arg, "--until=", 8)) {
+                               show_datestring("--min-age=", arg+8);
+                               continue;
+                       }
                        if (verify)
                                die("Needed a single revision");
                        show_flag(arg);
@@ -224,9 +281,8 @@ int main(int argc, char **argv)
                }
                if (verify)
                        die("Needed a single revision");
-               if ((filter & (DO_NONFLAGS|DO_NOREV)) ==
-                   (DO_NONFLAGS|DO_NOREV))
-                       show(arg);
+               as_is = 1;
+               show_file(arg);
        }
        show_default();
        if (verify && revs_count != 1)