From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Sat, 23 Sep 2017 16:47:14 +0100 Subject: [RFCv2 PATCH 2/7] ui-blame: create framework In-Reply-To: <20170923033848.5922-3-whydoubt@gmail.com> References: <20170608021810.12964-1-whydoubt@gmail.com> <20170923033848.5922-1-whydoubt@gmail.com> <20170923033848.5922-3-whydoubt@gmail.com> Message-ID: <20170923154714.GB2548@john.keeping.me.uk> On Fri, Sep 22, 2017 at 10:38:43PM -0500, Jeff Smith wrote: > Create framework for a page that will contain the 'blame' for a file > in the repository. > > Signed-off-by: Jeff Smith > --- > ui-blame.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ui-blame.h | 7 +++ > 2 files changed, 167 insertions(+) > create mode 100644 ui-blame.c > create mode 100644 ui-blame.h > > diff --git a/ui-blame.c b/ui-blame.c > new file mode 100644 > index 0000000..901ca89 > --- /dev/null > +++ b/ui-blame.c > @@ -0,0 +1,160 @@ > +/* ui-blame.c: functions for blame output > + * > + * Copyright (C) 2006-2017 cgit Development Team > + * > + * Licensed under GNU General Public License v2 > + * (see COPYING for full license text) > + */ > + > +#include "cgit.h" > +#include "ui-blame.h" > +#include "html.h" > +#include "ui-shared.h" > + > +struct walk_tree_context { > + char *curr_rev; > + int match_baselen; > + int state; > +}; > + > +static void set_title_from_path(const char *path) This looks exactly the same as the function in ui-tree.c, so can't we extract it to ui-shared.c? > +{ > + size_t path_len, path_index, path_last_end; > + char *new_title; > + > + if (!path) > + return; > + > + path_len = strlen(path); > + new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); > + new_title[0] = '\0'; > + > + for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { > + if (path[path_index] == '/') { > + if (path_index == path_len - 1) { > + path_last_end = path_index - 1; > + continue; > + } > + strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); > + strcat(new_title, "\\"); > + path_last_end = path_index; > + } > + } > + if (path_last_end) > + strncat(new_title, path, path_last_end); > + > + strcat(new_title, " - "); > + strcat(new_title, ctx.page.title); > + ctx.page.title = new_title; > +}