git.strcat.st

/strcat/sgit.git/ - summarytreelogarchive

subject
restore sgit.c and Makefile from ee3b035
commit
b857b32b505da58ca017790e40b7383d5accf8b3
date
2026-05-28T12:35:15Z
message
diff
 Makefile |   14 -
 sgit.c   | 1564 --------------------------------------------------------------
 2 files changed, 1578 deletions(-)

diff --git a/Makefile b/Makefile
index d1911f4..5e5a7cc 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,3 @@
-<<<<<<< HEAD
-PROG    = sgit
-CFLAGS  = -O2 -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
-LDFLAGS = -static
-
-all: $(PROG)
-
-$(PROG): sgit.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $(PROG) sgit.c
-
-clean:
-	rm -f $(PROG)
-=======
 PROG     = sgit
 CFLAGS   = -O2 -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
 LDFLAGS  = -static
@@ -39,4 +26,3 @@ extras/markdown.o: extras/markdown.c extras/markdown.h
 
 clean:
 	rm -f $(PROG) sgit.o extras/markdown.o
->>>>>>> ee3b035 (init)
diff --git a/sgit.c b/sgit.c
index 9a16338..3f52ac9 100644
--- a/sgit.c
+++ b/sgit.c
@@ -13,45 +13,15 @@
 #include <string.h>
 #include <unistd.h>
 
-<<<<<<< HEAD
-=======
 #ifdef USE_MARKDOWN
 #include "extras/markdown.h"
 #endif
 
->>>>>>> ee3b035 (init)
 #ifndef PATH_MAX
 #define PATH_MAX 4096
 #endif
 
 #define COMMIT_LIMIT 100
-<<<<<<< HEAD
-#define SEP '\x1f'
-
-struct repo {
-	char	*branch;
-	char	*cloneurl;
-	char	*head;
-	char	*last_author;
-	char	*last_date;
-	char	*last_subject;
-	char	*name;
-	char	*owner;
-	char	*outdir;
-	char	*path;
-	char	*rootlink_deep;
-	char	*rootlink_repo;
-	int	 changed;
-};
-
-struct tree_node {
-	struct tree_node **children;
-	char	*name;
-	char	*path;
-	size_t	 cap;
-	size_t	 nchildren;
-	int	 is_dir;
-=======
 #define CACHE_VERSION "2"
 #define SEP '\x1f'
 
@@ -78,7 +48,6 @@ struct tree_node {
   size_t	 cap;
   size_t	 nchildren;
   int	 is_dir;
->>>>>>> ee3b035 (init)
 };
 
 static const char *progname;
@@ -96,33 +65,19 @@ static void	 ensure_parent_dir(const char *);
 static void	 clear_html_files(const char *);
 static void	 free_repos(struct repo *, size_t);
 static char	*join3(const char *, const char *, const char *);
-<<<<<<< HEAD
-static void	 load_repo_meta(struct repo *);
-static void	 make_commit_page(const struct repo *, const char *, const char *,
-	        const char *, const char *, const char *);
-static void	 make_files_page(const struct repo *, const char *);
-=======
 static int	 load_repo_meta(struct repo *);
 static void	 make_commit_page(const struct repo *, const char *, const char *,
           const char *, const char *, const char *);
 static void	 make_files_page(const struct repo *, const char *);
 static char	*repo_gitdir_path(const struct repo *);
->>>>>>> ee3b035 (init)
 static char	*read_git_meta_file(const struct repo *, const char *);
 static void	 make_index(const char *, struct repo *, size_t);
 static void	 make_readme_page(const struct repo *, const char *, int);
 static void	 make_repo_page(const struct repo *);
 static char	*file_page_name(const char *);
 static int	 has_suffix_ci(const char *, const char *);
-<<<<<<< HEAD
-static void	 render_markdown(FILE *, const char *);
-static void	 render_markdown_inline(FILE *, const char *);
-static void	 render_tree(FILE *, const struct repo *, struct tree_node *,
-	        int);
-=======
 static void	 render_tree(FILE *, const struct repo *, struct tree_node *,
           int);
->>>>>>> ee3b035 (init)
 static int	 repo_cmp(const void *, const void *);
 static size_t	 read_blob_size(const struct repo *, const char *);
 static char	*read_cache_head(const char *);
@@ -154,79 +109,6 @@ static char	*write_shell_quoted(const char *);
 int
 main(int argc, char *argv[])
 {
-<<<<<<< HEAD
-	char *argv0;
-	const char *input, *output;
-	const char *raw;
-	struct repo *repos;
-	size_t cap, i, nrepos;
-	int ch, multi;
-
-	argv0 = argv[0];
-	while ((ch = getopt(argc, argv, "")) != -1) {
-	    switch (ch) {
-	    default:
-	        usage();
-	    }
-	}
-	argc -= optind;
-	argv += optind;
-	progname = argv0;
-	raw = getenv("RAW");
-	raw_mode = 0;
-	if (raw != NULL && strcmp(raw, "1") == 0)
-	    raw_mode = 1;
-	if (argc == 0) {
-	    input = "repos";
-	    output = "out";
-	} else if (argc == 2) {
-	    input = argv[0];
-	    output = argv[1];
-	} else
-	    usage();
-
-	repos = NULL;
-	cap = 0;
-	nrepos = 0;
-	discover_repos(input, &repos, &nrepos, &cap);
-	if (nrepos == 0)
-	    errx(1, "no git repositories found in %s", input);
-	qsort(repos, nrepos, sizeof(struct repo), repo_cmp);
-
-	ensure_dir(output);
-	multi = nrepos > 1;
-
-	for (i = 0; i < nrepos; i++) {
-	    if (multi) {
-	        repos[i].outdir = join3(output, "/", repos[i].name);
-	        if (repos[i].outdir == NULL)
-	            err(1, "malloc");
-	    } else {
-	        repos[i].outdir = str_dup(output);
-	        if (repos[i].outdir == NULL)
-	            err(1, "malloc");
-	    }
-	    if (multi) {
-	        repos[i].rootlink_repo = str_dup("../index.html");
-	        repos[i].rootlink_deep = str_dup("../../index.html");
-	    } else {
-	        repos[i].rootlink_repo = str_dup("index.html");
-	        repos[i].rootlink_deep = str_dup("../index.html");
-	    }
-	    if (repos[i].rootlink_repo == NULL || repos[i].rootlink_deep == NULL)
-	        err(1, "malloc");
-	    load_repo_meta(&repos[i]);
-	    repos[i].changed = repo_changed(&repos[i]);
-	    if (repos[i].changed)
-	        make_repo_page(&repos[i]);
-	}
-
-	if (multi)
-	    make_index(output, repos, nrepos);
-
-	free_repos(repos, nrepos);
-	return 0;
-=======
   char *argv0;
   const char *input, *output;
   const char *raw;
@@ -303,39 +185,18 @@ main(int argc, char *argv[])
 
   free_repos(repos, nrepos);
   return 0;
->>>>>>> ee3b035 (init)
 }
 
 static void
 usage(void)
 {
-<<<<<<< HEAD
-	fprintf(stderr, "usage: %s [repos out]\n", progname);
-	exit(1);
-=======
   fprintf(stderr, "usage: %s [repos out]\n", progname);
   exit(1);
->>>>>>> ee3b035 (init)
 }
 
 static void
 warn(const char *fmt, ...)
 {
-<<<<<<< HEAD
-	va_list ap;
-	int saved;
-
-	saved = errno;
-	if (progname != NULL && *progname != '\0')
-		fprintf(stderr, "%s: ", progname);
-	va_start(ap, fmt);
-	if (fmt != NULL && *fmt != '\0')
-		vfprintf(stderr, fmt, ap);
-	else
-		fputs("warning", stderr);
-	va_end(ap);
-	fprintf(stderr, ": %s\n", strerror(saved));
-=======
   va_list ap;
   int saved;
 
@@ -349,26 +210,11 @@ warn(const char *fmt, ...)
     fputs("warning", stderr);
   va_end(ap);
   fprintf(stderr, ": %s\n", strerror(saved));
->>>>>>> ee3b035 (init)
 }
 
 static void
 errx(int eval, const char *fmt, ...)
 {
-<<<<<<< HEAD
-	va_list ap;
-
-	if (progname != NULL && *progname != '\0')
-		fprintf(stderr, "%s: ", progname);
-	va_start(ap, fmt);
-	if (fmt != NULL && *fmt != '\0')
-		vfprintf(stderr, fmt, ap);
-	else
-		fputs("error", stderr);
-	va_end(ap);
-	fputc('\n', stderr);
-	exit(eval);
-=======
   va_list ap;
 
   if (progname != NULL && *progname != '\0')
@@ -381,28 +227,11 @@ errx(int eval, const char *fmt, ...)
   va_end(ap);
   fputc('\n', stderr);
   exit(eval);
->>>>>>> ee3b035 (init)
 }
 
 static void
 err(int eval, const char *fmt, ...)
 {
-<<<<<<< HEAD
-	va_list ap;
-	int saved;
-
-	saved = errno;
-	if (progname != NULL && *progname != '\0')
-		fprintf(stderr, "%s: ", progname);
-	va_start(ap, fmt);
-	if (fmt != NULL && *fmt != '\0')
-		vfprintf(stderr, fmt, ap);
-	else
-		fputs("error", stderr);
-	va_end(ap);
-	fprintf(stderr, ": %s\n", strerror(saved));
-	exit(eval);
-=======
   va_list ap;
   int saved;
 
@@ -417,23 +246,11 @@ err(int eval, const char *fmt, ...)
   va_end(ap);
   fprintf(stderr, ": %s\n", strerror(saved));
   exit(eval);
->>>>>>> ee3b035 (init)
 }
 
 static char *
 str_dup(const char *s)
 {
-<<<<<<< HEAD
-	char *out;
-	size_t len;
-
-	len = strlen(s);
-	out = malloc(len + 1);
-	if (out == NULL)
-	    return NULL;
-	memcpy(out, s, len + 1);
-	return out;
-=======
   char *out;
   size_t len;
 
@@ -443,22 +260,11 @@ str_dup(const char *s)
       return NULL;
   memcpy(out, s, len + 1);
   return out;
->>>>>>> ee3b035 (init)
 }
 
 static char *
 trim_newline(char *s)
 {
-<<<<<<< HEAD
-	size_t len;
-
-	len = strlen(s);
-	while (len > 0 && (s[len - 1] == '\n' || s[len - 1] == '\r')) {
-	    s[len - 1] = '\0';
-	    len--;
-	}
-	return s;
-=======
   size_t len;
 
   len = strlen(s);
@@ -467,24 +273,11 @@ trim_newline(char *s)
       len--;
   }
   return s;
->>>>>>> ee3b035 (init)
 }
 
 static size_t
 text_loc(const char *s)
 {
-<<<<<<< HEAD
-	size_t loc;
-
-	if (*s == '\0')
-	    return 0;
-	loc = 0;
-	for (; *s != '\0'; s++) {
-	    if (*s == '\n')
-	        loc++;
-	}
-	return loc + 1;
-=======
   size_t loc;
 
   if (*s == '\0')
@@ -495,28 +288,11 @@ text_loc(const char *s)
           loc++;
   }
   return loc + 1;
