root/git/ui-log.c
/*DEFINITIONS
This source file includes following definitions.1 #include <stdio.h> 2 #include <string.h> 3 #include <git2.h> 4 5 #include "html.h" 6 #include "ui-log.h" 7 #include "git.h" 8 9 static int 10 log_filter(git_commit *commit) 11 { 12 git_commit *pcommit = NULL; 13 git_tree *root, *proot = NULL; 14 git_tree_entry *entry = NULL, *pentry = NULL; 15 git_object *object = NULL, *pobject = NULL; 16 17 /* we aren't searching for a file */ 18 if (query.path[0] == '\0') 19 return 0; 20 21 check_sgerr(git_commit_tree(&root, commit)); 22 git_tree_entry_bypath(&entry, root, query.path); 23 24 /* the file does not exist in this tree */ 25 if (!entry) return 1; 26 27 check_sgerr(git_tree_entry_to_object(&object, grepo, entry)); 28 git_commit_parent(&pcommit, commit, 0); 29 30 /* there is no parent, file was created here */ 31 if (!pcommit) return 0; 32 33 check_sgerr(git_commit_tree(&proot, pcommit)); 34 git_tree_entry_bypath(&pentry, proot, query.path); 35 36 /* parent does not contain file, file was created here */ 37 if (!pentry) return 0; 38 39 check_sgerr(git_tree_entry_to_object(&pobject, grepo, pentry)); 40 41 /* commit and parent object ids for file haven't changed, no change */ 42 if (git_oid_cmp(git_object_id(object), git_object_id(pobject)) == 0) 43 return 1; 44 45 git_object_free(object); 46 git_object_free(pobject); 47 git_tree_entry_free(pentry); 48 git_tree_entry_free(entry); 49 git_tree_free(root); 50 git_tree_free(proot); 51 git_commit_free(pcommit); 52 53 return 0; 54 } 55 56 57 static void 58 dump_commit_le(git_commit *commit) { 59 git_commit *parent = NULL; 60 git_diff *diff; 61 git_diff_stats *stats; 62 63 git_commit_parent(&parent, commit, 0); 64 diff = commit_to_diff(commit, parent); 65 check_sgerr(git_diff_get_stats(&stats, diff)); 66 67 html("<tr>\n\ 68 <td class=\"git-long\">%s</td>\n\ 69 <td class=\"git-flat\">%s</td>\n\ 70 <td class=\"git-flat\">%s</td>\n\ 71 <td class=\"git-flat\">%zu</td>\n\ 72 <td class=\"git-flat\">\n\ 73 <span class=\"git-del\">-%zu</span>/<span class=\"git-add\">+%zu\ 74 </span></td>\n\ 75 </tr>\n", 76 my_html_make_link( 77 make_query_simple( 78 T_COMMIT, 79 git_commit_id(commit), 80 NULL), 81 make_tag_summary(commit)), 82 83 my_html_encode(git_commit_author(commit)->name), 84 85 check_sptr(readable_time(git_commit_time(commit))), 86 87 git_diff_stats_files_changed(stats), 88 git_diff_stats_deletions(stats), 89 git_diff_stats_insertions(stats)); 90 91 git_diff_stats_free(stats); 92 git_diff_free(diff); 93 git_commit_free(parent); 94 } 95 96 97 void 98 dump_commits(void) { 99 git_revwalk *walker; 100 git_commit *commit; 101 git_oid oid; 102 int i = 0; 103 104 check_sgerr(git_revwalk_new(&walker, grepo)); 105 check_sgerr(git_revwalk_push(walker, gbase)); 106 check_sgerr(git_revwalk_sorting(walker, 107 GIT_SORT_TOPOLOGICAL | 108 GIT_SORT_TIME)); 109 html_table_begin(5, "Message", "Author", "Date", "Files", "Lines"); 110 while (!git_revwalk_next(&oid, walker)) { 111 check_sgerr(git_commit_lookup(&commit, grepo, &oid)); 112 if (log_filter(commit) > 0) continue; 113 if (i >= 50) { 114 html_table_end(); 115 html("<span class=\"git-sb\">\n\ 116 [%s]\n\ 117 </span>\n", my_html_make_link( 118 make_query_simple(0, git_commit_id(commit), NULL), 119 "next")); 120 return; 121 } 122 dump_commit_le(commit); 123 git_commit_free(commit); 124 i++; 125 } 126 html_table_end(); 127 git_revwalk_free(walker); 128 }
/*