- commit
- dd1c8d7bf63d2f6cdfc10999c8090d66dac41395
- parent
- 5f4be9680178be9547b675a386669ba5c9145373
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-09-05 11:03
refactor: get diff in process_commits()
Diffstat
M | src/stagit.c.in | 20 | +++++++++----------- |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/stagit.c.in b/src/stagit.c.in
@@ -207,23 +207,19 @@ err: 207 207 } 208 208 209 209 struct commitstats *210 -1 commitinfo_getstats(struct commitinfo *ci)-1 210 commitinfo_getstats(git_diff *diff) 211 211 { 212 212 struct commitstats *cs; 213 213 struct deltainfo *di; 214 214 const git_diff_delta *delta; 215 215 const git_diff_hunk *hunk; 216 216 const git_diff_line *line;217 -1 git_diff *diff;218 217 git_patch *patch = NULL; 219 218 size_t ndeltas, nhunks, nhunklines, i, j, k; 220 219 221 220 if (!(cs = calloc(1, sizeof(struct commitstats)))) 222 221 err(1, "calloc"); 223 222224 -1 if (git_commit_get_diff(&diff, ci->commit))225 -1 goto err;226 -1227 223 ndeltas = git_diff_num_deltas(diff); 228 224 if (ndeltas && !(cs->deltas = calloc(ndeltas, sizeof(struct deltainfo *)))) 229 225 err(1, "calloc"); @@ -262,9 +258,6 @@ commitinfo_getstats(struct commitinfo *ci) 262 258 } 263 259 cs->ndeltas = i; 264 260265 -1 git_diff_free(diff);266 -1267 -1 err:268 261 return cs; 269 262 } 270 263 @@ -477,10 +470,10 @@ write_commit_file(FILE *fp, struct deltainfo *di, size_t i) 477 470 } 478 471 479 472 void480 -1 write_commit(FILE *fp, struct commitinfo *ci)-1 473 write_commit(FILE *fp, struct commitinfo *ci, git_diff *diff) 481 474 { 482 475 size_t i;483 -1 struct commitstats *cs = commitinfo_getstats(ci);-1 476 struct commitstats *cs = commitinfo_getstats(diff); 484 477 485 478 T("<dl>\n"); 486 479 T("<dt>commit</dt><dd><a href=\"\">{ci->oid:%s}</a></dd>\n"); @@ -758,6 +751,7 @@ process_commits(FILE *fp_log, FILE *fp_atom, size_t m) 758 751 struct commitinfo *ci; 759 752 git_revwalk *w = NULL; 760 753 git_oid id; -1 754 git_diff *diff; 761 755 FILE *fp_commit; 762 756 char path[PATH_MAX], oidstr[GIT_OID_HEXSZ + 1]; 763 757 @@ -772,6 +766,9 @@ process_commits(FILE *fp_log, FILE *fp_atom, size_t m) 772 766 if (!(ci = commitinfo_getbyoid(&id))) 773 767 break; 774 768 -1 769 if (git_commit_get_diff(&diff, ci->commit)) -1 770 break; -1 771 775 772 write_log_line(fp_log, ci); 776 773 write_atom_entry(fp_atom, ci); 777 774 @@ -782,12 +779,13 @@ process_commits(FILE *fp_log, FILE *fp_atom, size_t m) 782 779 mkdirp("commit"); 783 780 fp_commit = efopen(path, "w"); 784 781 write_header(fp_commit, ci->summary, "../");785 -1 write_commit(fp_commit, ci);-1 782 write_commit(fp_commit, ci, diff); 786 783 write_footer(fp_commit); 787 784 fclose(fp_commit); 788 785 } 789 786 790 787 m -= 1; -1 788 git_diff_free(diff); 791 789 commitinfo_free(ci); 792 790 } 793 791 git_revwalk_free(w);