From: Linus Torvalds <torva...@linux-foundation.org> Date: Sun, 27 Apr 2014 18:18:12 -0700 Subject: [PATCH] make git save commit messages more informative
Instead of just having "Created by subsurface <version>", put the number of dives and the location of the last dive in the message. That makes things like "gitk" show a much more useful view of what actually got saved. We still save the subsurface version in the body of the message, because that is interesting and relevant information. It's just not the *primary* relevant information. Anyway, with this, a git commit message might looke something like dive 474: North West Point (Christmas Island) Created by subsurface 4.0.96-17-g649e9ed89d9d which is much more relevant for the common case of adding new dives at the end. Of course, if the reason for the save is that you edited old dives, the relevance of the commit message telling you the number of dives you have in the log and the dive number is questionable. But then you have to look at the actual diff to see what's going on. Signed-off-by: Linus Torvalds <torva...@linux-foundation.org> --- NOTE! If you were to just save a subset of dives (ie "save selected"), we'll still pick the last dive you had globally, not the last dive actually saved. I couldn't find it in myself to care too deeply, the git format is unlikely to be used for partial saves. This really does make the logs look much better. Not that I'll have much proof of it until the next dive trip (soon, soon), but the fake testing I did make it look way better in gitk than just seeing that "Created by" repeated over and over. save-git.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/save-git.c b/save-git.c index e418b9830780..169f5a1c6736 100644 --- a/save-git.c +++ b/save-git.c @@ -833,6 +833,26 @@ static int get_authorship(git_repository *repo, git_signature **authorp) #endif } +static void create_commit_message(struct membuffer *msg) +{ + int nr = dive_table.nr; + struct dive *dive = get_dive(nr-1); + + if (dive) { + dive_trip_t *trip = dive->divetrip; + const char *location = dive->location ? : "no location"; + + if (dive->number) + nr = dive->number; + + put_format(msg, "dive %d: %s", nr, location); + if (trip->location && *trip->location && strcmp(trip->location, location)) + put_format(msg, " (%s)", trip->location); + put_format(msg, "\n\n"); + } + put_format(msg, "Created by subsurface %s\n", VERSION_STRING); +} + static int create_new_commit(git_repository *repo, const char *branch, git_oid *tree_id) { int ret; @@ -842,7 +862,6 @@ static int create_new_commit(git_repository *repo, const char *branch, git_oid * git_signature *author; git_commit *commit; git_tree *tree; - struct membuffer commit_msg = { 0 }; ret = git_branch_lookup(&ref, repo, branch, GIT_BRANCH_LOCAL); switch (ret) { @@ -882,9 +901,12 @@ static int create_new_commit(git_repository *repo, const char *branch, git_oid * /* Else we do want to create the new branch, but with the old commit */ commit = (git_commit *) parent; } else { - put_format(&commit_msg, "Created by subsurface %s\n", VERSION_STRING); + struct membuffer commit_msg = { 0 }; + + create_commit_message(&commit_msg); if (git_commit_create_v(&commit_id, repo, NULL, author, author, NULL, mb_cstring(&commit_msg), tree, parent != NULL, parent)) return report_error("Git commit create failed (%s)", strerror(errno)); + free_buffer(&commit_msg); if (git_commit_lookup(&commit, repo, &commit_id)) return report_error("Could not look up newly created commit"); -- 2.0.0.rc1 _______________________________________________ subsurface mailing list subsurface@hohndel.org http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface