diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-27 18:18:12 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-04-27 20:02:51 -0700 |
commit | de9360e2e00508000ab51daa126e6aa1149b24ad (patch) | |
tree | 75e854015e5574f3268624e01e1cbec1d11d0720 /save-git.c | |
parent | 4d48eb826279953d3809ec2420bcc3e848f4fa88 (diff) | |
download | subsurface-de9360e2e00508000ab51daa126e6aa1149b24ad.tar.gz |
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 <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'save-git.c')
-rw-r--r-- | save-git.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/save-git.c b/save-git.c index e418b9830..169f5a1c6 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"); |