summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonnie Sahlberg <sahlberg@google.com>2014-11-03 08:55:51 -0800
committerJunio C Hamano <gitster@pobox.com>2014-11-03 11:16:58 -0800
commit77c70c73faa5feea44764649a76b096c63f7cb13 (patch)
treeecdb5bf10df479af6bbf545e4be21b088d0ddc50
parent9d22e2507795f604bd26bd5ed714981b48b6fb9d (diff)
downloadgit-77c70c73faa5feea44764649a76b096c63f7cb13.tar.gz
refs.c: only write reflog update if msg is non-NULL
When performing a reflog transaction update, only write to the reflog iff msg is non-NULL. This can then be combined with REFLOG_TRUNCATE to perform an update that only truncates but does not write. This change only affects whether or not a reflog entry should be generated and written. If msg==NULL then no such entry will be written. Orthogonal to this we have a boolean flag REFLOG_TRUNCATE which is used to tell the transaction system to "truncate the reflog and thus discard all previous users". At the current time the only place where we use msg==NULL is also the place where we use REFLOG_TRUNCATE. Even though these two settings are currently only ever used together, it still makes sense to have them through two separate knobs. This allows future consumers of this API that may want to do things differently. For example someone can do: msg="Reflog truncated by Bob because ..." + REFLOG_TRUNCATE and have it truncate the log and have it start fresh with an initial message that explains the log was truncated. This API allows that. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--refs.c5
-rw-r--r--refs.h1
2 files changed, 4 insertions, 2 deletions
diff --git a/refs.c b/refs.c
index d54c3b98b3..f14b76eb8f 100644
--- a/refs.c
+++ b/refs.c
@@ -3895,8 +3895,9 @@ int transaction_commit(struct transaction *transaction,
update->reflog_fd = -1;
continue;
}
- if (log_ref_write_fd(update->reflog_fd, update->old_sha1,
- update->new_sha1,
+ if (update->msg &&
+ log_ref_write_fd(update->reflog_fd,
+ update->old_sha1, update->new_sha1,
update->committer, update->msg)) {
error("Could write to reflog: %s. %s",
update->refname, strerror(errno));
diff --git a/refs.h b/refs.h
index 50750734c4..bf96b363a6 100644
--- a/refs.h
+++ b/refs.h
@@ -337,6 +337,7 @@ int transaction_delete_ref(struct transaction *transaction,
/*
* Append a reflog entry for refname. If the REFLOG_TRUNCATE flag is set
* this update will first truncate the reflog before writing the entry.
+ * If msg is NULL no update will be written to the log.
*/
int transaction_update_reflog(struct transaction *transaction,
const char *refname,