diff options
author | John Keeping <john@keeping.me.uk> | 2015-08-12 14:55:28 +0000 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2015-08-12 14:57:46 +0000 |
commit | 30304d8156a72ffc95e45e1aa9407319b81bd253 (patch) | |
tree | c3f8220fb2abfa0da7f7f0b479415db42820d838 /ui-shared.c | |
parent | 044e2d26da4f8b4f9ff25e4a729ab4e393073b5e (diff) | |
download | cgit-30304d8156a72ffc95e45e1aa9407319b81bd253.tar cgit-30304d8156a72ffc95e45e1aa9407319b81bd253.tar.gz cgit-30304d8156a72ffc95e45e1aa9407319b81bd253.zip |
log: allow users to follow a file
Teach the "log" UI to behave in the same way as "git log --follow", when
given a suitable instruction by the user. The default behaviour remains
to show the log without following renames, but the follow behaviour can
be activated by following a link in the page header.
Follow is not the default because outputting merges in follow mode is
tricky ("git log --follow" will not show merges). We also disable the
graph in follow mode because the commit graph is not simplified so we
end up with frequent gaps in the graph and many lines that do not
connect with any commits we're actually showing.
We also teach the "diff" and "commit" UIs to respect the follow flag on
URLs, causing the single-file version of these UIs to detect renames.
This feature is needed only for commits that rename the path we're
interested in.
For commits before the file has been renamed (i.e. that appear later in
the log list) we change the file path in the links from the log to point
to the old name; this means that links to commits always limit by the
path known to that commit. If we didn't do this we would need to walk
down the log diff'ing every commit whenever we want to show a commit.
The drawback is that the "Log" link in the top bar of such a page links
to the log limited by the old name, so it will only show pre-rename
commits. I consider this a reasonable trade-off since the "Back" button
still works and the log matches the path displayed in the top bar.
Since following renames requires running diff on every commit we
consider, I've added a knob to the configuration file to globally
enable/disable this feature. Note that we may consider a large number
of commits the revision walking machinery no longer performs any path
limitation so we have to examine every commit until we find a page full
of commits that affect the target path or something related to it.
Suggested-by: René Neumann <necoro@necoro.eu>
Signed-off-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'ui-shared.c')
-rw-r--r-- | ui-shared.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/ui-shared.c b/ui-shared.c index 4f84b7c..6be0c2e 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -303,7 +303,8 @@ void cgit_plain_link(const char *name, const char *title, const char *class, void cgit_log_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path, - int ofs, const char *grep, const char *pattern, int showmsg) + int ofs, const char *grep, const char *pattern, int showmsg, + int follow) { char *delim; @@ -332,6 +333,11 @@ void cgit_log_link(const char *name, const char *title, const char *class, if (showmsg) { html(delim); html("showmsg=1"); + delim = "&"; + } + if (follow) { + html(delim); + html("follow=1"); } html("'>"); html_txt(name); @@ -373,6 +379,10 @@ void cgit_commit_link(char *name, const char *title, const char *class, html("ignorews=1"); delim = "&"; } + if (ctx.qry.follow) { + html(delim); + html("follow=1"); + } html("'>"); if (name[0] != '\0') html_txt(name); @@ -429,6 +439,10 @@ void cgit_diff_link(const char *name, const char *title, const char *class, html("ignorews=1"); delim = "&"; } + if (ctx.qry.follow) { + html(delim); + html("follow=1"); + } html("'>"); html_txt(name); html("</a>"); @@ -469,7 +483,7 @@ static void cgit_self_link(char *name, const char *title, const char *class) ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, ctx.qry.path, ctx.qry.ofs, ctx.qry.grep, ctx.qry.search, - ctx.qry.showmsg); + ctx.qry.showmsg, ctx.qry.follow); else if (!strcmp(ctx.qry.page, "commit")) cgit_commit_link(name, title, class, ctx.qry.head, ctx.qry.has_sha1 ? ctx.qry.sha1 : NULL, @@ -945,7 +959,7 @@ void cgit_print_pageheader(void) ctx.qry.sha1, NULL); cgit_log_link("log", NULL, hc("log"), ctx.qry.head, NULL, ctx.qry.vpath, 0, NULL, NULL, - ctx.qry.showmsg); + ctx.qry.showmsg, ctx.qry.follow); cgit_tree_link("tree", NULL, hc("tree"), ctx.qry.head, ctx.qry.sha1, ctx.qry.vpath); cgit_commit_link("commit", NULL, hc("commit"), @@ -993,6 +1007,14 @@ void cgit_print_pageheader(void) html("<div class='path'>"); html("path: "); cgit_print_path_crumbs(ctx.qry.vpath); + if (ctx.cfg.enable_follow_links && !strcmp(ctx.qry.page, "log")) { + html(" ("); + ctx.qry.follow = !ctx.qry.follow; + cgit_self_link(ctx.qry.follow ? "follow" : "unfollow", + NULL, NULL); + ctx.qry.follow = !ctx.qry.follow; + html(")"); + } html("</div>"); } html("<div class='content'>"); |