->>>>>>> ee3b035 (init)
 }
 
 static int
 text_content_p(const char *s, size_t nbytes, size_t blob_size)
 {
-<<<<<<< HEAD
-	size_t i;
-	unsigned char c;
-
-	if (nbytes < blob_size)
-	    return 0;
-	for (i = 0; i < nbytes; i++) {
-	    c = (unsigned char)s[i];
-	    if (c == '\n' || c == '\r' || c == '\t')
-	        continue;
-	    if (c >= 0x20 || c >= 0x80)
-	        continue;
-	    return 0;
-	}
-	return 1;
-=======
   size_t i;
   unsigned char c;
 
@@ -531,35 +307,11 @@ text_content_p(const char *s, size_t nbytes, size_t blob_size)
       return 0;
   }
   return 1;
->>>>>>> ee3b035 (init)
 }
 
 static void
 format_size(size_t nbytes, char *buf, size_t buflen)
 {
-<<<<<<< HEAD
-	const char *units[] = { "bytes", "kb", "mb", "gb", "tb", "pb" };
-	double v;
-	size_t i, nunits;
-
-	nunits = sizeof(units) / sizeof(units[0]);
-	if (nbytes < 1024) {
-	    snprintf(buf, buflen, "%lu bytes", (unsigned long)nbytes);
-	    return;
-	}
-	v = (double)nbytes;
-	i = 0;
-	while (v >= 1024.0 && i + 1 < nunits) {
-	    v /= 1024.0;
-	    i++;
-	}
-	if (v >= 100.0)
-	    snprintf(buf, buflen, "%.0f %s", v, units[i]);
-	else if (v >= 10.0)
-	    snprintf(buf, buflen, "%.1f %s", v, units[i]);
-	else
-	    snprintf(buf, buflen, "%.2f %s", v, units[i]);
-=======
   const char *units[] = { "bytes", "kb", "mb", "gb", "tb", "pb" };
   double v;
   size_t i, nunits;
@@ -581,46 +333,21 @@ format_size(size_t nbytes, char *buf, size_t buflen)
       snprintf(buf, buflen, "%.1f %s", v, units[i]);
   else
       snprintf(buf, buflen, "%.2f %s", v, units[i]);
->>>>>>> ee3b035 (init)
 }
 
 static int
 stat_is_dir(const char *path)
 {
-<<<<<<< HEAD
-	struct stat st;
-
-	if (stat(path, &st) == -1)
-	    return 0;
-	return S_ISDIR(st.st_mode);
-=======
   struct stat st;
 
   if (stat(path, &st) == -1)
       return 0;
   return S_ISDIR(st.st_mode);
->>>>>>> ee3b035 (init)
 }
 
 static char *
 join3(const char *a, const char *b, const char *c)
 {
-<<<<<<< HEAD
-	char *out;
-	size_t la, lb, lc;
-
-	la = strlen(a);
-	lb = strlen(b);
-	lc = strlen(c);
-	out = malloc(la + lb + lc + 1);
-	if (out == NULL)
-	    return NULL;
-	memcpy(out, a, la);
-	memcpy(out + la, b, lb);
-	memcpy(out + la + lb, c, lc);
-	out[la + lb + lc] = '\0';
-	return out;
-=======
   char *out;
   size_t la, lb, lc;
 
@@ -635,23 +362,11 @@ join3(const char *a, const char *b, const char *c)
   memcpy(out + la + lb, c, lc);
   out[la + lb + lc] = '\0';
   return out;
->>>>>>> ee3b035 (init)
 }
 
 static int
 repo_has_git(const char *path)
 {
-<<<<<<< HEAD
-	char *dotgit;
-	int ok;
-
-	dotgit = join3(path, "/", ".git");
-	if (dotgit == NULL)
-	    err(1, "malloc");
-	ok = stat_is_dir(dotgit);
-	free(dotgit);
-	return ok;
-=======
   char *dotgit, *head, *objects, *out, *packed_refs, *qpath, *refs;
   struct stat st;
   int ok;
@@ -693,27 +408,11 @@ repo_has_git(const char *path)
   ok = out[0] != '\0';
   free(out);
   return ok;
->>>>>>> ee3b035 (init)
 }
 
 static char *
 repo_basename(const char *path)
 {
-<<<<<<< HEAD
-	const char *p;
-
-	p = strrchr(path, '/');
-	if (p == NULL)
-	    return str_dup(path);
-	if (*(p + 1) == '\0') {
-	    for (; p > path && *p == '/'; p--)
-	        continue;
-	    for (; p > path && *(p - 1) != '/'; p--)
-	        continue;
-	    return str_dup(p);
-	}
-	return str_dup(p + 1);
-=======
   const char *p;
 
   p = strrchr(path, '/');
@@ -727,29 +426,11 @@ repo_basename(const char *path)
       return str_dup(p);
   }
   return str_dup(p + 1);
