[PATCH] Florent Vial: added a hide-diff-in-commit-tab parameter to the cgitrc config file to make displaying of the diff optional in the commit tab.

Vial, Florent florent.vial at intel.com
Fri Sep 9 13:54:13 CEST 2011


Hi,

Please find the patch to make display of the diff optional in the commit tab.

--------------1.7.0.4
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit

---
cgit.c       |    3 +++
cgit.h       |    1 +
cgitrc.5.txt |    4 ++++
cmd.c        |    7 ++++++-
ui-commit.c  |    3 ++-
ui-diff.c    |   25 ++++++++++++++-----------
ui-diff.h    |    2 +-
7 files changed, 31 insertions(+), 14 deletions(-)


--------------1.7.0.4
Content-Type: text/x-patch; name="0001-Florent-Vial-added-a-hide-diff-in-commit-tab-paramet.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="0001-Florent-Vial-added-a-hide-diff-in-commit-tab-paramet.patch"

diff --git a/cgit.c b/cgit.c
index b7807ad..6bcbba8 100644
--- a/cgit.c
+++ b/cgit.c
@@ -252,6 +252,8 @@ void config_cb(const char *name, const char *value)
                               add_mimetype(name + 9, value);
               else if (!strcmp(name, "include"))
                               parse_configfile(expand_macros(value), config_cb);
+             else if (!strcmp(name, "hide-diff-in-commit-tab"))
+                             ctx.cfg.hide_diff_in_commit_tab = atoi(value);
}
 static void querystring_cb(const char *name, const char *value)
@@ -327,6 +329,7 @@ static void prepare_context(struct cgit_context *ctx)
               ctx->cfg.cache_static_ttl = -1;
               ctx->cfg.css = "/cgit.css";
               ctx->cfg.logo = "/cgit.png";
+             ctx->cfg.hide_diff_in_commit_tab = 0;
               ctx->cfg.local_time = 0;
               ctx->cfg.enable_gitweb_owner = 1;
               ctx->cfg.enable_http_clone = 1;
diff --git a/cgit.h b/cgit.h
index bad66f0..c95cf8d 100644
--- a/cgit.h
+++ b/cgit.h
@@ -204,6 +204,7 @@ struct cgit_config {
               int enable_remote_branches;
               int enable_subject_links;
               int enable_tree_linenumbers;
+             int hide_diff_in_commit_tab; /** new parameter to allow the user to configure the behaviour of the commit tab*/
               int local_time;
               int max_atom_items;
               int max_repo_count;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 4721c1e..48393cf 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -164,6 +164,10 @@ header::
               The content of the file specified with this option will be included
               verbatim at the top of all pages. Default value: none.
+hide-diff-in-commit-tab::
+             Flag which, if set to "1", makes cgit print only diffstat information
+             in the commit tab instead of diffstat and diff. Default value: "0".
+
include::
               Name of a configfile to include before the rest of the current config-
               file is parsed. Default value: none. See also: "MACRO EXPANSION".
diff --git a/cmd.c b/cmd.c
index 5a3d157..c69ddbc 100644
--- a/cmd.c
+++ b/cmd.c
@@ -56,7 +56,12 @@ static void commit_fn(struct cgit_context *ctx)
 static void diff_fn(struct cgit_context *ctx)
{
-              cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, 1);
+       /**  This is the real diff function so want the diff controls to be displayed,
+                 as well as the whole diff.
+             */
+             int show_ctrls = 1;
+             int show_fulldiff = 1;
+             cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, show_ctrls, show_fulldiff);
}
 static void info_fn(struct cgit_context *ctx)
diff --git a/ui-commit.c b/ui-commit.c
index 536a8e8..237e26a 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -21,6 +21,7 @@ void cgit_print_commit(char *hex, const char *prefix)
               unsigned char sha1[20];
               char *tmp, *tmp2;
               int parents = 0;
+             int show_full_diff = ctx.cfg.hide_diff_in_commit_tab == 0 ? 1 : 0;
                if (!hex)
                               hex = ctx.qry.head;
@@ -135,7 +136,7 @@ void cgit_print_commit(char *hex, const char *prefix)
                                               tmp = sha1_to_hex(commit->parents->item->object.sha1);
                               else
                                               tmp = NULL;
-                              cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0);
+                             cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0, show_full_diff);
               }
               strbuf_release(&notes);
               cgit_free_commitinfo(info);
diff --git a/ui-diff.c b/ui-diff.c
index d97a801..4102b5d 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -355,7 +355,7 @@ void cgit_print_diff_ctrls()
}
 void cgit_print_diff(const char *new_rev, const char *old_rev,
-                                   const char *prefix, int show_ctrls)
+                                  const char *prefix, int show_ctrls, int show_full_diff)
{
               enum object_type type;
               unsigned long size;
@@ -403,15 +403,18 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
                cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
-              if (use_ssdiff) {
-                              html("<table summary='ssdiff' class='ssdiff'>");
-              } else {
-                              html("<table summary='diff' class='diff'>");
-                              html("<tr><td>");
+             if (show_full_diff)
+             {
+               if (use_ssdiff) {
+                               html("<table summary='ssdiff' class='ssdiff'>");
+               } else {
+                               html("<table summary='diff' class='diff'>");
+                               html("<tr><td>");
+               }
+               cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix,
+                                             ctx.qry.ignorews);
+               if (!use_ssdiff)
+                               html("</td></tr>");
+               html("</table>");
               }
-              cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix,
-                                     ctx.qry.ignorews);
-              if (!use_ssdiff)
-                              html("</td></tr>");
-              html("</table>");
}
diff --git a/ui-diff.h b/ui-diff.h
index 0161ffb..797cd70 100644
--- a/ui-diff.h
+++ b/ui-diff.h
@@ -7,7 +7,7 @@ extern void cgit_print_diffstat(const unsigned char *old_sha1,
                                                               const unsigned char *new_sha1);
 extern void cgit_print_diff(const char *new_hex, const char *old_hex,
-                                                  const char *prefix, int show_ctrls);
+                                                 const char *prefix, int show_ctrls, int show_full_diff);
 extern struct diff_filespec *cgit_get_current_old_file(void);
extern struct diff_filespec *cgit_get_current_new_file(void);

--------------1.7.0.4--





More information about the CGit mailing list