mirror of
https://github.com/git/git.git
synced 2026-03-02 03:26:24 +00:00
ref_transaction_commit(): remove local variable n
This microoptimization doesn't make a significant difference in speed. And it causes problems if somebody ever wants to modify the function to add updates to a transaction as part of processing it, as will happen shortly. Make the same change in initial_ref_transaction_commit(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
This commit is contained in:
@@ -3076,7 +3076,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||
struct strbuf *err)
|
||||
{
|
||||
int ret = 0, i;
|
||||
int n = transaction->nr;
|
||||
struct ref_update **updates = transaction->updates;
|
||||
struct string_list refs_to_delete = STRING_LIST_INIT_NODUP;
|
||||
struct string_list_item *ref_to_delete;
|
||||
@@ -3087,13 +3086,13 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||
if (transaction->state != REF_TRANSACTION_OPEN)
|
||||
die("BUG: commit called for transaction that is not open");
|
||||
|
||||
if (!n) {
|
||||
if (!transaction->nr) {
|
||||
transaction->state = REF_TRANSACTION_CLOSED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Fail if a refname appears more than once in the transaction: */
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < transaction->nr; i++)
|
||||
string_list_append(&affected_refnames, updates[i]->refname);
|
||||
string_list_sort(&affected_refnames);
|
||||
if (ref_update_reject_duplicates(&affected_refnames, err)) {
|
||||
@@ -3107,7 +3106,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||
* lockfiles, ready to be activated. Only keep one lockfile
|
||||
* open at a time to avoid running out of file descriptors.
|
||||
*/
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < transaction->nr; i++) {
|
||||
struct ref_update *update = updates[i];
|
||||
|
||||
if ((update->flags & REF_HAVE_NEW) &&
|
||||
@@ -3178,7 +3177,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||
}
|
||||
|
||||
/* Perform updates first so live commits remain referenced */
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < transaction->nr; i++) {
|
||||
struct ref_update *update = updates[i];
|
||||
|
||||
if (update->flags & REF_NEEDS_COMMIT) {
|
||||
@@ -3197,7 +3196,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||
}
|
||||
|
||||
/* Perform deletes now that updates are safely completed */
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < transaction->nr; i++) {
|
||||
struct ref_update *update = updates[i];
|
||||
|
||||
if (update->flags & REF_DELETING) {
|
||||
@@ -3223,7 +3222,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||
cleanup:
|
||||
transaction->state = REF_TRANSACTION_CLOSED;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < transaction->nr; i++)
|
||||
if (updates[i]->lock)
|
||||
unlock_ref(updates[i]->lock);
|
||||
string_list_clear(&refs_to_delete, 0);
|
||||
@@ -3243,7 +3242,6 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
|
||||
struct strbuf *err)
|
||||
{
|
||||
int ret = 0, i;
|
||||
int n = transaction->nr;
|
||||
struct ref_update **updates = transaction->updates;
|
||||
struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
|
||||
|
||||
@@ -3253,7 +3251,7 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
|
||||
die("BUG: commit called for transaction that is not open");
|
||||
|
||||
/* Fail if a refname appears more than once in the transaction: */
|
||||
for (i = 0; i < n; i++)
|
||||
for (i = 0; i < transaction->nr; i++)
|
||||
string_list_append(&affected_refnames, updates[i]->refname);
|
||||
string_list_sort(&affected_refnames);
|
||||
if (ref_update_reject_duplicates(&affected_refnames, err)) {
|
||||
@@ -3276,7 +3274,7 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
|
||||
if (for_each_rawref(ref_present, &affected_refnames))
|
||||
die("BUG: initial ref transaction called with existing refs");
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < transaction->nr; i++) {
|
||||
struct ref_update *update = updates[i];
|
||||
|
||||
if ((update->flags & REF_HAVE_OLD) &&
|
||||
@@ -3297,7 +3295,7 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < transaction->nr; i++) {
|
||||
struct ref_update *update = updates[i];
|
||||
|
||||
if ((update->flags & REF_HAVE_NEW) &&
|
||||
|
||||
Reference in New Issue
Block a user