* Feature Request: show ages in tree view
@ 2016-10-30 12:22
2016-11-24 18:56 ` john
0 siblings, 1 reply; 2+ messages in thread
From: @ 2016-10-30 12:22 UTC (permalink / raw)
Hello,
i want to see when a file or tree was last changed when i'm watching the tree of a repository.
I've tried to implement it myself, but it seems i can't, though i have something to illustrate what i mean.
diff --git a/ui-tree.c b/ui-tree.c
index b310242..78e5676 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -232,6 +232,10 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base,
enum object_type type;
unsigned long size = 0;
+ struct commitinfo *info;
+ struct commit *commit;
+ unsigned char c_sha1[20];
+
name = xstrdup(pathname);
strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "",
ctx.qry.path ? "/" : "", name);
@@ -247,6 +251,10 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base,
}
}
+ get_sha1(walk_tree_ctx->curr_rev, c_sha1);
+ commit = lookup_commit_reference(c_sha1);
+ info = cgit_parse_commit(commit);
+
html("<tr><td class='ls-mode'>");
cgit_print_filemode(mode);
html("</td><td>");
@@ -255,6 +263,8 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base,
} else if (S_ISDIR(mode)) {
write_tree_link(sha1, name, walk_tree_ctx->curr_rev,
&fullpath);
+ html("</td><td style='text-align:right'>");
+ cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2);
} else {
char *ext = strrchr(name, '.');
strbuf_addstr(&class, "ls-blob");
@@ -262,6 +272,8 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base,
strbuf_addf(&class, " %s", ext + 1);
cgit_tree_link(name, NULL, class.buf, ctx.qry.head,
walk_tree_ctx->curr_rev, fullpath.buf);
+ html("</td><td style='text-align:right'>");
+ cgit_print_age(info->committer_date, info->committer_tz, TM_WEEK * 2);
}
htmlf("</td><td class='ls-size'>%li</td>", size);
@@ -289,6 +301,7 @@ static void ls_head(void)
html("<tr class='nohover'>");
html("<th class='left'>Mode</th>");
html("<th class='left'>Name</th>");
+ html("<th class='right'>Age</th>");
html("<th class='right'>Size</th>");
html("<th/>");
html("</tr>\n");
^ permalink raw reply [flat|nested] 2+ messages in thread
* Feature Request: show ages in tree view
2016-10-30 12:22 Feature Request: show ages in tree view
@ 2016-11-24 18:56 ` john
0 siblings, 0 replies; 2+ messages in thread
From: john @ 2016-11-24 18:56 UTC (permalink / raw)
On Sun, Oct 30, 2016 at 01:22:24PM +0100, Silly Slux wrote:
> i want to see when a file or tree was last changed when i'm watching
> the tree of a repository. I've tried to implement it myself, but it
> seems i can't, though i have something to illustrate what i mean.
This is going to be quite a costly operation because it entails walking
back along the commit graph to see when the relevant path last changed.
The algorithm for doing this has to get the SHA-1 associated with the
tree/blob representing the path of interest and then finding the most
recent commit with a different SHA-1 at that location. Obviously at
merges all parents have to be added to the list of interesting commits.
If you want to try to implement this, Git's commit_list_insert_by_date
function is probably useful for sorting the parent commits. You can see
how this is used in git/builtin/describe.c::describe() which looks to
have the right structure for walking backwards in the history, then you
just need to get the SHA-1 of the relevant path and break as soon as it
changes.
I expect there's a relatively obvious optimization when we're printing
the contents of a tree object to avoid walking the history for every
path that is printed, but I haven't thought about this in detail.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-11-24 18:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-30 12:22 Feature Request: show ages in tree view
2016-11-24 18:56 ` john
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).