diff options
| author | Ronnie Sahlberg <sahlberg@google.com> | 2014-07-23 10:03:48 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2014-09-03 10:15:50 -0700 |
| commit | 2679332664656b13836e6c09516736b2861d850e (patch) | |
| tree | 7aecec16fd2aa863c33dc5560713805cc37f8297 | |
| parent | 0cd0dea5b16d542e70e09c059679a5c1c34bdd1d (diff) | |
| download | git-2679332664656b13836e6c09516736b2861d850e.tar.gz | |
refs.c: add a flag to allow reflog updates to truncate the log
Add a flag that allows us to truncate the reflog before we write the
update.
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
| -rw-r--r-- | refs.c | 17 | ||||
| -rw-r--r-- | refs.h | 10 |
2 files changed, 24 insertions, 3 deletions
@@ -3748,7 +3748,12 @@ int transaction_commit(struct ref_transaction *transaction, } } - /* Update all reflog files */ + /* + * Update all reflog files + * We have already done all ref updates and deletes. + * There is not much we can do here if there are any reflog + * update errors other than complain. + */ for (i = 0; i < n; i++) { struct ref_update *update = updates[i]; @@ -3756,7 +3761,15 @@ int transaction_commit(struct ref_transaction *transaction, continue; if (update->reflog_fd == -1) continue; - + if (update->flags & REFLOG_TRUNCATE) + if (lseek(update->reflog_fd, 0, SEEK_SET) < 0 || + ftruncate(update->reflog_fd, 0)) { + error("Could not truncate reflog: %s. %s", + update->refname, strerror(errno)); + rollback_lock_file(&update->reflog_lock); + update->reflog_fd = -1; + continue; + } if (log_ref_write_fd(update->reflog_fd, update->old_sha1, update->new_sha1, update->committer, update->msg)) { @@ -320,7 +320,15 @@ int transaction_delete_sha1(struct ref_transaction *transaction, struct strbuf *err); /* - * Append a reflog entry for refname. + * Flags controlling transaction_update_reflog(). + * REFLOG_TRUNCATE: Truncate the reflog. + * + * Flags >= 0x100 are reserved for internal use. + */ +#define REFLOG_TRUNCATE 0x01 +/* + * Append a reflog entry for refname. If the REFLOG_TRUNCATE flag is set + * this update will first truncate the reflog before writing the entry. */ int transaction_update_reflog(struct ref_transaction *transaction, const char *refname, |