->>>>>>> ee3b035 (init)
 }
 
 static void
 append_char(char **buf, size_t *len, size_t *cap, char c)
 {
-<<<<<<< HEAD
-	char *tmp;
-
-	if (*len + 2 > *cap) {
-	    if (*cap == 0)
-	        *cap = 128;
-	    else
-	        *cap *= 2;
-	    tmp = realloc(*buf, *cap);
-	    if (tmp == NULL)
-	        err(1, "realloc");
-	    *buf = tmp;
-	}
-	(*buf)[*len] = c;
-	(*len)++;
-	(*buf)[*len] = '\0';
-=======
   char *tmp;
 
   if (*len + 2 > *cap) {
@@ -765,46 +446,20 @@ append_char(char **buf, size_t *len, size_t *cap, char c)
   (*buf)[*len] = c;
   (*len)++;
   (*buf)[*len] = '\0';
->>>>>>> ee3b035 (init)
 }
 
 static void
 append_str(char **buf, size_t *len, size_t *cap, const char *s)
 {
-<<<<<<< HEAD
-	while (*s != '\0') {
-	    append_char(buf, len, cap, *s);
-	    s++;
-	}
-=======
   while (*s != '\0') {
       append_char(buf, len, cap, *s);
       s++;
   }
->>>>>>> ee3b035 (init)
 }
 
 static char *
 write_shell_quoted(const char *s)
 {
-<<<<<<< HEAD
-	char *out;
-	size_t cap, len;
-
-	out = NULL;
-	cap = 0;
-	len = 0;
-	append_char(&out, &len, &cap, '\'');
-	while (*s != '\0') {
-	    if (*s == '\'')
-	        append_str(&out, &len, &cap, "'\\''");
-	    else
-	        append_char(&out, &len, &cap, *s);
-	    s++;
-	}
-	append_char(&out, &len, &cap, '\'');
-	return out;
-=======
   char *out;
   size_t cap, len;
 
@@ -821,54 +476,11 @@ write_shell_quoted(const char *s)
   }
   append_char(&out, &len, &cap, '\'');
   return out;
->>>>>>> ee3b035 (init)
 }
 
 static char *
 read_cmd_output(const char *fmt, ...)
 {
-<<<<<<< HEAD
-	va_list ap;
-	char line[4096], *cmd, *out;
-	size_t cap, len;
-	FILE *fp;
-	int n;
-
-	cmd = NULL;
-	n = 0;
-	va_start(ap, fmt);
-	n = vsnprintf(NULL, 0, fmt, ap);
-	va_end(ap);
-	if (n < 0)
-	    return NULL;
-	cmd = malloc((size_t)n + 1);
-	if (cmd == NULL)
-	    err(1, "malloc");
-	va_start(ap, fmt);
-	vsnprintf(cmd, (size_t)n + 1, fmt, ap);
-	va_end(ap);
-
-	fp = popen(cmd, "r");
-	free(cmd);
-	if (fp == NULL)
-	    return NULL;
-
-	out = NULL;
-	cap = 0;
-	len = 0;
-	while (fgets(line, sizeof(line), fp) != NULL)
-	    append_str(&out, &len, &cap, line);
-	if (pclose(fp) == -1) {
-	    free(out);
-	    return NULL;
-	}
-	if (out == NULL) {
-	    out = str_dup("");
-	    if (out == NULL)
-	        err(1, "malloc");
-	}
-	return out;
-=======
   va_list ap;
   char line[4096], *cmd, *out;
   size_t cap, len;
@@ -909,46 +521,11 @@ read_cmd_output(const char *fmt, ...)
           err(1, "malloc");
   }
   return out;
->>>>>>> ee3b035 (init)
 }
 
 static void
 add_repo(struct repo **repos, size_t *nrepos, size_t *cap, const char *path)
 {
-<<<<<<< HEAD
-	struct repo *tmp;
-	char *name;
-
-	name = repo_basename(path);
-	if (name == NULL)
-	    err(1, "malloc");
-	if (*nrepos + 1 > *cap) {
-	    if (*cap == 0)
-	        *cap = 8;
-	    else
-	        *cap *= 2;
-	    tmp = realloc(*repos, *cap * sizeof(struct repo));
-	    if (tmp == NULL)
-	        err(1, "realloc");
-	    *repos = tmp;
-	}
-	(*repos)[*nrepos].branch = NULL;
-	(*repos)[*nrepos].cloneurl = NULL;
-	(*repos)[*nrepos].head = NULL;
-	(*repos)[*nrepos].last_author = NULL;
-	(*repos)[*nrepos].last_date = NULL;
-	(*repos)[*nrepos].last_subject = NULL;
-	(*repos)[*nrepos].name = name;
-	(*repos)[*nrepos].owner = NULL;
-	(*repos)[*nrepos].outdir = NULL;
-	(*repos)[*nrepos].path = str_dup(path);
-	(*repos)[*nrepos].rootlink_deep = NULL;
-	(*repos)[*nrepos].rootlink_repo = NULL;
-	if ((*repos)[*nrepos].path == NULL)
-	    err(1, "malloc");
-	(*repos)[*nrepos].changed = 1;
-	(*nrepos)++;
-=======
   struct repo *tmp;
   char *name;
 
@@ -981,40 +558,11 @@ add_repo(struct repo **repos, size_t *nrepos, size_t *cap, const char *path)
       err(1, "malloc");
   (*repos)[*nrepos].changed = 1;
   (*nrepos)++;
->>>>>>> ee3b035 (init)
 }
 
 static void
 discover_repos(const char *input, struct repo **repos, size_t *nrepos, size_t *cap)
 {
-<<<<<<< HEAD
-	struct dirent *de;
-	char *candidate;
-	DIR *dp;
-
-	if (repo_has_git(input)) {
-	    add_repo(repos, nrepos, cap, input);
-	    return;
-	}
-	if (!stat_is_dir(input))
-	    errx(1, "%s is not a directory", input);
-
-	dp = opendir(input);
-	if (dp == NULL)
-	    err(1, "opendir %s", input);
-	while ((de = readdir(dp)) != NULL) {
-	    if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
-	        continue;
-	    candidate = join3(input, "/", de->d_name);
-	    if (candidate == NULL)
-	        err(1, "malloc");
-	    if (repo_has_git(candidate))
-	        add_repo(repos, nrepos, cap, candidate);
-	    free(candidate);
-	}
-	if (closedir(dp) == -1)
-	    err(1, "closedir %s", input);
-=======
   struct dirent *de;
   char *candidate;
   DIR *dp;
@@ -1041,53 +589,21 @@ discover_repos(const char *input, struct repo **repos, size_t *nrepos, size_t *c
   }
   if (closedir(dp) == -1)
       err(1, "closedir %s", input);
->>>>>>> ee3b035 (init)
 }
 
 static int
 repo_cmp(const void *a, const void *b)
 {
-<<<<<<< HEAD
-	const struct repo *ra, *rb;
-
-	ra = a;
-	rb = b;
-	return strcmp(ra->name, rb->name);
-=======
   const struct repo *ra, *rb;
 
   ra = a;
   rb = b;
   return strcmp(ra->name, rb->name);
->>>>>>> ee3b035 (init)
 }
 
 static void
 ensure_dir(const char *path)
 {
-<<<<<<< HEAD
-	char buf[PATH_MAX];
-	char *p;
-	size_t len;
-
-	len = strlen(path);
-	if (len == 0)
-	    errx(1, "empty path");
-	if (len >= sizeof(buf))
-	    errx(1, "path too long: %s", path);
-	memcpy(buf, path, len + 1);
-
-	for (p = buf + 1; *p != '\0'; p++) {
-	    if (*p != '/')
-	        continue;
-	    *p = '\0';
-	    if (mkdir(buf, 0755) == -1 && errno != EEXIST)
-	        err(1, "mkdir %s", buf);
-	    *p = '/';
-	}
-	if (mkdir(buf, 0755) == -1 && errno != EEXIST)
-	    err(1, "mkdir %s", buf);
-=======
   char buf[PATH_MAX];
   char *p;
   size_t len;
@@ -1109,27 +625,11 @@ ensure_dir(const char *path)
   }
   if (mkdir(buf, 0755) == -1 && errno != EEXIST)
       err(1, "mkdir %s", buf);
->>>>>>> ee3b035 (init)
 }
 
 static void
 ensure_parent_dir(const char *path)
 {
-<<<<<<< HEAD
-	char *copy;
-	char *p;
-
-	copy = str_dup(path);
-	if (copy == NULL)
-	    err(1, "malloc");
-	p = strrchr(copy, '/');
-	if (p != NULL) {
-	    *p = '\0';
-	    if (*copy != '\0')
-	        ensure_dir(copy);
-	}
-	free(copy);
-=======
   char *copy;
   char *p;
 
@@ -1143,37 +643,11 @@ ensure_parent_dir(const char *path)
           ensure_dir(copy);
   }
   free(copy);
->>>>>>> ee3b035 (init)
 }
 
 static void
 clear_html_files(const char *dir)
 {
-<<<<<<< HEAD
-	struct dirent *de;
-	char *path;
-	DIR *dp;
-	size_t len;
-
-	dp = opendir(dir);
-	if (dp == NULL)
-	    return;
-	while ((de = readdir(dp)) != NULL) {
-	    if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
-	        continue;
-	    len = strlen(de->d_name);
-	    if (len < 6 || strcmp(de->d_name + len - 5, ".html") != 0)
-	        continue;
-	    path = join3(dir, "/", de->d_name);
-	    if (path == NULL)
-	        err(1, "malloc");
-	    if (unlink(path) == -1 && errno != ENOENT)
-	        warn("unlink %s", path);
-	    free(path);
-	}
-	if (closedir(dp) == -1)
-	    warn("closedir %s", dir);
-=======
   struct dirent *de;
   char *path;
   DIR *dp;
@@ -1197,32 +671,11 @@ clear_html_files(const char *dir)
   }
   if (closedir(dp) == -1)
       warn("closedir %s", dir);
