summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonnie Sahlberg <sahlberg@google.com>2014-07-23 10:03:48 -0700
committerJunio C Hamano <gitster@pobox.com>2014-09-03 10:15:50 -0700
commit2679332664656b13836e6c09516736b2861d850e (patch)
tree7aecec16fd2aa863c33dc5560713805cc37f8297
parent0cd0dea5b16d542e70e09c059679a5c1c34bdd1d (diff)
downloadgit-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.c17
-rw-r--r--refs.h10
2 files changed, 24 insertions, 3 deletions
diff --git a/refs.c b/refs.c
index 4fcef5291d..01d5ed5a97 100644
--- a/refs.c
+++ b/refs.c
@@ -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)) {
diff --git a/refs.h b/refs.h
index 479615f84e..2234750cf8 100644
--- a/refs.h
+++ b/refs.h
@@ -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,