summaryrefslogtreecommitdiff
path: root/csvncgi/ui-diff.c
diff options
context:
space:
mode:
authorkx <kx@radix.pro>2023-03-24 03:55:33 +0300
committerkx <kx@radix.pro>2023-03-24 03:55:33 +0300
commitbfc1508d26c89c9a36d2d9a827fe2c4ed128884d (patch)
tree8d41298a7072a3e289e4912f77ece75cbea1bd54 /csvncgi/ui-diff.c
parentc836ae3775cf72f17e0b7e3792d156fdb389bee3 (diff)
downloadcsvn-ui-bfc1508d26c89c9a36d2d9a827fe2c4ed128884d.tar.xz
Version 0.1.4
Diffstat (limited to 'csvncgi/ui-diff.c')
-rw-r--r--csvncgi/ui-diff.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/csvncgi/ui-diff.c b/csvncgi/ui-diff.c
new file mode 100644
index 0000000..7851f00
--- /dev/null
+++ b/csvncgi/ui-diff.c
@@ -0,0 +1,137 @@
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/sysinfo.h>
+#include <sys/types.h>
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#else
+#include <stdint.h>
+#endif
+#include <stddef.h> /* offsetof(3) */
+#include <dirent.h>
+#include <sys/stat.h> /* chmod(2) */
+#include <sys/file.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <string.h> /* strdup(3) */
+#include <libgen.h> /* basename(3) */
+#include <ctype.h> /* tolower(3) */
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+#include <pwd.h>
+#include <grp.h>
+#include <stdarg.h>
+#include <locale.h>
+#include <unistd.h>
+
+#include <nls.h>
+
+#include <defs.h>
+
+#include <fatal.h>
+#include <http.h>
+#include <html.h>
+
+#include <dlist.h>
+#include <strbuf.h>
+#include <repolist.h>
+#include <wrapper.h>
+#include <system.h>
+#include <date.h>
+
+#include <ctx.h>
+#include <ui-shared.h>
+
+
+static void csvn_print_diff( struct strbuf *sb, const char *relative_path, int revision )
+{
+ const char *co_prefix = ctx.repo.checkout_ro_prefix;
+ const char *repo_path = ctx.repo.name;
+
+ if( !sb || !relative_path || !revision ) return;
+
+ strbuf_addf( sb, "<pre><code class='language-Diff'>" );
+
+ if( co_prefix )
+ {
+ char cmd[1024];
+ struct strbuf buf = STRBUF_INIT;
+ char *raw = NULL;
+ pid_t p = (pid_t) -1;
+ int rc;
+
+ snprintf( (char *)&cmd[0], 1024,
+ "svn diff --revision %d:%d %s/%s/%s 2>/dev/null",
+ revision-1, revision, co_prefix, repo_path, relative_path );
+ p = sys_exec_command( &buf, cmd );
+ rc = sys_wait_command( p, NULL );
+ if( rc != 0 )
+ {
+ strbuf_release( &buf );
+ return;
+ }
+
+ raw = strbuf_detach( &buf, NULL );
+ strbuf_addstr_xml_quoted( &buf, (const char *)raw );
+ free( raw );
+
+ strbuf_addbuf( sb, (const struct strbuf *)&buf );
+ strbuf_release( &buf );
+ }
+
+ strbuf_addstr( sb, "\n</code></pre>\n" );
+
+ return;
+}
+
+void csvn_print_diff_page( void )
+{
+ FILE *fp;
+ struct strbuf buf = STRBUF_INIT;
+
+ fp = xfopen( ctx.page.header, "r" );
+ (void)strbuf_env_fread( &buf, fp );
+ fclose( fp );
+
+ strbuf_addf( &buf, " <div class=\"content segment\">\n" );
+ strbuf_addf( &buf, " <div class=\"container\">\n" );
+ strbuf_addf( &buf, " <div class=\"csvn-main-content\">\n" );
+
+ if( ctx.repo.name )
+ {
+ if( ctx.query.rev )
+ {
+ csvn_print_diff( &buf, ctx.repo.relative_path, ctx.query.rev );
+ }
+ else
+ {
+ strbuf_addf( &buf, " <h1>Requested diff cannot be shown</h1>\n" );
+ strbuf_addf( &buf, " <p class='leading'>Revision for diff operation is not defined.</p>\n" );
+ }
+ }
+ else
+ {
+ strbuf_addf( &buf, " <h1>Requested resource cannot be shown</h1>\n" );
+ strbuf_addf( &buf, " <p class='leading'>Repository '%s' not found.</p>\n", ctx.repo.name );
+ }
+
+ strbuf_addf( &buf, " </div> <!-- End of csvn-main-content -->\n" );
+ strbuf_addf( &buf, " </div> <!-- End of container -->\n" );
+ strbuf_addf( &buf, " </div> <!-- End of content segment -->\n" );
+
+ fp = xfopen( ctx.page.footer, "r" );
+ (void)strbuf_env_fread( &buf, fp );
+ fclose( fp );
+
+ ctx.page.size = buf.len;
+ csvn_print_http_headers();
+ strbuf_write( &buf, STDOUT_FILENO );
+ strbuf_release( &buf );
+}