->>>>>>> ee3b035 (init)
 }
 
 static char *
 read_cache_head(const char *outdir)
 {
-<<<<<<< HEAD
-	char buf[256], *path;
-	FILE *fp;
-
-	path = join3(outdir, "/", ".sgit-cache");
-	if (path == NULL)
-	    err(1, "malloc");
-	fp = fopen(path, "r");
-	free(path);
-	if (fp == NULL)
-	    return NULL;
-	if (fgets(buf, sizeof(buf), fp) == NULL) {
-	    fclose(fp);
-	    return NULL;
-	}
-	if (fclose(fp) == EOF)
-	    warn("fclose cache");
-	trim_newline(buf);
-	return str_dup(buf);
-=======
   char buf[256], *path;
   FILE *fp;
 
@@ -1241,84 +694,11 @@ read_cache_head(const char *outdir)
       warn("fclose cache");
   trim_newline(buf);
   return str_dup(buf);
->>>>>>> ee3b035 (init)
 }
 
 static void
 write_cache_head(const char *outdir, const char *head)
 {
-<<<<<<< HEAD
-	char *path;
-	FILE *fp;
-
-	path = join3(outdir, "/", ".sgit-cache");
-	if (path == NULL)
-	    err(1, "malloc");
-	fp = fopen(path, "w");
-	if (fp == NULL)
-	    err(1, "fopen %s", path);
-	fprintf(fp, "%s\n", head);
-	if (fclose(fp) == EOF)
-	    err(1, "fclose %s", path);
-	free(path);
-}
-
-static void
-load_repo_meta(struct repo *r)
-{
-	char *fmt, *out, *p;
-	char *author, *date, *qpath, *subject;
-
-	qpath = write_shell_quoted(r->path);
-	if (qpath == NULL)
-	    err(1, "malloc");
-
-	out = read_cmd_output("git -C %s rev-parse --verify HEAD 2>/dev/null", qpath);
-	if (out == NULL)
-	    errx(1, "failed to get HEAD for %s", r->path);
-	trim_newline(out);
-	r->head = out;
-
-	out = read_cmd_output("git -C %s rev-parse --abbrev-ref HEAD 2>/dev/null", qpath);
-	if (out == NULL)
-	    errx(1, "failed to get branch for %s", r->path);
-	trim_newline(out);
-	r->branch = out;
-
-	fmt = "%ad%x1f%an%x1f%s";
-	out = read_cmd_output("git -C %s log -1 --date=iso --pretty=format:%s 2>/dev/null",
-	    qpath, fmt);
-	if (out == NULL)
-	    errx(1, "failed to get last commit for %s", r->path);
-	trim_newline(out);
-
-	p = out;
-	if ((date = split_field(&p)) == NULL)
-	    errx(1, "invalid git log output");
-	if ((author = split_field(&p)) == NULL)
-	    errx(1, "invalid git log output");
-	if ((subject = split_field(&p)) == NULL)
-	    errx(1, "invalid git log output");
-
-	r->last_date = str_dup(date);
-	if (r->last_date == NULL)
-	    err(1, "malloc");
-	r->last_author = str_dup(author);
-	if (r->last_author == NULL)
-	    err(1, "malloc");
-	r->last_subject = str_dup(subject);
-	if (r->last_subject == NULL)
-	    err(1, "malloc");
-	r->owner = read_git_meta_file(r, "owner");
-	if (r->owner == NULL)
-	    err(1, "malloc");
-	r->cloneurl = read_git_meta_file(r, "cloneurl");
-	if (r->cloneurl == NULL)
-	    err(1, "malloc");
-
-	free(out);
-	free(qpath);
-=======
   char *path;
   FILE *fp;
 
@@ -1399,27 +779,11 @@ load_repo_meta(struct repo *r)
   free(out);
   free(qpath);
   return 1;
->>>>>>> ee3b035 (init)
 }
 
 static char *
 split_field(char **s)
 {
-<<<<<<< HEAD
-	char *field, *p;
-
-	if (*s == NULL)
-	    return NULL;
-	field = *s;
-	p = strchr(field, SEP);
-	if (p == NULL) {
-	    *s = NULL;
-	    return field;
-	}
-	*p = '\0';
-	*s = p + 1;
-	return field;
-=======
   char *field, *p;
 
   if (*s == NULL)
@@ -1433,24 +797,11 @@ split_field(char **s)
   *p = '\0';
   *s = p + 1;
   return field;
->>>>>>> ee3b035 (init)
 }
 
 static int
 repo_changed(struct repo *r)
 {
-<<<<<<< HEAD
-	char *cached;
-	int changed;
-
-	ensure_dir(r->outdir);
-	cached = read_cache_head(r->outdir);
-	if (cached == NULL)
-	    return 1;
-	changed = strcmp(cached, r->head) != 0;
-	free(cached);
-	return changed;
-=======
   char *cached, *expect;
   int changed;
 
@@ -1465,46 +816,17 @@ repo_changed(struct repo *r)
   free(cached);
   free(expect);
   return changed;
->>>>>>> ee3b035 (init)
 }
 
 static void
 write_html_escaped(FILE *fp, const char *s)
 {
-<<<<<<< HEAD
-	write_html_escaped_len(fp, s, strlen(s));
-=======
   write_html_escaped_len(fp, s, strlen(s));
->>>>>>> ee3b035 (init)
 }
 
 static void
 write_html_escaped_len(FILE *fp, const char *s, size_t len)
 {
-<<<<<<< HEAD
-	size_t i;
-
-	for (i = 0; i < len; i++) {
-	    switch (*s) {
-	    case '&':
-	        fputs("&amp;", fp);
-	        break;
-	    case '<':
-	        fputs("&lt;", fp);
-	        break;
-	    case '>':
-	        fputs("&gt;", fp);
-	        break;
-	    case '\"':
-	        fputs("&quot;", fp);
-	        break;
-	    default:
-	        fputc((unsigned char)*s, fp);
-	        break;
-	    }
-	    s++;
-	}
-=======
   size_t i;
 
   for (i = 0; i < len; i++) {
@@ -1527,80 +849,12 @@ write_html_escaped_len(FILE *fp, const char *s, size_t len)
       }
       s++;
   }
