]> granicus.if.org Git - cgit/commitdiff
struct cgit_cmd: Differentiate between various usages of ctx.qry.path
authorJohan Herland <johan@herland.net>
Wed, 9 Jun 2010 23:09:26 +0000 (01:09 +0200)
committerLars Hjemli <hjemli@gmail.com>
Sat, 19 Jun 2010 08:40:22 +0000 (10:40 +0200)
For many commands/pages (e.g. 'tree', 'diff', 'plain', etc.), the
ctx.qry.path argument is interpreted as a path within the "virtual" project
directory structure. However, for some other commands (notably 'refs', and
the clone-related commands) ctx.qry.path is used in a different context (as
a more or less "real" path within the '.git' directory).

This patch differentiates between these two usages of ctx.qry.path, by
introducing a new variable - ctx.qry.vpath - which is equal to ctx.qry.path
in the former case, and NULL in the latter.

This will become useful in future patches when we want various pages and the
links between them to preserve existing in-project paths.

Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
cgit.c
cgit.h
cmd.c
cmd.h

diff --git a/cgit.c b/cgit.c
index 9305d0a873a191e730d622d14067a2eee56003a6..2c3ad73e064b556a23629194b9ca0a0a696186ee 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -424,6 +424,12 @@ static void process_request(void *cbdata)
                return;
        }
 
+       /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual"
+        * in-project path limit to be made available at ctx->qry.vpath.
+        * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL).
+        */
+       ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL;
+
        if (cmd->want_repo && !ctx->repo) {
                cgit_print_http_headers(ctx);
                cgit_print_docstart(ctx);
diff --git a/cgit.h b/cgit.h
index cd4af7247b7c00dd9562917d2df94472d2e1317e..f990b1506e29cdc10e89697041da06959319fdaa 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -145,6 +145,7 @@ struct cgit_query {
        char *sort;
        int showmsg;
        int ssdiff;
+       char *vpath;
 };
 
 struct cgit_config {
diff --git a/cmd.c b/cmd.c
index 766f90397b89d2407574f3e2bf7056df68b43add..a9e426a9a223add80d990886936b5d42be8cef85 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -129,31 +129,31 @@ static void tree_fn(struct cgit_context *ctx)
        cgit_print_tree(ctx->qry.sha1, ctx->qry.path);
 }
 
-#define def_cmd(name, want_repo, want_layout) \
-       {#name, name##_fn, want_repo, want_layout}
+#define def_cmd(name, want_repo, want_layout, want_vpath) \
+       {#name, name##_fn, want_repo, want_layout, want_vpath}
 
 struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx)
 {
        static struct cgit_cmd cmds[] = {
-               def_cmd(HEAD, 1, 0),
-               def_cmd(atom, 1, 0),
-               def_cmd(about, 0, 1),
-               def_cmd(blob, 1, 0),
-               def_cmd(commit, 1, 1),
-               def_cmd(diff, 1, 1),
-               def_cmd(info, 1, 0),
-               def_cmd(log, 1, 1),
-               def_cmd(ls_cache, 0, 0),
-               def_cmd(objects, 1, 0),
-               def_cmd(patch, 1, 0),
-               def_cmd(plain, 1, 0),
-               def_cmd(refs, 1, 1),
-               def_cmd(repolist, 0, 0),
-               def_cmd(snapshot, 1, 0),
-               def_cmd(stats, 1, 1),
-               def_cmd(summary, 1, 1),
-               def_cmd(tag, 1, 1),
-               def_cmd(tree, 1, 1),
+               def_cmd(HEAD, 1, 0, 0),
+               def_cmd(atom, 1, 0, 0),
+               def_cmd(about, 0, 1, 0),
+               def_cmd(blob, 1, 0, 0),
+               def_cmd(commit, 1, 1, 1),
+               def_cmd(diff, 1, 1, 1),
+               def_cmd(info, 1, 0, 0),
+               def_cmd(log, 1, 1, 1),
+               def_cmd(ls_cache, 0, 0, 0),
+               def_cmd(objects, 1, 0, 0),
+               def_cmd(patch, 1, 0, 1),
+               def_cmd(plain, 1, 0, 0),
+               def_cmd(refs, 1, 1, 0),
+               def_cmd(repolist, 0, 0, 0),
+               def_cmd(snapshot, 1, 0, 0),
+               def_cmd(stats, 1, 1, 1),
+               def_cmd(summary, 1, 1, 0),
+               def_cmd(tag, 1, 1, 0),
+               def_cmd(tree, 1, 1, 1),
        };
        int i;
 
diff --git a/cmd.h b/cmd.h
index ec9e6915dec2bd59afccd242c42b19bc44a0c20a..8dc01bd32b6c22d3426310a916ff5dabd2f0aa88 100644 (file)
--- a/cmd.h
+++ b/cmd.h
@@ -7,7 +7,8 @@ struct cgit_cmd {
        const char *name;
        cgit_cmd_fn fn;
        unsigned int want_repo:1,
-               want_layout:1;
+               want_layout:1,
+               want_vpath:1;
 };
 
 extern struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx);