From 55b823b226194cd25864f1b61bc5b4f343e4e822 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 7 Dec 2015 21:16:28 +0100 Subject: [PATCH] fix when commit has no parent also dont show parent when there is no id for it. --- urmoms.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/urmoms.c b/urmoms.c index ab370ea..64a7737 100644 --- a/urmoms.c +++ b/urmoms.c @@ -168,7 +168,7 @@ printcommit(FILE *fp, git_commit *commit) fprintf(fp, "commit %s\n", relpath, buf, buf); - if (git_oid_tostr(buf, sizeof(buf), git_commit_parent_id(commit, 0))) + if (git_oid_tostr(buf, sizeof(buf), git_commit_parent_id(commit, 0)) && buf[0]) fprintf(fp, "parent %s\n", relpath, buf, buf); @@ -225,12 +225,15 @@ printshowfile(git_commit *commit) writeheader(fp); printcommit(fp, commit); - if ((error = git_commit_parent(&parent, commit, 0))) - return; if ((error = git_commit_tree(&commit_tree, commit))) goto err; - if ((error = git_commit_tree(&parent_tree, parent))) - goto err; + if (!(error = git_commit_parent(&parent, commit, 0))) { + if ((error = git_commit_tree(&parent_tree, parent))) + goto err; /* TODO: handle error */ + } else { + parent = NULL; + parent_tree = NULL; + } if ((error = git_diff_tree_to_tree(&diff, repo, parent_tree, commit_tree, NULL))) goto err; @@ -334,7 +337,7 @@ writelog(FILE *fp) size_t i, nfiles, ndel, nadd; const char *summary; char buf[GIT_OID_HEXSZ + 1]; - int error; + int error, ret = 0; mkdir("commit", 0755); @@ -352,14 +355,20 @@ writelog(FILE *fp) relpath = ""; - if (git_commit_lookup(&commit, repo, &id)) - return 1; /* TODO: error */ - if ((error = git_commit_parent(&parent, commit, 0))) - continue; /* TODO: handle error */ + if (git_commit_lookup(&commit, repo, &id)) { + ret = 1; + goto err; + } if ((error = git_commit_tree(&commit_tree, commit))) - continue; /* TODO: handle error */ - if ((error = git_commit_tree(&parent_tree, parent))) - continue; /* TODO: handle error */ + goto errdiff; /* TODO: handle error */ + if (!(error = git_commit_parent(&parent, commit, 0))) { + if ((error = git_commit_tree(&parent_tree, parent))) + goto errdiff; /* TODO: handle error */ + } else { + parent = NULL; + parent_tree = NULL; + } + if ((error = git_diff_tree_to_tree(&diff, repo, parent_tree, commit_tree, NULL))) continue; /* TODO: handle error */ if (git_diff_get_stats(&stats, diff)) @@ -399,14 +408,16 @@ writelog(FILE *fp) relpath = "../"; printshowfile(commit); +errdiff: git_diff_free(diff); git_commit_free(commit); } fprintf(fp, ""); +err: git_revwalk_free(w); relpath = ""; - return 0; + return ret; } void @@ -439,7 +450,7 @@ printcommitatom(FILE *fp, git_commit *commit) fputs("", fp); fprintf(fp, "commit %s\n", buf); - if (git_oid_tostr(buf, sizeof(buf), git_commit_parent_id(commit, 0))) + if (git_oid_tostr(buf, sizeof(buf), git_commit_parent_id(commit, 0)) && buf[0]) fprintf(fp, "parent %s\n", buf); if ((count = (int)git_commit_parentcount(commit)) > 1) { -- libgit2 1.1.1