->>>>>>> ee3b035 (init)
 }
 
 static void
 make_commit_page(const struct repo *r, const char *hash, const char *short_hash,
     const char *date, const char *author, const char *subject)
 {
-<<<<<<< HEAD
-	char *dir, *html, *patch, *qhash, *qpath, *tmp;
-	FILE *fp;
-
-	dir = join3(r->outdir, "/", "commits");
-	if (dir == NULL)
-	    err(1, "malloc");
-	ensure_dir(dir);
-	tmp = join3(dir, "/", hash);
-	if (tmp == NULL)
-	    err(1, "malloc");
-	html = join3(tmp, "", ".html");
-	if (html == NULL)
-	    err(1, "malloc");
-	free(tmp);
-
-	qpath = write_shell_quoted(r->path);
-	qhash = write_shell_quoted(hash);
-	if (qpath == NULL || qhash == NULL)
-	    err(1, "malloc");
-	patch = read_cmd_output("git -C %s show --date=short --pretty=format: "
-	    "--patch --stat %s 2>/dev/null", qpath, qhash);
-	if (patch == NULL)
-	    patch = str_dup("");
-	if (patch == NULL)
-	    err(1, "malloc");
-
-	fp = fopen(html, "w");
-	if (fp == NULL)
-	    err(1, "fopen %s", html);
-
-	fputs("<!doctype html>\n<html lang=\"en\">\n<head>\n", fp);
-	fputs("<meta charset=\"utf-8\">\n", fp);
-	fputs("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n", fp);
-	fputs("<link rel=\"stylesheet\" href=\"../../style.css\">\n", fp);
-	fputs("<title>", fp);
-	write_html_escaped(fp, short_hash);
-	fputs(" - ", fp);
-	write_html_escaped(fp, r->name);
-	fputs("</title>\n", fp);
-	fputs("</head>\n<body>\n<h1>", fp);
-	write_html_escaped(fp, short_hash);
-	fputs("</h1>\n<p><a href=\"../index.html\">summary</a> | "
-	    "<a href=\"../files.html\">files</a> | "
-	    "<a href=\"../history.html\">history</a> | ", fp);
-	write_html_escaped(fp, r->name);
-	fputs("</p>\n<p>commit: <code>", fp);
-	write_html_escaped(fp, hash);
-	fputs("</code><br>author: ", fp);
-	write_html_escaped(fp, author);
-	fputs("<br>date: ", fp);
-	write_html_escaped(fp, date);
-	fputs("<br>subject: ", fp);
-	write_html_escaped(fp, subject);
-	fputs("</p>\n", fp);
-	fputs("<h2>Diff</h2>\n<pre>", fp);
-	write_html_escaped(fp, patch);
-	fputs("</pre>\n</body>\n</html>\n", fp);
-
-	if (fclose(fp) == EOF)
-	    err(1, "fclose %s", html);
-	free(dir);
-	free(html);
-	free(patch);
-	free(qhash);
-	free(qpath);
-=======
   char *dir, *html, *patch, *qhash, *qpath, *tmp;
   FILE *fp;
 
@@ -1666,41 +920,11 @@ make_commit_page(const struct repo *r, const char *hash, const char *short_hash,
   free(patch);
   free(qhash);
   free(qpath);
->>>>>>> ee3b035 (init)
 }
 
 static char *
 read_readme(const struct repo *r, int *is_md)
 {
-<<<<<<< HEAD
-	const char *names[] = { "README.md", "README", "README.txt", "readme.md",
-	    "readme", NULL };
-	char *out, *qname, *qpath;
-	size_t i;
-
-	*is_md = 0;
-	qpath = write_shell_quoted(r->path);
-	if (qpath == NULL)
-	    err(1, "malloc");
-	for (i = 0; names[i] != NULL; i++) {
-	    qname = write_shell_quoted(names[i]);
-	    if (qname == NULL)
-	        err(1, "malloc");
-	    out = read_cmd_output("git -C %s show HEAD:%s 2>/dev/null", qpath,
-	        qname);
-	    free(qname);
-	    if (out == NULL)
-	        continue;
-	    if (out[0] != '\0') {
-	        *is_md = has_suffix_ci(names[i], ".md");
-	        free(qpath);
-	        return out;
-	    }
-	    free(out);
-	}
-	free(qpath);
-	return str_dup("");
-=======
   const char *names[] = { "README.md", "README", "README.txt", "readme.md",
       "readme", NULL };
   char *out, *qhead, *qname, *qpath;
@@ -1733,186 +957,11 @@ read_readme(const struct repo *r, int *is_md)
   free(qhead);
   free(qpath);
   return str_dup("");
->>>>>>> ee3b035 (init)
 }
 
 static int
 has_suffix_ci(const char *s, const char *suffix)
 {
-<<<<<<< HEAD
-	size_t i, ls, lsf;
-
-	ls = strlen(s);
-	lsf = strlen(suffix);
-	if (lsf > ls)
-	    return 0;
-	for (i = 0; i < lsf; i++) {
-	    if (tolower((unsigned char)s[ls - lsf + i]) !=
-	        tolower((unsigned char)suffix[i]))
-	        return 0;
-	}
-	return 1;
-}
-
-static void
-render_markdown_inline(FILE *fp, const char *line)
-{
-	const char *code_end, *link_close, *link_end, *p, *url_start;
-	size_t n;
-
-	p = line;
-	while (*p != '\0') {
-	    if (*p == '`') {
-	        code_end = strchr(p + 1, '`');
-	        if (code_end != NULL) {
-	            fputs("<code>", fp);
-	            write_html_escaped_len(fp, p + 1,
-	                (size_t)(code_end - (p + 1)));
-	            fputs("</code>", fp);
-	            p = code_end + 1;
-	            continue;
-	        }
-	    }
-	    if (*p == '[') {
-	        link_close = strchr(p + 1, ']');
-	        if (link_close != NULL && *(link_close + 1) == '(') {
-	            url_start = link_close + 2;
-	            link_end = strchr(url_start, ')');
-	            if (link_end != NULL) {
-	                fputs("<a href=\"", fp);
-	                write_html_escaped_len(fp, url_start,
-	                    (size_t)(link_end - url_start));
-	                fputs("\">", fp);
-	                write_html_escaped_len(fp, p + 1,
-	                    (size_t)(link_close - (p + 1)));
-	                fputs("</a>", fp);
-	                p = link_end + 1;
-	                continue;
-	            }
-	        }
-	    }
-	    n = strcspn(p, "`[");
-	    if (n == 0) {
-	        write_html_escaped_len(fp, p, 1);
-	        p++;
-	    } else {
-	        write_html_escaped_len(fp, p, n);
-	        p += n;
-	    }
-	}
-}
-
-static void
-render_markdown(FILE *fp, const char *md)
-{
-	char *line;
-	char *next;
-	char *save;
-	int in_code, in_list, in_p, level;
-
-	save = str_dup(md);
-	if (save == NULL)
-	    err(1, "malloc");
-	in_code = 0;
-	in_list = 0;
-	in_p = 0;
-	line = save;
-	while (line != NULL) {
-	    next = strchr(line, '\n');
-	    if (next != NULL) {
-	        *next = '\0';
-	        next++;
-	    }
-	    while (*line == ' ' || *line == '\t')
-	        line++;
-	    if (strncmp(line, "```", 3) == 0) {
-	        if (in_p) {
-	            fputs("</p>\n", fp);
-	            in_p = 0;
-	        }
-	        if (in_list) {
-	            fputs("</ul>\n", fp);
-	            in_list = 0;
-	        }
-	        if (!in_code)
-	            fputs("<pre>", fp);
-	        else
-	            fputs("</pre>\n", fp);
-	        in_code = !in_code;
-	        line = next;
-	        continue;
-	    }
-	    if (in_code) {
-	        write_html_escaped(fp, line);
-	        fputc('\n', fp);
-	        line = next;
-	        continue;
-	    }
-	    if (*line == '\0') {
-	        if (in_p) {
-	            fputs("</p>\n", fp);
-	            in_p = 0;
-	        }
-	        if (in_list) {
-	            fputs("</ul>\n", fp);
-	            in_list = 0;
-	        }
-	        line = next;
-	        continue;
-	    }
-	    if (*line == '#') {
-	        if (in_p) {
-	            fputs("</p>\n", fp);
-	            in_p = 0;
-	        }
-	        if (in_list) {
-	            fputs("</ul>\n", fp);
-	            in_list = 0;
-	        }
-	        level = 0;
-	        while (*line == '#' && level < 6) {
-	            level++;
-	            line++;
-	        }
-	        while (*line == ' ')
-	            line++;
-	        fprintf(fp, "<h%d>", level == 0 ? 1 : level);
-	        render_markdown_inline(fp, line);
-	        fprintf(fp, "</h%d>\n", level == 0 ? 1 : level);
-	        line = next;
-	        continue;
-	    }
-	    if ((line[0] == '-' || line[0] == '*') && line[1] == ' ') {
-	        if (in_p) {
-	            fputs("</p>\n", fp);
-	            in_p = 0;
-	        }
-	        if (!in_list) {
-	            fputs("<ul>\n", fp);
-	            in_list = 1;
-	        }
-	        fputs("<li>", fp);
-	        render_markdown_inline(fp, line + 2);
-	        fputs("</li>\n", fp);
-	        line = next;
-	        continue;
-	    }
-	    if (!in_p) {
-	        fputs("<p>", fp);
-	        in_p = 1;
-	    } else
-	        fputs("<br>\n", fp);
-	    render_markdown_inline(fp, line);
-	    line = next;
-	}
-	if (in_code)
-	    fputs("</pre>\n", fp);
-	if (in_p)
-	    fputs("</p>\n", fp);
-	if (in_list)
-	    fputs("</ul>\n", fp);
-	free(save);
-=======
   size_t i, ls, lsf;
 
   ls = strlen(s);
@@ -1952,43 +1001,11 @@ repo_gitdir_path(const struct repo *r)
   if (tmp == NULL)
       err(1, "malloc");
   return tmp;
->>>>>>> ee3b035 (init)
 }
 
 static char *
 read_git_meta_file(const struct repo *r, const char *name)
 {
-<<<<<<< HEAD
-	char *file, *gitdir, *out;
-	FILE *fp;
-	size_t n;
-
-	out = NULL;
-	n = 0;
-	gitdir = join3(r->path, "/", ".git");
-	if (gitdir == NULL)
-	    err(1, "malloc");
-	file = join3(gitdir, "/", name);
-	if (file == NULL)
-	    err(1, "malloc");
-	free(gitdir);
-
-	fp = fopen(file, "r");
-	free(file);
-	if (fp == NULL)
-	    return str_dup("");
-
-	if (getline(&out, &n, fp) == -1) {
-	    if (fclose(fp) == EOF)
-	        warn("fclose metadata");
-	    free(out);
-	    return str_dup("");
-	}
-	if (fclose(fp) == EOF)
-	    warn("fclose metadata");
-	trim_newline(out);
-	return out;
-=======
   char *file, *gitdir, *out;
   FILE *fp;
   size_t n;
@@ -2018,68 +1035,11 @@ read_git_meta_file(const struct repo *r, const char *name)
       warn("fclose metadata");
   trim_newline(out);
   return out;
->>>>>>> ee3b035 (init)
 }
 
 static void
 make_readme_page(const struct repo *r, const char *readme, int readme_md)
 {
-<<<<<<< HEAD
-	char *html;
-	FILE *fp;
-
-	html = join3(r->outdir, "/", "index.html");
-	if (html == NULL)
-	    err(1, "malloc");
-	fp = fopen(html, "w");
-	if (fp == NULL)
-	    err(1, "fopen %s", html);
-
-	fputs("<!doctype html>\n<html lang=\"en\">\n<head>\n", fp);
-	fputs("<meta charset=\"utf-8\">\n", fp);
-	fputs("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n", fp);
-	fputs("<link rel=\"stylesheet\" href=\"../style.css\">\n", fp);
-	fputs("<title>", fp);
-	write_html_escaped(fp, r->name);
-	fputs(" summary</title>\n", fp);
-	fputs("</head>\n<body>\n", fp);
-	if (strcmp(r->rootlink_repo, "index.html") != 0)
-	    fputs("<p><a class=\"index-link\" href=\"../index.html\">index</a></p>\n", fp);
-	fputs("<h1>", fp);
-	write_html_escaped(fp, r->name);
-	fputs("</h1>\n<p><a href=\"index.html\">summary</a> | <a href=\"files.html\">files</a>", fp);
-	fputs(" | <a href=\"history.html\">history</a></p>\n<p class=\"meta\">", fp);
-	fputs("<span class=\"meta-k\">branch</span> : ", fp);
-	write_html_escaped(fp, r->branch);
-	fputs("<br><span class=\"meta-k\">head</span> : ", fp);
-	write_html_escaped(fp, r->head);
-	fputs("<br><span class=\"meta-k\">owner</span> : ", fp);
-	if (r->owner[0] == '\0')
-	    fputs("unknown", fp);
-	else
-	    write_html_escaped(fp, r->owner);
-	if (r->cloneurl[0] != '\0') {
-	    fputs("<br><span class=\"meta-k\">clone</span> : git clone ", fp);
-	    write_html_escaped(fp, r->cloneurl);
-	}
-	fputs("</p>\n", fp);
-
-	if (readme[0] != '\0') {
-	    fputs("<h2>readme</h2>\n", fp);
-	    if (readme_md)
-	        render_markdown(fp, readme);
-	    else {
-	        fputs("<pre>", fp);
-	        write_html_escaped(fp, readme);
-	        fputs("</pre>\n", fp);
-	    }
-	}
-	fputs("</body>\n</html>\n", fp);
-
-	if (fclose(fp) == EOF)
-	    err(1, "fclose %s", html);
-	free(html);
-=======
   char *html;
   FILE *fp;
 
@@ -2140,25 +1100,10 @@ make_readme_page(const struct repo *r, const char *readme, int readme_md)
   if (fclose(fp) == EOF)
       err(1, "fclose %s", html);
   free(html);
->>>>>>> ee3b035 (init)
 }
 static char *
 file_page_name(const char *path)
 {
-<<<<<<< HEAD
-	const char *base;
-	char *out;
-
-	base = strrchr(path, '/');
-	if (base == NULL)
-	    base = path;
-	else
-	    base++;
-	out = join3(base, "", ".html");
-	if (out == NULL)
-	    err(1, "malloc");
-	return out;
-=======
   const unsigned char *p;
   char *out;
   size_t cap, len;
@@ -2186,32 +1131,11 @@ file_page_name(const char *path)
   if (out == NULL)
       err(1, "malloc");
   return out;
->>>>>>> ee3b035 (init)
 }
 
 static char *
 read_file_head(const struct repo *r, const char *path)
 {
-<<<<<<< HEAD
-	char *qpath, *qspec, *spec, *out;
-
-	spec = join3("HEAD:", "", path);
-	if (spec == NULL)
-	    err(1, "malloc");
-	qpath = write_shell_quoted(r->path);
-	qspec = write_shell_quoted(spec);
-	free(spec);
-	if (qpath == NULL || qspec == NULL)
-	    err(1, "malloc");
-	out = read_cmd_output("git -C %s show %s 2>/dev/null", qpath, qspec);
-	if (out == NULL)
-	    out = str_dup("");
-	if (out == NULL)
-	    err(1, "malloc");
-	free(qpath);
-	free(qspec);
-	return out;
-=======
   char *qpath, *qspec, *spec, *out;
 
   spec = join3(r->head, ":", path);
@@ -2230,38 +1154,11 @@ read_file_head(const struct repo *r, const char *path)
   free(qpath);
   free(qspec);
   return out;
->>>>>>> ee3b035 (init)
 }
 
 static size_t
 read_blob_size(const struct repo *r, const char *path)
 {
-<<<<<<< HEAD
-	char *end, *out, *qpath, *qspec, *spec;
-	unsigned long n;
-
-	spec = join3("HEAD:", "", path);
-	if (spec == NULL)
-	    err(1, "malloc");
-	qpath = write_shell_quoted(r->path);
-	qspec = write_shell_quoted(spec);
-	free(spec);
-	if (qpath == NULL || qspec == NULL)
-	    err(1, "malloc");
-	out = read_cmd_output("git -C %s cat-file -s %s 2>/dev/null", qpath,
-	    qspec);
-	free(qpath);
-	free(qspec);
-	if (out == NULL)
-	    return 0;
-	trim_newline(out);
-	errno = 0;
-	n = strtoul(out, &end, 10);
-	free(out);
-	if (errno != 0 || end == NULL || *end != '\0')
-	    return 0;
-	return (size_t)n;
-=======
   char *end, *out, *qpath, *qspec, *spec;
   unsigned long n;
 
@@ -2288,47 +1185,11 @@ read_blob_size(const struct repo *r, const char *path)
   }
   free(out);
   return (size_t)n;
->>>>>>> ee3b035 (init)
 }
 
 static void
 write_raw_blob(const struct repo *r, const char *path)
 {
-<<<<<<< HEAD
-	char *cmd, *dst, *qdst, *qpath, *qspec, *spec;
-	int n, rc;
-
-	dst = join3(r->outdir, "/raw/", path);
-	if (dst == NULL)
-	    err(1, "malloc");
-	ensure_parent_dir(dst);
-	qpath = write_shell_quoted(r->path);
-	spec = join3("HEAD:", "", path);
-	if (qpath == NULL || spec == NULL)
-	    err(1, "malloc");
-	qspec = write_shell_quoted(spec);
-	qdst = write_shell_quoted(dst);
-	free(spec);
-	if (qspec == NULL || qdst == NULL)
-	    err(1, "malloc");
-	n = snprintf(NULL, 0, "git -C %s cat-file blob %s > %s 2>/dev/null",
-	    qpath, qspec, qdst);
-	if (n < 0)
-	    errx(1, "snprintf");
-	cmd = malloc((size_t)n + 1);
-	if (cmd == NULL)
-	    err(1, "malloc");
-	snprintf(cmd, (size_t)n + 1, "git -C %s cat-file blob %s > %s 2>/dev/null",
-	    qpath, qspec, qdst);
-	rc = system(cmd);
-	if (rc != 0)
-	    warn("write raw blob %s", path);
-	free(cmd);
-	free(dst);
-	free(qdst);
-	free(qpath);
-	free(qspec);
-=======
   char *cmd, *dst, *qdst, *qpath, *qspec, *spec;
   int n, rc;
 
@@ -2362,27 +1223,11 @@ write_raw_blob(const struct repo *r, const char *path)
   free(qdst);
   free(qpath);
   free(qspec);
->>>>>>> ee3b035 (init)
 }
 
 static struct tree_node *
 tree_new(const char *name, const char *path, int is_dir)
 {
-<<<<<<< HEAD
-	struct tree_node *n;
-
-	n = calloc(1, sizeof(*n));
-	if (n == NULL)
-	    err(1, "calloc");
-	n->name = str_dup(name);
-	if (n->name == NULL)
-	    err(1, "malloc");
-	n->path = str_dup(path);
-	if (n->path == NULL)
-	    err(1, "malloc");
-	n->is_dir = is_dir;
-	return n;
-=======
   struct tree_node *n;
 
   n = calloc(1, sizeof(*n));
@@ -2396,24 +1241,11 @@ tree_new(const char *name, const char *path, int is_dir)
       err(1, "malloc");
   n->is_dir = is_dir;
   return n;
->>>>>>> ee3b035 (init)
 }
 
 static int
 tree_cmp(const void *a, const void *b)
 {
-<<<<<<< HEAD
-	const struct tree_node *na, *nb;
-	const struct tree_node *const *pa, *const *pb;
-
-	pa = a;
-	pb = b;
-	na = *pa;
-	nb = *pb;
-	if (na->is_dir != nb->is_dir)
-	    return nb->is_dir - na->is_dir;
-	return strcmp(na->name, nb->name);
-=======
   const struct tree_node *na, *nb;
   const struct tree_node *const *pa, *const *pb;
 
@@ -2424,81 +1256,11 @@ tree_cmp(const void *a, const void *b)
   if (na->is_dir != nb->is_dir)
       return nb->is_dir - na->is_dir;
   return strcmp(na->name, nb->name);
->>>>>>> ee3b035 (init)
 }
 
 static struct tree_node *
 tree_add_path(struct tree_node *root, const char *path)
 {
-<<<<<<< HEAD
-	char *copy, *curpath, *part, *slash;
-	struct tree_node *cur, *next;
-	size_t i;
-
-	copy = str_dup(path);
-	curpath = str_dup("");
-	if (copy == NULL || curpath == NULL)
-	    err(1, "malloc");
-	cur = root;
-	part = copy;
-
-	while (part != NULL && *part != '\0') {
-	    int is_dir;
-
-	    slash = strchr(part, '/');
-	    is_dir = slash != NULL;
-	    if (slash != NULL)
-	        *slash = '\0';
-
-	    if (curpath[0] == '\0')
-	        next = tree_new(part, part, is_dir);
-	    else {
-	        char *tmp;
-
-	        tmp = join3(curpath, "/", part);
-	        if (tmp == NULL)
-	            err(1, "malloc");
-	        next = tree_new(part, tmp, is_dir);
-	        free(tmp);
-	    }
-
-	    for (i = 0; i < cur->nchildren; i++) {
-	        if (strcmp(cur->children[i]->name, next->name) == 0 &&
-	            cur->children[i]->is_dir == next->is_dir)
-	            break;
-	    }
-	    if (i == cur->nchildren) {
-	        struct tree_node **tmp_children;
-
-	        if (cur->nchildren + 1 > cur->cap) {
-	            if (cur->cap == 0)
-	                cur->cap = 8;
-	            else
-	                cur->cap *= 2;
-	            tmp_children = realloc(cur->children,
-	                cur->cap * sizeof(*cur->children));
-	            if (tmp_children == NULL)
-	                err(1, "realloc");
-	            cur->children = tmp_children;
-	        }
-	        cur->children[cur->nchildren++] = next;
-	        cur = next;
-	    } else {
-	        tree_free(next);
-	        cur = cur->children[i];
-	    }
-
-	    free(curpath);
-	    curpath = str_dup(cur->path);
-	    if (curpath == NULL)
-	        err(1, "malloc");
-	    part = slash == NULL ? NULL : slash + 1;
-	}
-
-	free(curpath);
-	free(copy);
-	return root;
-=======
   char *copy, *curpath, *part, *slash;
   struct tree_node *cur, *next;
   size_t i;
@@ -2566,28 +1328,11 @@ tree_add_path(struct tree_node *root, const char *path)
   free(curpath);
   free(copy);
   return root;
->>>>>>> ee3b035 (init)
 }
 
 static struct tree_node *
 tree_root_from_files(const char *files)
 {
-<<<<<<< HEAD
-	char *copy, *line;
-	struct tree_node *root;
-
-	root = tree_new("", "", 1);
-	copy = str_dup(files);
-	if (copy == NULL)
-	    err(1, "malloc");
-	line = strtok(copy, "\n");
-	while (line != NULL) {
-	    tree_add_path(root, line);
-	    line = strtok(NULL, "\n");
-	}
-	free(copy);
-	return root;
-=======
   char *copy, *line;
   struct tree_node *root;
 
@@ -2602,24 +1347,11 @@ tree_root_from_files(const char *files)
   }
   free(copy);
   return root;
->>>>>>> ee3b035 (init)
 }
 
 static void
 tree_free(struct tree_node *n)
 {
-<<<<<<< HEAD
-	size_t i;
-
-	if (n == NULL)
-	    return;
-	for (i = 0; i < n->nchildren; i++)
-	    tree_free(n->children[i]);
-	free(n->children);
-	free(n->name);
-	free(n->path);
-	free(n);
-=======
   size_t i;
 
   if (n == NULL)
@@ -2630,110 +1362,11 @@ tree_free(struct tree_node *n)
   free(n->name);
   free(n->path);
   free(n);
->>>>>>> ee3b035 (init)
 }
 
 static void
 render_tree(FILE *fp, const struct repo *r, struct tree_node *n, int depth)
 {
-<<<<<<< HEAD
-	char *blob, *html, *name;
-	char *content;
-	char hsize[64];
-	FILE *bfp;
-	size_t blob_size, i, loc, nbytes;
-
-	if (!n->is_dir) {
-	    name = file_page_name(n->path);
-	    if (raw_mode)
-	        write_raw_blob(r, n->path);
-	    blob_size = read_blob_size(r, n->path);
-	    content = read_file_head(r, n->path);
-	    nbytes = strlen(content);
-	    if (!text_content_p(content, nbytes, blob_size)) {
-	        if (raw_mode) {
-	            fputs("<li><a href=\"raw/", fp);
-	            write_html_escaped(fp, n->path);
-	            fputs("\"><code>", fp);
-	            write_html_escaped(fp, n->path);
-	            fputs("</code></a></li>\n", fp);
-	        } else {
-	            fputs("<li><code>", fp);
-	            write_html_escaped(fp, n->path);
-	            fputs("</code></li>\n", fp);
-	        }
-	        free(content);
-	        free(name);
-	        return;
-	    }
-	    fputs("<li><a href=\"file/", fp);
-	    write_html_escaped(fp, name);
-	    fputs("\"><code>", fp);
-	    write_html_escaped(fp, n->path);
-	    fputs("</code></a></li>\n", fp);
-
-	    blob = join3(r->outdir, "/file/", name);
-	    if (blob == NULL)
-	        err(1, "malloc");
-	    html = blob;
-	    loc = text_loc(content);
-	    bfp = fopen(html, "w");
-	    if (bfp == NULL)
-	        err(1, "fopen %s", html);
-	    fputs("<!doctype html>\n<html lang=\"en\">\n<head>\n", bfp);
-	    fputs("<meta charset=\"utf-8\">\n", bfp);
-	    fputs("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n", bfp);
-	    fputs("<link rel=\"stylesheet\" href=\"../../style.css\">\n", bfp);
-	    fputs("<title>", bfp);
-	    write_html_escaped(bfp, n->path);
-	    fputs(" - ", bfp);
-	    write_html_escaped(bfp, r->name);
-	    fputs("</title>\n", bfp);
-	    fputs("</head>\n<body>\n<p><a href=\"../index.html\">summary</a> | "
-	        "<a href=\"../files.html\">files</a> | "
-	        "<a href=\"../history.html\">history</a></p>\n<h1><code>",
-	        bfp);
-	    write_html_escaped(bfp, n->path);
-	    fputs("</code></h1>\n<p class=\"meta\">", bfp);
-	    fputs("<span class=\"meta-k\">file</span> : ", bfp);
-	    write_html_escaped(bfp, n->path);
-	    fputs("<br><span class=\"meta-k\">loc</span> : ", bfp);
-	    fprintf(bfp, "%lu", (unsigned long)loc);
-	    fputs("<br><span class=\"meta-k\">size</span> : ", bfp);
-	    format_size(nbytes, hsize, sizeof(hsize));
-	    fprintf(bfp, "%lu bytes (%s)", (unsigned long)nbytes, hsize);
-	    if (raw_mode) {
-	        fputs("<br><span class=\"meta-k\">raw</span> : <a href=\"../raw/",
-	            bfp);
-	        write_html_escaped(bfp, n->path);
-	        fputs("\">raw</a>", bfp);
-	    }
-	    fputs("</p>\n<pre>", bfp);
-	    write_html_escaped(bfp, content);
-	    fputs("</pre>\n</body>\n</html>\n", bfp);
-	    if (fclose(bfp) == EOF)
-	        err(1, "fclose %s", html);
-	    free(content);
-	    free(name);
-	    free(html);
-	    return;
-	}
-
-	if (depth == 0)
-	    fputs("<ul>\n", fp);
-	else {
-	    fputs("<li><code>", fp);
-	    write_html_escaped(fp, n->name);
-	    fputs("/</code>\n<ul>\n", fp);
-	}
-	qsort(n->children, n->nchildren, sizeof(*n->children), tree_cmp);
-	for (i = 0; i < n->nchildren; i++)
-	    render_tree(fp, r, n->children[i], depth + 1);
-	if (depth == 0)
-	    fputs("</ul>\n", fp);
-	else
-	    fputs("</ul>\n</li>\n", fp);
-=======
   char *blob, *html, *name;
   char *content;
   char hsize[64];
@@ -2830,54 +1463,11 @@ render_tree(FILE *fp, const struct repo *r, struct tree_node *n, int depth)
       fputs("</ul>\n", fp);
   else
       fputs("</ul>\n</li>\n", fp);
->>>>>>> ee3b035 (init)
 }
 
 static void
 make_files_page(const struct repo *r, const char *files)
 {
-<<<<<<< HEAD
-	struct tree_node *root;
-	char *dir, *html;
-	FILE *fp;
-
-	root = tree_root_from_files(files);
-	dir = join3(r->outdir, "/", "file");
-	if (dir == NULL)
-	    err(1, "malloc");
-	ensure_dir(dir);
-	clear_html_files(dir);
-	free(dir);
-
-	html = join3(r->outdir, "/", "files.html");
-	if (html == NULL)
-	    err(1, "malloc");
-	fp = fopen(html, "w");
-	if (fp == NULL)
-	    err(1, "fopen %s", html);
-
-	fputs("<!doctype html>\n<html lang=\"en\">\n<head>\n", fp);
-	fputs("<meta charset=\"utf-8\">\n", fp);
-	fputs("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n", fp);
-	fputs("<link rel=\"stylesheet\" href=\"../style.css\">\n", fp);
-	fputs("<title>", fp);
-	write_html_escaped(fp, r->name);
-	fputs(" files</title>\n", fp);
-	fputs("</head>\n<body>\n", fp);
-	if (strcmp(r->rootlink_repo, "index.html") != 0)
-	    fputs("<p><a class=\"index-link\" href=\"../index.html\">index</a></p>\n", fp);
-	fputs("<h1>", fp);
-	write_html_escaped(fp, r->name);
-	fputs("</h1>\n<p><a href=\"index.html\">summary</a> | <a href=\"files.html\">files</a>", fp);
-	fputs(" | <a href=\"history.html\">history</a></p>\n<h2>Files</h2>\n", fp);
-	render_tree(fp, r, root, 0);
-	fputs("</body>\n</html>\n", fp);
-
-	if (fclose(fp) == EOF)
-	    err(1, "fclose %s", html);
-	free(html);
-	tree_free(root);
-=======
   struct tree_node *root;
   char *dir, *html;
   FILE *fp;
@@ -2918,100 +1508,11 @@ make_files_page(const struct repo *r, const char *files)
       err(1, "fclose %s", html);
   free(html);
   tree_free(root);
->>>>>>> ee3b035 (init)
 }
 
 static void
 make_repo_page(const struct repo *r)
 {
-<<<<<<< HEAD
-	char *commits, *files, *full_hash, *history, *line, *qpath, *readme;
-	char *short_hash, *author, *date, *subject;
-	FILE *fp;
-	int readme_md;
-
-	qpath = write_shell_quoted(r->path);
-	if (qpath == NULL)
-	    err(1, "malloc");
-	commits = read_cmd_output("git -C %s log -n %d --date=short "
-	    "--pretty=format:%%H%%x1f%%h%%x1f%%ad%%x1f%%an%%x1f%%s 2>/dev/null",
-	    qpath, COMMIT_LIMIT);
-	if (commits == NULL)
-	    errx(1, "failed to read commits for %s", r->path);
-	files = read_cmd_output("git -C %s ls-tree -r --name-only HEAD 2>/dev/null",
-	    qpath);
-	if (files == NULL)
-	    files = str_dup("");
-	if (files == NULL)
-	    err(1, "malloc");
-	free(qpath);
-
-	readme = read_readme(r, &readme_md);
-	if (readme == NULL)
-	    err(1, "malloc");
-
-	make_readme_page(r, readme, readme_md);
-	make_files_page(r, files);
-
-	history = join3(r->outdir, "/", "history.html");
-	if (history == NULL)
-	    err(1, "malloc");
-	fp = fopen(history, "w");
-	if (fp == NULL)
-	    err(1, "fopen %s", history);
-
-	fputs("<!doctype html>\n<html lang=\"en\">\n<head>\n", fp);
-	fputs("<meta charset=\"utf-8\">\n", fp);
-	fputs("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n", fp);
-	fputs("<link rel=\"stylesheet\" href=\"../style.css\">\n", fp);
-	fputs("<title>", fp);
-	write_html_escaped(fp, r->name);
-	fputs(" history</title>\n</head>\n<body>\n", fp);
-	if (strcmp(r->rootlink_repo, "index.html") != 0)
-	    fputs("<p><a class=\"index-link\" href=\"../index.html\">index</a></p>\n", fp);
-	fputs("<h1>", fp);
-	write_html_escaped(fp, r->name);
-	fputs("</h1>\n<p><a href=\"index.html\">summary</a> | <a href=\"files.html\">files</a>", fp);
-	fputs(" | <a href=\"history.html\">history</a></p>\n", fp);
-	fputs("<h2>History</h2>\n", fp);
-	fputs("<table>\n<thead><tr><th>hash</th><th>date</th><th>author</th><th>subject</th></tr></thead>\n<tbody>\n", fp);
-
-	line = strtok(commits, "\n");
-	while (line != NULL) {
-	    full_hash = split_field(&line);
-	    short_hash = split_field(&line);
-	    date = split_field(&line);
-	    author = split_field(&line);
-	    subject = line == NULL ? "" : line;
-	    if (full_hash != NULL && short_hash != NULL && date != NULL &&
-	        author != NULL && subject != NULL) {
-	        make_commit_page(r, full_hash, short_hash, date, author,
-	            subject);
-	        fputs("<tr><td><a href=\"commits/", fp);
-	        write_html_escaped(fp, full_hash);
-	        fputs(".html\"><code>", fp);
-	        write_html_escaped(fp, short_hash);
-	        fputs("</code></a></td><td>", fp);
-	        write_html_escaped(fp, date);
-	        fputs("</td><td>", fp);
-	        write_html_escaped(fp, author);
-	        fputs("</td><td>", fp);
-	        write_html_escaped(fp, subject);
-	        fputs("</td></tr>\n", fp);
-	    }
-	    line = strtok(NULL, "\n");
-	}
-	fputs("</tbody>\n</table>\n</body>\n</html>\n", fp);
-
-	if (fclose(fp) == EOF)
-	    err(1, "fclose %s", history);
-	write_cache_head(r->outdir, r->head);
-
-	free(history);
-	free(commits);
-	free(files);
-	free(readme);
-=======
   char *commits, *files, *full_hash, *history, *line, *qhead, *qpath, *readme;
   char *short_hash, *author, *date, *subject;
   FILE *fp;
@@ -3102,55 +1603,11 @@ make_repo_page(const struct repo *r)
   free(commits);
   free(files);
   free(readme);
->>>>>>> ee3b035 (init)
 }
 
 static void
 make_index(const char *outdir, struct repo *repos, size_t nrepos)
 {
-<<<<<<< HEAD
-	FILE *fp;
-	char *path;
-	size_t i;
-
-	path = join3(outdir, "/", "index.html");
-	if (path == NULL)
-	    err(1, "malloc");
-	fp = fopen(path, "w");
-	if (fp == NULL)
-	    err(1, "fopen %s", path);
-
-	fputs("<!doctype html>\n<html lang=\"en\">\n<head>\n", fp);
-	fputs("<meta charset=\"utf-8\">\n", fp);
-	fputs("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n", fp);
-	fputs("<link rel=\"stylesheet\" href=\"style.css\">\n", fp);
-	fputs("<title>git index</title>\n", fp);
-	fputs("</head>\n<body>\n<h1>Repositories</h1>\n", fp);
-	fputs("<table>\n<thead><tr><th>repo</th><th>owner</th><th>branch</th><th>head</th><th>last commit</th></tr></thead>\n<tbody>\n", fp);
-	for (i = 0; i < nrepos; i++) {
-	    fputs("<tr><td><a href=\"", fp);
-	    write_html_escaped(fp, repos[i].name);
-	    fputs("/\">", fp);
-	    write_html_escaped(fp, repos[i].name);
-	    fputs("</a></td><td>", fp);
-	    if (repos[i].owner[0] == '\0')
-	        fputs("unknown", fp);
-	    else
-	        write_html_escaped(fp, repos[i].owner);
-	    fputs("</td><td>", fp);
-	    write_html_escaped(fp, repos[i].branch);
-	    fputs("</td><td><code>", fp);
-	    write_html_escaped(fp, repos[i].head);
-	    fputs("</code></td><td>", fp);
-	    write_html_escaped(fp, repos[i].last_date);
-	    fputs("</td></tr>\n", fp);
-	}
-	fputs("</tbody>\n</table>\n</body>\n</html>\n", fp);
-
-	if (fclose(fp) == EOF)
-	    err(1, "fclose %s", path);
-	free(path);
-=======
   FILE *fp;
   char *path;
   size_t i;
@@ -3194,31 +1651,11 @@ make_index(const char *outdir, struct repo *repos, size_t nrepos)
   if (fclose(fp) == EOF)
       err(1, "fclose %s", path);
   free(path);
->>>>>>> ee3b035 (init)
 }
 
 static void
 free_repos(struct repo *repos, size_t nrepos)
 {
-<<<<<<< HEAD
-	size_t i;
-
-	for (i = 0; i < nrepos; i++) {
-	    free(repos[i].branch);
-	    free(repos[i].cloneurl);
-	    free(repos[i].head);
-	    free(repos[i].last_author);
-	    free(repos[i].last_date);
-	    free(repos[i].last_subject);
-	    free(repos[i].name);
-	    free(repos[i].owner);
-	    free(repos[i].outdir);
-	    free(repos[i].path);
-	    free(repos[i].rootlink_deep);
-	    free(repos[i].rootlink_repo);
-	}
-	free(repos);
-=======
   size_t i;
 
   for (i = 0; i < nrepos; i++) {
@@ -3236,5 +1673,4 @@ free_repos(struct repo *repos, size_t nrepos)
       free(repos[i].rootlink_repo);
   }
   free(repos);
->>>>>>> ee3b035 (init)
 }