By closing the file descriptors after creating the lock file we are not
limiting the size of the transaction by the number of available file
descriptors.

When closing the file descriptors early, we also need to write the values
in early, if we don't want to reopen the files.

Signed-off-by: Stefan Beller <sbel...@google.com>
---

Notes:
    version3:
    * Do not reopen the files after closing them. Make sure we have
      written all necessary information before closing the file.
      Doing it that way enabled us to drop the patch "[PATCH 4/6]
      refs.c: Have a write_in_full_to_lock_file wrapping write_in_full"

 refs.c                | 15 ++++++++++++---
 t/t1400-update-ref.sh |  4 ++--
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/refs.c b/refs.c
index 1bfc84b..2594b23 100644
--- a/refs.c
+++ b/refs.c
@@ -3752,6 +3752,17 @@ int ref_transaction_commit(struct ref_transaction 
*transaction,
                                    update->refname);
                        goto cleanup;
                }
+               if (!is_null_sha1(update->new_sha1)) {
+                       if (write_ref_sha1(update->lock, update->new_sha1,
+                                          update->msg)) {
+                               strbuf_addf(err, "Cannot write to the ref lock 
'%s'.",
+                                           update->refname);
+                               ret = TRANSACTION_GENERIC_ERROR;
+                               goto cleanup;
+                       }
+               }
+               /* Do not keep all lock files open at the same time. */
+               close_ref(update->lock);
        }
 
        /* Perform updates first so live commits remain referenced */
@@ -3759,9 +3770,7 @@ int ref_transaction_commit(struct ref_transaction 
*transaction,
                struct ref_update *update = updates[i];
 
                if (!is_null_sha1(update->new_sha1)) {
-                       if (write_ref_sha1(update->lock, update->new_sha1,
-                                          update->msg)
-                           || commit_ref(update->lock, update->new_sha1)) {
+                       if (commit_ref(update->lock, update->new_sha1)) {
                                strbuf_addf(err, "Cannot update the ref '%s'.",
                                            update->refname);
                                ret = TRANSACTION_GENERIC_ERROR;
diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh
index 47d2fe9..c593a1d 100755
--- a/t/t1400-update-ref.sh
+++ b/t/t1400-update-ref.sh
@@ -979,7 +979,7 @@ run_with_limited_open_files () {
 
 test_lazy_prereq ULIMIT_FILE_DESCRIPTORS 'run_with_limited_open_files true'
 
-test_expect_failure ULIMIT_FILE_DESCRIPTORS 'large transaction creating 
branches does not burst open file limit' '
+test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating 
branches does not burst open file limit' '
 (
        for i in $(test_seq 33)
        do
@@ -990,7 +990,7 @@ test_expect_failure ULIMIT_FILE_DESCRIPTORS 'large 
transaction creating branches
 )
 '
 
-test_expect_failure ULIMIT_FILE_DESCRIPTORS 'large transaction deleting 
branches does not burst open file limit' '
+test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting 
branches does not burst open file limit' '
 (
        for i in $(test_seq 33)
        do
-- 
2.2.1.62.g3f15098

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to