This adds a prefix string to any filename arguments encountered after it
has been specified.

Signed-off-by: John Keeping <j...@keeping.me.uk>
---
 builtin/rev-parse.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index f267a1d..11501a4 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -212,11 +212,12 @@ static void show_datestring(const char *flag, const char 
*datestr)
        show(buffer);
 }
 
-static int show_file(const char *arg)
+static int show_file(const char *arg, const char *prefix)
 {
        show_default();
        if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) {
-               show(arg);
+               size_t prefixlen = prefix ? strlen(prefix) : 0;
+               show(prefix_filename(prefix, prefixlen, arg));
                return 1;
        }
        return 0;
@@ -470,6 +471,7 @@ N_("git rev-parse --parseopt [options] -- [<args>...]\n"
 int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 {
        int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
+       const char *filename_prefix = NULL;
        unsigned char sha1[20];
        const char *name = NULL;
 
@@ -503,7 +505,7 @@ int cmd_rev_parse(int argc, const char **argv, const char 
*prefix)
                const char *arg = argv[i];
 
                if (as_is) {
-                       if (show_file(arg) && as_is < 2)
+                       if (show_file(arg, filename_prefix) && as_is < 2)
                                verify_filename(prefix, arg, 0);
                        continue;
                }
@@ -527,7 +529,7 @@ int cmd_rev_parse(int argc, const char **argv, const char 
*prefix)
                                as_is = 2;
                                /* Pass on the "--" if we show anything but 
files.. */
                                if (filter & (DO_FLAGS | DO_REVS))
-                                       show_file(arg);
+                                       show_file(arg, NULL);
                                continue;
                        }
                        if (!strcmp(arg, "--default")) {
@@ -535,6 +537,11 @@ int cmd_rev_parse(int argc, const char **argv, const char 
*prefix)
                                i++;
                                continue;
                        }
+                       if (!strcmp(arg, "--filename-prefix")) {
+                               filename_prefix = argv[i+1];
+                               i++;
+                               continue;
+                       }
                        if (!strcmp(arg, "--revs-only")) {
                                filter &= ~DO_NOREV;
                                continue;
@@ -754,7 +761,7 @@ int cmd_rev_parse(int argc, const char **argv, const char 
*prefix)
                if (verify)
                        die_no_single_rev(quiet);
                as_is = 1;
-               if (!show_file(arg))
+               if (!show_file(arg, filename_prefix))
                        continue;
                verify_filename(prefix, arg, 1);
        }
-- 
1.8.2.694.ga76e9c3.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to