{"thread":{"id":"37213","subject":"[PATCH 1/5] refs.c: allow passing raw git_committer_info as email to _update_reflog","startedAt":"2014-07-25T16:58:36Z","lastAt":"2014-07-28T23:39:55Z","messageCount":13,"participants":["Ronnie Sahlberg","Jonathan Nieder","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"246713","messageId":"1406307521-10339-1-git-send-email-sahlberg@google.com","threadId":"37213","inReplyTo":null,"subject":"[PATCH 0/5] ref-transactions-rename","fromName":"Ronnie Sahlberg","fromEmail":"sahlberg@google.com","sentAt":"2014-07-25T16:58:36Z","receivedAt":"2014-07-25T16:58:36Z","isPatch":true,"sender":{"key":"sahlberg@google.com","avatar":"https://avatars.githubusercontent.com/u/7320636?v=4"},"body":"This patch series adds support for using transactions and atomic renames.\nIt focuses on what needs to be done in order to support fully atomic\nand rollbackable renames that may or may not involve name conflicts.\n\nBy performing the actual delete old/create new via a single operation to\nthe packed refs file this process will also appear as an atomic change for\nany external observers.\n\n(While this series is \"short\" it contains a very important change where\nwe start performing ref changes as operations inside a locked packed refs\nfile instead of as discreete operations of loose ref files.\nThis approach will be extended in the next patch series where we will start\nusing it also to make multi-ref creations/updates become fully\natomic for external observers.)\n\n\nThis series is built on iand depend on the previous reflog series:\n  * rs/ref-transaction-reflog (2014-07-23) 15 commits\n   - refs.c: allow deleting refs with a broken sha1\n   - refs.c: remove lock_any_ref_for_update\n   - refs.c: make unlock_ref/close_ref/commit_ref static\n   - refs.c: rename log_ref_setup to create_reflog\n   - reflog.c: use a reflog transaction when writing during expire\n   - refs.c: allow multiple reflog updates during a single transaction\n   - refs.c: only write reflog update if msg is non-NULL\n   - refs.c: add a flag to allow reflog updates to truncate the log\n   - refs.c: add a transaction function to append a reflog entry\n   - lockfile.c: make hold_lock_file_for_append preserve meaningful errno\n   - refs.c: add a function to append a reflog entry to a fd\n   - refs.c: add a new update_type field to ref_update\n   - refs.c: rename the transaction functions\n   - refs.c: make ref_transaction_delete a wrapper for ref_transaction_update\n   - refs.c: make ref_transaction_create a wrapper to ref_transaction_update\n   (this branch uses rs/ref-transaction and rs/ref-transaction-1.)\n\n\nRonnie Sahlberg (5):\n  refs.c: allow passing raw git_committer_info as email to\n    _update_reflog\n  refs.c: return error instead of dying when locking fails during\n    transaction\n  refs.c: use packed refs when deleting refs during a transaction\n  refs.c: update rename_ref to use a transaction\n  refs.c: rollback the lockfile before we die() in repack_without_refs\n\n builtin/remote.c  |  13 +-\n refs.c            | 369 +++++++++++++++++++++++++++++-------------------------\n refs.h            |   1 +\n t/t3200-branch.sh |   7 --\n 4 files changed, 210 insertions(+), 180 deletions(-)\n\n-- \n2.0.1.508.g763ab16\n"},{"id":"246712","messageId":"1406307521-10339-2-git-send-email-sahlberg@google.com","threadId":"37213","inReplyTo":"1406307521-10339-1-git-send-email-sahlberg@google.com","subject":"[PATCH 1/5] refs.c: allow passing raw git_committer_info as email to _update_reflog","fromName":"Ronnie Sahlberg","fromEmail":"sahlberg@google.com","sentAt":"2014-07-25T16:58:37Z","receivedAt":"2014-07-25T16:58:37Z","isPatch":true,"sender":{"key":"sahlberg@google.com","avatar":"https://avatars.githubusercontent.com/u/7320636?v=4"},"body":"In many places in the code we do not have access to the individual fields\nin the committer data. Instead we might only have access to prebaked data\nsuch as what is returned by git_committer_info() containing a string\nthat consists of email, timestamp, zone etc.\n\nThis makes it inconvenient to use transaction_update_reflog since it means\nyou would have to first parse git_committer_info before you can call\nupdate_reflog.\n\nAdd a new flag REFLOG_EMAIL_IS_COMMITTER to _update_reflog to tell it\nthat what we pass in as email is already the fully baked committer string\nwe can use as-is.\n\nSigned-off-by: Ronnie Sahlberg <sahlberg@google.com>\n---\n refs.c | 20 ++++++++++++--------\n refs.h |  1 +\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 2662ef6..6c55032 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -3522,14 +3522,18 @@ int transaction_update_reflog(struct ref_transaction *transaction,\n \thashcpy(update->old_sha1, old_sha1);\n \tupdate->reflog_fd = -1;\n \tif (email) {\n-\t\tstruct strbuf buf = STRBUF_INIT;\n-\t\tchar sign = (tz < 0) ? '-' : '+';\n-\t\tint zone = (tz < 0) ? (-tz) : tz;\n-\n-\t\tstrbuf_addf(&buf, \"%s %lu %c%04d\", email, timestamp, sign,\n-\t\t\t    zone);\n-\t\tupdate->committer = xstrdup(buf.buf);\n-\t\tstrbuf_release(&buf);\n+\t\tif (flags & REFLOG_EMAIL_IS_COMMITTER)\n+\t\t\tupdate->committer = xstrdup(email);\n+\t\telse {\n+\t\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\t\tchar sign = (tz < 0) ? '-' : '+';\n+\t\t\tint zone = (tz < 0) ? (-tz) : tz;\n+\n+\t\t\tstrbuf_addf(&buf, \"%s %lu %c%04d\", email, timestamp,\n+\t\t\t\t    sign, zone);\n+\t\t\tupdate->committer = xstrdup(buf.buf);\n+\t\t\tstrbuf_release(&buf);\n+\t\t}\n \t}\n \tif (msg)\n \t\tupdate->msg = xstrdup(msg);\ndiff --git a/refs.h b/refs.h\nindex 0172f48..eb918a0 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -309,6 +309,7 @@ int transaction_delete_sha1(struct ref_transaction *transaction,\n  * Flags >= 0x100 are reserved for internal use.\n  */\n #define REFLOG_TRUNCATE 0x01\n+#define REFLOG_EMAIL_IS_COMMITTER 0x02\n /*\n  * Append a reflog entry for refname. If the REFLOG_TRUNCATE flag is set\n  * this update will first truncate the reflog before writing the entry.\n-- \n2.0.1.508.g763ab16\n"},{"id":"246715","messageId":"1406307521-10339-3-git-send-email-sahlberg@google.com","threadId":"37213","inReplyTo":"1406307521-10339-1-git-send-email-sahlberg@google.com","subject":"[PATCH 2/5] refs.c: return error instead of dying when locking fails during transaction","fromName":"Ronnie Sahlberg","fromEmail":"sahlberg@google.com","sentAt":"2014-07-25T16:58:38Z","receivedAt":"2014-07-25T16:58:38Z","isPatch":true,"sender":{"key":"sahlberg@google.com","avatar":"https://avatars.githubusercontent.com/u/7320636?v=4"},"body":"Change lock_ref_sha1_basic to return an error instead of dying when\nwe fail to lock a file during a transaction.\n\nSigned-off-by: Ronnie Sahlberg <sahlberg@google.com>\n---\n refs.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/refs.c b/refs.c\nindex 6c55032..2ea85a8 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2214,7 +2214,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n \t\t\t */\n \t\t\tgoto retry;\n \t\telse\n-\t\t\tunable_to_lock_index_die(ref_file, errno);\n+\t\t\tgoto error_return;\n \t}\n \tif (bad_ref)\n \t\treturn lock;\n-- \n2.0.1.508.g763ab16\n"},{"id":"246717","messageId":"1406307521-10339-4-git-send-email-sahlberg@google.com","threadId":"37213","inReplyTo":"1406307521-10339-1-git-send-email-sahlberg@google.com","subject":"[PATCH 3/5] refs.c: use packed refs when deleting refs during a transaction","fromName":"Ronnie Sahlberg","fromEmail":"sahlberg@google.com","sentAt":"2014-07-25T16:58:39Z","receivedAt":"2014-07-25T16:58:39Z","isPatch":true,"sender":{"key":"sahlberg@google.com","avatar":"https://avatars.githubusercontent.com/u/7320636?v=4"},"body":"Make the deletion of refs during a transaction more atomic.\nStart by first copying all loose refs we will be deleting to the packed\nrefs file and then commit the packed refs file. Then re-lock the packed refs\nfile to stop anyone else from modifying these refs and keep it locked until\nwe are finished.\nSince all refs we are about to delete are now safely held in the packed refs\nfile we can proceed to immediately unlink any corresponding loose refs\nand still be fully rollback-able.\n\nThe exception is for refs that can not be resolved. Those refs are never\nadded to the packed refs and will just be un-rollback-ably deleted during\ncommit.\n\nBy deleting all the loose refs at the start of the transaction we make make\nit possible to both delete one ref and then re-create a different ref in\nthe same transaction even if the two refs would normally conflict.\n\nExample: rename m->m/m\n\nIn that example we want to delete the file 'm' so that we make room so\nthat we can create a directory with the same name in order to lock and\nwrite to the ref m/m and its lock-file m/m.lock.\n\nIf there is a failure during the commit phase we can rollback without losing\nany refs since we have so far only deleted loose refs that that are\nguaranteed to also have a corresponding entry in the packed refs file.\nOnce we have finished all updates for refs and their reflogs we can repack\nthe packed refs file and remove the to-be-deleted refs from the packed refs,\nat which point all the deleted refs will disappear in one atomic rename\noperation.\n\nThis also means that for an outside observer, deletion of multiple refs\nin a single transaction will look atomic instead of one ref being deleted\nat a time.\n\nIn order to do all this we need to change the semantics for the\nrepack_without_refs function so that we can lock the packed refs file,\ndo other stuff, and later be able to call repack_without_refs with the\nlock already taken.\nThis means we need some additional changes in remote.c to reflect the\nchanges to the repack_without_refs semantics.\n\nSigned-off-by: Ronnie Sahlberg <sahlberg@google.com>\n---\n builtin/remote.c |  13 +++--\n refs.c           | 151 +++++++++++++++++++++++++++++++++++++++++++------------\n 2 files changed, 128 insertions(+), 36 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex be8ebac..9a9cc92 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -756,6 +756,8 @@ static int remove_branches(struct string_list *branches)\n \tbranch_names = xmalloc(branches->nr * sizeof(*branch_names));\n \tfor (i = 0; i < branches->nr; i++)\n \t\tbranch_names[i] = branches->items[i].string;\n+\tif (lock_packed_refs(0))\n+\t\tresult |= unable_to_lock_error(git_path(\"packed-refs\"), errno);\n \tresult |= repack_without_refs(branch_names, branches->nr, NULL);\n \tfree(branch_names);\n \n@@ -1333,9 +1335,14 @@ static int prune_remote(const char *remote, int dry_run)\n \t\tdelete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));\n \t\tfor (i = 0; i < states.stale.nr; i++)\n \t\t\tdelete_refs[i] = states.stale.items[i].util;\n-\t\tif (!dry_run)\n-\t\t\tresult |= repack_without_refs(delete_refs,\n-\t\t\t\t\t\t      states.stale.nr, NULL);\n+\t\tif (!dry_run) {\n+\t\t\tif (lock_packed_refs(0))\n+\t\t\t\tresult |= unable_to_lock_error(\n+\t\t\t\t\tgit_path(\"packed-refs\"), errno);\n+\t\t\telse\n+\t\t\t\tresult |= repack_without_refs(delete_refs,\n+\t\t\t\t\t\t\tstates.stale.nr, NULL);\n+\t\t}\n \t\tfree(delete_refs);\n \t}\n \ndiff --git a/refs.c b/refs.c\nindex 2ea85a8..0d800f1 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1330,7 +1330,7 @@ static struct ref_entry *get_packed_ref(const char *refname)\n \n /*\n  * A loose ref file doesn't exist; check for a packed ref.  The\n- * options are forwarded from resolve_safe_unsafe().\n+ * options are forwarded from resolve_ref_unsafe().\n  */\n static const char *handle_missing_loose_ref(const char *refname,\n \t\t\t\t\t    unsigned char *sha1,\n@@ -1387,7 +1387,6 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int fla\n \t\t}\n \n \t\tgit_snpath(path, sizeof(path), \"%s\", refname);\n-\n \t\t/*\n \t\t * We might have to loop back here to avoid a race\n \t\t * condition: first we lstat() the file, then we try\n@@ -2532,6 +2531,9 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data)\n \treturn 0;\n }\n \n+/*\n+ * Must be called with packed refs already locked (and sorted)\n+ */\n int repack_without_refs(const char **refnames, int n, struct strbuf *err)\n {\n \tstruct ref_dir *packed;\n@@ -2544,19 +2546,12 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)\n \t\tif (get_packed_ref(refnames[i]))\n \t\t\tbreak;\n \n-\t/* Avoid locking if we have nothing to do */\n-\tif (i == n)\n+\t/* Avoid processing if we have nothing to do */\n+\tif (i == n) {\n+\t\trollback_packed_refs();\n \t\treturn 0; /* no refname exists in packed refs */\n-\n-\tif (lock_packed_refs(0)) {\n-\t\tif (err) {\n-\t\t\tunable_to_lock_message(git_path(\"packed-refs\"), errno,\n-\t\t\t\t\t       err);\n-\t\t\treturn -1;\n-\t\t}\n-\t\tunable_to_lock_error(git_path(\"packed-refs\"), errno);\n-\t\treturn error(\"cannot delete '%s' from packed refs\", refnames[i]);\n \t}\n+\n \tpacked = get_packed_refs(&ref_cache);\n \n \t/* Remove refnames from the cache */\n@@ -3669,10 +3664,12 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,\n int transaction_commit(struct ref_transaction *transaction,\n \t\t       struct strbuf *err)\n {\n-\tint ret = 0, delnum = 0, i, df_conflict = 0;\n+\tint ret = 0, delnum = 0, i, df_conflict = 0, need_repack = 0;\n \tconst char **delnames;\n \tint n = transaction->nr;\n+\tstruct packed_ref_cache *packed_ref_cache;\n \tstruct ref_update **updates = transaction->updates;\n+\tstruct ref_dir *packed;\n \n \tif (transaction->state != REF_TRANSACTION_OPEN)\n \t\tdie(\"BUG: commit called for transaction that is not open\");\n@@ -3692,12 +3689,65 @@ int transaction_commit(struct ref_transaction *transaction,\n \t\tgoto cleanup;\n \t}\n \n-\t/* Acquire all ref locks while verifying old values */\n+\t/* Lock packed refs during commit */\n+\tif (lock_packed_refs(0)) {\n+\t\tif (err)\n+\t\t\tunable_to_lock_message(git_path(\"packed-refs\"),\n+\t\t\t\t\t       errno, err);\n+\t\tret = -1;\n+\t\tgoto cleanup;\n+\t}\n+\n+\t/* any loose refs are to be deleted are first copied to packed refs */\n \tfor (i = 0; i < n; i++) {\n \t\tstruct ref_update *update = updates[i];\n+\t\tunsigned char sha1[20];\n \n \t\tif (update->update_type != UPDATE_SHA1)\n \t\t\tcontinue;\n+\t\tif (!is_null_sha1(update->new_sha1))\n+\t\t\tcontinue;\n+\t\tif (get_packed_ref(update->refname))\n+\t\t\tcontinue;\n+\t\tif (!resolve_ref_unsafe(update->refname, sha1, 1, NULL))\n+\t\t\tcontinue;\n+\n+\t\tadd_packed_ref(update->refname, sha1);\n+\t\tneed_repack = 1;\n+\t}\n+\tif (need_repack) {\n+\t\tpacked = get_packed_refs(&ref_cache);;\n+\t\tsort_ref_dir(packed);\n+\t\tif (commit_packed_refs()){\n+\t\t\tstrbuf_addf(err, \"unable to overwrite old ref-pack \"\n+\t\t\t\t    \"file\");\n+\t\t\tret = -1;\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t\t/* lock the packed refs again so no one can change it */\n+\t\tif (lock_packed_refs(0)) {\n+\t\t\tif (err)\n+\t\t\t\tunable_to_lock_message(git_path(\"packed-refs\"),\n+\t\t\t\t\t\t       errno, err);\n+\t\t\tret = -1;\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * At this stage any refs that are to be deleted have been moved to the\n+\t * packed refs file anf the packed refs file is deleted. We can now\n+\t * safely delete these loose refs.\n+\t */\n+\n+\t/* Unlink any loose refs scheduled for deletion */\n+\tfor (i = 0; i < n; i++) {\n+\t\tstruct ref_update *update = updates[i];\n+\n+\t\tif (update->update_type != UPDATE_SHA1)\n+\t\t\tcontinue;\n+\t\tif (!is_null_sha1(update->new_sha1))\n+\t\t\tcontinue;\n \t\tupdate->lock = lock_ref_sha1_basic(update->refname,\n \t\t\t\t\t\t   (update->have_old ?\n \t\t\t\t\t\t    update->old_sha1 :\n@@ -3714,8 +3764,47 @@ int transaction_commit(struct ref_transaction *transaction,\n \t\t\tret = -1;\n \t\t\tgoto cleanup;\n \t\t}\n+\t\tif (delete_ref_loose(update->lock, update->type, err)) {\n+\t\t\tret = -1;\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t\ttry_remove_empty_parents((char *)update->refname);\n+\t\tif (!(update->flags & REF_ISPRUNING))\n+\t\t\t  delnames[delnum++] = xstrdup(update->lock->ref_name);\n+\t\tunlock_ref(update->lock);\n+\t\tupdate->lock = NULL;\n \t}\n \n+\t/* Acquire all ref locks for updates while verifying old values */\n+\tfor (i = 0; i < n; i++) {\n+\t\tstruct ref_update *update = updates[i];\n+\n+\t\tif (update->update_type != UPDATE_SHA1)\n+\t\t\tcontinue;\n+\t\tif (is_null_sha1(update->new_sha1))\n+\t\t\tcontinue;\n+\t\tupdate->lock = lock_ref_sha1_basic(update->refname,\n+\t\t\t\t\t\t   (update->have_old ?\n+\t\t\t\t\t\t    update->old_sha1 :\n+\t\t\t\t\t\t    NULL),\n+\t\t\t\t\t\t   update->flags,\n+\t\t\t\t\t\t   &update->type,\n+\t\t\t\t\t\t   delnames, delnum);\n+\t\tif (!update->lock) {\n+\t\t\tif (errno == ENOTDIR)\n+\t\t\t\tdf_conflict = 1;\n+\t\t\tif (err)\n+\t\t\t\tstrbuf_addf(err, \"Cannot lock the ref '%s'.\",\n+\t\t\t\t\t    update->refname);\n+\t\t\tret = -1;\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\t/* delete reflog for all deleted refs */\n+\tfor (i = 0; i < delnum; i++)\n+\t\tunlink_or_warn(git_path(\"logs/%s\", delnames[i]));\n+\n \t/* Lock all reflog files */\n \tfor (i = 0; i < n; i++) {\n \t\tstruct ref_update *update = updates[i];\n@@ -3727,6 +3816,16 @@ int transaction_commit(struct ref_transaction *transaction,\n \t\t\tupdate->reflog_lock = update->orig_update->reflog_lock;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (log_all_ref_updates && !reflog_exists(update->refname) &&\n+\t\t    create_reflog(update->refname)) {\n+\t\t\tret = -1;\n+\t\t\tif (err)\n+\t\t\t\tstrbuf_addf(err, \"Failed to setup reflog for \"\n+\t\t\t\t\t    \"%s\", update->refname);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t\tif (!reflog_exists(update->refname))\n+\t\t\tcontinue;\n \t\tupdate->reflog_fd = hold_lock_file_for_append(\n \t\t\t\t\tupdate->reflog_lock,\n \t\t\t\t\tgit_path(\"logs/%s\", update->refname),\n@@ -3742,7 +3841,7 @@ int transaction_commit(struct ref_transaction *transaction,\n \t\t}\n \t}\n \n-\t/* Perform ref updates first so live commits remain referenced */\n+\t/* Perform ref updates */\n \tfor (i = 0; i < n; i++) {\n \t\tstruct ref_update *update = updates[i];\n \n@@ -3763,21 +3862,6 @@ int transaction_commit(struct ref_transaction *transaction,\n \t\t}\n \t}\n \n-\t/* Perform deletes now that updates are safely completed */\n-\tfor (i = 0; i < n; i++) {\n-\t\tstruct ref_update *update = updates[i];\n-\n-\t\tif (update->update_type != UPDATE_SHA1)\n-\t\t\tcontinue;\n-\t\tif (update->lock) {\n-\t\t\tif (delete_ref_loose(update->lock, update->type, err))\n-\t\t\t\tret = -1;\n-\n-\t\t\tif (!(update->flags & REF_ISPRUNING))\n-\t\t\t\tdelnames[delnum++] = update->lock->ref_name;\n-\t\t}\n-\t}\n-\n \t/*\n \t * Update all reflog files\n \t * We have already committed all ref updates and deletes.\n@@ -3830,11 +3914,12 @@ int transaction_commit(struct ref_transaction *transaction,\n \n \tif (repack_without_refs(delnames, delnum, err))\n \t\tret = -1;\n-\tfor (i = 0; i < delnum; i++)\n-\t\tunlink_or_warn(git_path(\"logs/%s\", delnames[i]));\n \tclear_loose_ref_cache(&ref_cache);\n \n cleanup:\n+\tpacked_ref_cache = get_packed_ref_cache(&ref_cache);\n+\tif (packed_ref_cache->lock)\n+\t\trollback_packed_refs();\n \ttransaction->state = ret ? REF_TRANSACTION_ERROR\n \t\t: REF_TRANSACTION_CLOSED;\n \n-- \n2.0.1.508.g763ab16\n"},{"id":"246716","messageId":"1406307521-10339-5-git-send-email-sahlberg@google.com","threadId":"37213","inReplyTo":"1406307521-10339-1-git-send-email-sahlberg@google.com","subject":"[PATCH 4/5] refs.c: update rename_ref to use a transaction","fromName":"Ronnie Sahlberg","fromEmail":"sahlberg@google.com","sentAt":"2014-07-25T16:58:40Z","receivedAt":"2014-07-25T16:58:40Z","isPatch":true,"sender":{"key":"sahlberg@google.com","avatar":"https://avatars.githubusercontent.com/u/7320636?v=4"},"body":"Change refs.c to use a single transaction to copy/rename both the refs and\nits reflog. Since we are no longer using rename() to move the reflog file\nwe no longer need to disallow rename_ref for refs with a symlink for its\nreflog so we can remove that test from the testsuite.\n\nChange the function to return 1 on failure instead of either -1 or 1.\n\nThese changes make the rename_ref operation atomic. This also eliminates the\nneed to use rename() to shift the reflog around via a temporary filename.\nAs an extension to this, since we no longer use rename() on the reflog file,\nwe can now safely perform renames even if the reflog is a symbolic link\nand thus can remove the check and fail for that condition.\n\nSigned-off-by: Ronnie Sahlberg <sahlberg@google.com>\n---\n refs.c            | 192 ++++++++++++++++++------------------------------------\n t/t3200-branch.sh |   7 --\n 2 files changed, 65 insertions(+), 134 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 0d800f1..a5053bf 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2616,82 +2616,43 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)\n \treturn 0;\n }\n \n-/*\n- * People using contrib's git-new-workdir have .git/logs/refs ->\n- * /some/other/path/.git/logs/refs, and that may live on another device.\n- *\n- * IOW, to avoid cross device rename errors, the temporary renamed log must\n- * live into logs/refs.\n- */\n-#define TMP_RENAMED_LOG  \"logs/refs/.tmp-renamed-log\"\n+struct rename_reflog_cb {\n+\tstruct ref_transaction *transaction;\n+\tconst char *refname;\n+\tstruct strbuf *err;\n+};\n \n-static int rename_tmp_log(const char *newrefname)\n+static int rename_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n+\t\t\t     const char *email, unsigned long timestamp, int tz,\n+\t\t\t     const char *message, void *cb_data)\n {\n-\tint attempts_remaining = 4;\n-\n- retry:\n-\tswitch (safe_create_leading_directories(git_path(\"logs/%s\", newrefname))) {\n-\tcase SCLD_OK:\n-\t\tbreak; /* success */\n-\tcase SCLD_VANISHED:\n-\t\tif (--attempts_remaining > 0)\n-\t\t\tgoto retry;\n-\t\t/* fall through */\n-\tdefault:\n-\t\terror(\"unable to create directory for %s\", newrefname);\n-\t\treturn -1;\n-\t}\n+\tstruct rename_reflog_cb *cb = cb_data;\n \n-\tif (rename(git_path(TMP_RENAMED_LOG), git_path(\"logs/%s\", newrefname))) {\n-\t\tif ((errno==EISDIR || errno==ENOTDIR) && --attempts_remaining > 0) {\n-\t\t\t/*\n-\t\t\t * rename(a, b) when b is an existing\n-\t\t\t * directory ought to result in ISDIR, but\n-\t\t\t * Solaris 5.8 gives ENOTDIR.  Sheesh.\n-\t\t\t */\n-\t\t\tif (remove_empty_directories(git_path(\"logs/%s\", newrefname))) {\n-\t\t\t\terror(\"Directory not empty: logs/%s\", newrefname);\n-\t\t\t\treturn -1;\n-\t\t\t}\n-\t\t\tgoto retry;\n-\t\t} else if (errno == ENOENT && --attempts_remaining > 0) {\n-\t\t\t/*\n-\t\t\t * Maybe another process just deleted one of\n-\t\t\t * the directories in the path to newrefname.\n-\t\t\t * Try again from the beginning.\n-\t\t\t */\n-\t\t\tgoto retry;\n-\t\t} else {\n-\t\t\terror(\"unable to move logfile \"TMP_RENAMED_LOG\" to logs/%s: %s\",\n-\t\t\t\tnewrefname, strerror(errno));\n-\t\t\treturn -1;\n-\t\t}\n-\t}\n-\treturn 0;\n+\treturn transaction_update_reflog(cb->transaction, cb->refname,\n+\t\t\t\t\t nsha1, osha1, email, timestamp, tz,\n+\t\t\t\t\t message, 0, cb->err);\n }\n \n-static int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1,\n-\t\t\t  const char *logmsg);\n-\n int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)\n {\n-\tunsigned char sha1[20], orig_sha1[20];\n-\tint flag = 0, logmoved = 0;\n-\tstruct ref_lock *lock;\n-\tstruct stat loginfo;\n-\tint log = !lstat(git_path(\"logs/%s\", oldrefname), &loginfo);\n+\tunsigned char sha1[20];\n+\tint flag = 0, log;\n+\tstruct ref_transaction *transaction = NULL;\n+\tstruct strbuf err = STRBUF_INIT;\n \tconst char *symref = NULL;\n+\tstruct rename_reflog_cb cb;\n \n-\tif (log && S_ISLNK(loginfo.st_mode))\n-\t\treturn error(\"reflog for %s is a symlink\", oldrefname);\n-\n-\tsymref = resolve_ref_unsafe(oldrefname, orig_sha1,\n+\tsymref = resolve_ref_unsafe(oldrefname, sha1,\n \t\t\t\t    RESOLVE_REF_READING, &flag);\n-\tif (flag & REF_ISSYMREF)\n-\t\treturn error(\"refname %s is a symbolic ref, renaming it is not supported\",\n+\tif (flag & REF_ISSYMREF) {\n+\t\terror(\"refname %s is a symbolic ref, renaming it is not supported\",\n \t\t\toldrefname);\n-\tif (!symref)\n-\t\treturn error(\"refname %s not found\", oldrefname);\n+\t\treturn 1;\n+\t}\n+\tif (!symref) {\n+\t\terror(\"refname %s not found\", oldrefname);\n+\t\treturn 1;\n+\t}\n \n \tif (!is_refname_available(newrefname, get_packed_refs(&ref_cache),\n \t\t\t\t  &oldrefname, 1))\n@@ -2701,70 +2662,47 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms\n \t\t\t\t  &oldrefname, 1))\n \t\treturn 1;\n \n-\tif (log && rename(git_path(\"logs/%s\", oldrefname), git_path(TMP_RENAMED_LOG)))\n-\t\treturn error(\"unable to move logfile logs/%s to \"TMP_RENAMED_LOG\": %s\",\n-\t\t\toldrefname, strerror(errno));\n-\n-\tif (delete_ref(oldrefname, orig_sha1, REF_NODEREF)) {\n-\t\terror(\"unable to delete old %s\", oldrefname);\n-\t\tgoto rollback;\n-\t}\n-\n-\tif (!read_ref_full(newrefname, sha1, RESOLVE_REF_READING, NULL) &&\n-\t    delete_ref(newrefname, sha1, REF_NODEREF)) {\n-\t\tif (errno==EISDIR) {\n-\t\t\tif (remove_empty_directories(git_path(\"%s\", newrefname))) {\n-\t\t\t\terror(\"Directory not empty: %s\", newrefname);\n-\t\t\t\tgoto rollback;\n-\t\t\t}\n-\t\t} else {\n-\t\t\terror(\"unable to delete existing %s\", newrefname);\n-\t\t\tgoto rollback;\n-\t\t}\n-\t}\n-\n-\tif (log && rename_tmp_log(newrefname))\n-\t\tgoto rollback;\n-\n-\tlogmoved = log;\n-\n-\tlock = lock_ref_sha1_basic(newrefname, NULL, 0, NULL, NULL, 0);\n-\tif (!lock) {\n-\t\terror(\"unable to lock %s for update\", newrefname);\n-\t\tgoto rollback;\n-\t}\n-\tlock->force_write = 1;\n-\thashcpy(lock->old_sha1, orig_sha1);\n-\tif (write_ref_sha1(lock, orig_sha1, logmsg)) {\n-\t\terror(\"unable to write current sha1 into %s\", newrefname);\n-\t\tgoto rollback;\n-\t}\n-\n+\tlog = reflog_exists(oldrefname);\n+\ttransaction = transaction_begin(&err);\n+\tif (!transaction)\n+\t\tgoto fail;\n+\n+\tif (strcmp(oldrefname, newrefname)) {\n+\t\tif (log && transaction_update_reflog(transaction, newrefname,\n+\t\t\t\t\t\t     sha1, sha1,\n+\t\t\t\t\t\t     git_committer_info(0),\n+\t\t\t\t\t\t     0, 0, NULL,\n+\t\t\t\t\t\t     REFLOG_TRUNCATE, &err))\n+\t\t\tgoto fail;\n+\t\tcb.transaction = transaction;\n+\t\tcb.refname = newrefname;\n+\t\tcb.err = &err;\n+\t\tif (log && for_each_reflog_ent(oldrefname, rename_reflog_ent,\n+\t\t\t\t\t       &cb))\n+\t\t\tgoto fail;\n+\n+\t\tif (transaction_delete_sha1(transaction, oldrefname, sha1,\n+\t\t\t\t\t    REF_NODEREF,\n+\t\t\t\t\t    1, NULL, &err))\n+\t\t\tgoto fail;\n+\t}\n+\tif (transaction_update_sha1(transaction, newrefname, sha1,\n+\t\t\t\t    NULL, 0, 0, NULL, &err))\n+\t\tgoto fail;\n+\tif (log && transaction_update_reflog(transaction, newrefname, sha1,\n+\t\t\t\t\t     sha1, git_committer_info(0),\n+\t\t\t\t\t     0, 0, logmsg,\n+\t\t\t\t\t     REFLOG_EMAIL_IS_COMMITTER, &err))\n+\t\tgoto fail;\n+\tif (transaction_commit(transaction, &err))\n+\t\tgoto fail;\n+\ttransaction_free(transaction);\n \treturn 0;\n \n- rollback:\n-\tlock = lock_ref_sha1_basic(oldrefname, NULL, 0, NULL, NULL, 0);\n-\tif (!lock) {\n-\t\terror(\"unable to lock %s for rollback\", oldrefname);\n-\t\tgoto rollbacklog;\n-\t}\n-\n-\tlock->force_write = 1;\n-\tflag = log_all_ref_updates;\n-\tlog_all_ref_updates = 0;\n-\tif (write_ref_sha1(lock, orig_sha1, NULL))\n-\t\terror(\"unable to write current sha1 into %s\", oldrefname);\n-\tlog_all_ref_updates = flag;\n-\n- rollbacklog:\n-\tif (logmoved && rename(git_path(\"logs/%s\", newrefname), git_path(\"logs/%s\", oldrefname)))\n-\t\terror(\"unable to restore logfile %s from %s: %s\",\n-\t\t\toldrefname, newrefname, strerror(errno));\n-\tif (!logmoved && log &&\n-\t    rename(git_path(TMP_RENAMED_LOG), git_path(\"logs/%s\", oldrefname)))\n-\t\terror(\"unable to restore logfile %s from \"TMP_RENAMED_LOG\": %s\",\n-\t\t\toldrefname, strerror(errno));\n-\n+ fail:\n+\terror(\"rename_ref failed: %s\", err.buf);\n+\tstrbuf_release(&err);\n+\ttransaction_free(transaction);\n \treturn 1;\n }\n \ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex ac31b71..64f5bf2 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -293,13 +293,6 @@ test_expect_success 'renaming a symref is not allowed' '\n \ttest_path_is_missing .git/refs/heads/master3\n '\n \n-test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '\n-\tgit branch -l u &&\n-\tmv .git/logs/refs/heads/u real-u &&\n-\tln -s real-u .git/logs/refs/heads/u &&\n-\ttest_must_fail git branch -m u v\n-'\n-\n test_expect_success 'test tracking setup via --track' '\n \tgit config remote.local.url . &&\n \tgit config remote.local.fetch refs/heads/*:refs/remotes/local/* &&\n-- \n2.0.1.508.g763ab16\n"},{"id":"246714","messageId":"1406307521-10339-6-git-send-email-sahlberg@google.com","threadId":"37213","inReplyTo":"1406307521-10339-1-git-send-email-sahlberg@google.com","subject":"[PATCH 5/5] refs.c: rollback the lockfile before we die() in repack_without_refs","fromName":"Ronnie Sahlberg","fromEmail":"sahlberg@google.com","sentAt":"2014-07-25T16:58:41Z","receivedAt":"2014-07-25T16:58:41Z","isPatch":true,"sender":{"key":"sahlberg@google.com","avatar":"https://avatars.githubusercontent.com/u/7320636?v=4"},"body":"Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>\n---\n refs.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/refs.c b/refs.c\nindex a5053bf..619725a 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2570,8 +2570,10 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)\n \t/* Remove any other accumulated cruft */\n \tdo_for_each_entry_in_dir(packed, 0, curate_packed_ref_fn, &refs_to_delete);\n \tfor_each_string_list_item(ref_to_delete, &refs_to_delete) {\n-\t\tif (remove_entry(packed, ref_to_delete->string) == -1)\n+\t\tif (remove_entry(packed, ref_to_delete->string) == -1) {\n+\t\t\trollback_packed_refs();\n \t\t\tdie(\"internal error\");\n+\t\t}\n \t}\n \n \t/* Write what remains */\n-- \n2.0.1.508.g763ab16\n"},{"id":"246743","messageId":"20140725193728.GG12427@google.com","threadId":"37213","inReplyTo":"1406307521-10339-2-git-send-email-sahlberg@google.com","subject":"Re: [PATCH 1/5] refs.c: allow passing raw git_committer_info as email to _update_reflog","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2014-07-25T19:37:28Z","receivedAt":"2014-07-25T19:37:28Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ronnie Sahlberg wrote:\n\n> Add a new flag REFLOG_EMAIL_IS_COMMITTER to _update_reflog to tell it\n> that what we pass in as email is already the fully baked committer string\n> we can use as-is.\n\nWith and without the new flag, the 'email' argument has two different\nmeanings:\n\n * with the new flag, it should be an ident string, like\n   'Jonathan Nieder <jrnieder@gmail.com> 1406251347 -0700'\n\n * without it, it should be the name-part of an ident string,\n   like 'Jonathan Nieder <jrnieder@gmail.com>\n\nIn neither case is it an email address.  This seems unnecessarily\nconfusing.\n\nIs the caller responsible for checking the argument for validity?\nDo callers do so?  Is this performance-critical or could the\ntransaction_update_reflog function do a sanity-check?\n\n[...]\n>  /*\n>   * Append a reflog entry for refname. If the REFLOG_TRUNCATE flag is set\n>   * this update will first truncate the reflog before writing the entry.\n>   * If msg is NULL no update will be written to the log.\n>   */\n>  int transaction_update_reflog(struct ref_transaction *transaction,\n>                                const char *refname,\n>                                const unsigned char *new_sha1,\n>                                const unsigned char *old_sha1,\n>                                const char *email,\n>                                unsigned long timestamp, int tz,\n>                                const char *msg, int flags,\n>                                struct strbuf *err);\n\nThis is a lot of parameters, some optional, not all documented.  Would\nit make sense to pack some into a struct?\n\nThanks and hope that helps,\nJonathan\n"},{"id":"246745","messageId":"20140725194023.GH12427@google.com","threadId":"37213","inReplyTo":"1406307521-10339-3-git-send-email-sahlberg@google.com","subject":"Re: [PATCH 2/5] refs.c: return error instead of dying when locking fails during transaction","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2014-07-25T19:40:23Z","receivedAt":"2014-07-25T19:40:23Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ronnie Sahlberg wrote:\n\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -2214,7 +2214,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n>  \t\t\t */\n>  \t\t\tgoto retry;\n>  \t\telse\n> -\t\t\tunable_to_lock_index_die(ref_file, errno);\n> +\t\t\tgoto error_return;\n\nShould probably save last_errno so error_return can pass that\ninformation back.\n\nCan the caller recover from this error?  Does it have enough information\nto produce the same helpful message as unable_to_lock_index_die?\n\nIf this could be done without regressing behavior (e.g., by passing\nback error information as a message instead of through errno) then I\nthink it would make sense.\n\nJonathan\n"},{"id":"246746","messageId":"20140725195843.GI12427@google.com","threadId":"37213","inReplyTo":"1406307521-10339-4-git-send-email-sahlberg@google.com","subject":"Re: [PATCH 3/5] refs.c: use packed refs when deleting refs during a transaction","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2014-07-25T19:58:43Z","receivedAt":"2014-07-25T19:58:43Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ronnie Sahlberg wrote:\n\n> Make the deletion of refs during a transaction more atomic.\n> Start by first copying all loose refs we will be deleting to the packed\n> refs file and then commit the packed refs file. Then re-lock the packed refs\n> file to stop anyone else from modifying these refs and keep it locked until\n> we are finished.\n[...]\n> By deleting all the loose refs at the start of the transaction we make make\n> it possible to both delete one ref and then re-create a different ref in\n> the same transaction even if the two refs would normally conflict.\n>\n> Example: rename m->m/m\n\nMakes a lot of sense.\n\nThis can potentially slow down a single-ref deletion in a repository with\na huge amount of refs (e.g., a Gerrit server with lots of\nrefs/changes/* refs), right?  But the cost is not more than a factor\nof 2 worse than if the ref had been packed (since you have to\nrepack_without_refs anyway) so I think this is acceptable.\n\n[...]\n> The exception is for refs that can not be resolved. Those refs are never\n> added to the packed refs and will just be un-rollback-ably deleted during\n> commit.\n\nThis also seems reasonable --- there's no need to be able to roll back\ninto an invalid state. :)\n\n[...]\n> --- a/builtin/remote.c\n> +++ b/builtin/remote.c\n> @@ -756,6 +756,8 @@ static int remove_branches(struct string_list *branches)\n>  \tbranch_names = xmalloc(branches->nr * sizeof(*branch_names));\n>  \tfor (i = 0; i < branches->nr; i++)\n>  \t\tbranch_names[i] = branches->items[i].string;\n> +\tif (lock_packed_refs(0))\n> +\t\tresult |= unable_to_lock_error(git_path(\"packed-refs\"), errno);\n>  \tresult |= repack_without_refs(branch_names, branches->nr, NULL);\n\nWhat should happen if lock_packed_refs fails?  Since\nrepack_without_refs is now documented to require a locked packed-refs\nfile, shouldn't the repack_without_refs call be guarded, like it is\nbelow?\n\n[...]\n> @@ -1333,9 +1335,14 @@ static int prune_remote(const char *remote, int dry_run)\n>  \t\tdelete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));\n>  \t\tfor (i = 0; i < states.stale.nr; i++)\n>  \t\t\tdelete_refs[i] = states.stale.items[i].util;\n> -\t\tif (!dry_run)\n> -\t\t\tresult |= repack_without_refs(delete_refs,\n> -\t\t\t\t\t\t      states.stale.nr, NULL);\n> +\t\tif (!dry_run) {\n> +\t\t\tif (lock_packed_refs(0))\n> +\t\t\t\tresult |= unable_to_lock_error(\n> +\t\t\t\t\tgit_path(\"packed-refs\"), errno);\n> +\t\t\telse\n> +\t\t\t\tresult |= repack_without_refs(delete_refs,\n> +\t\t\t\t\t\t\tstates.stale.nr, NULL);\n[...]\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -1330,7 +1330,7 @@ static struct ref_entry *get_packed_ref(const char *refname)\n>  \n>  /*\n>   * A loose ref file doesn't exist; check for a packed ref.  The\n> - * options are forwarded from resolve_safe_unsafe().\n> + * options are forwarded from resolve_ref_unsafe().\n\nUnrelated changes snuck in?  (A good change, but it presumably belongs\nas a separate patch.)\n\n[...]\n> @@ -1387,7 +1387,6 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int fla\n>  \t\t}\n>  \n>  \t\tgit_snpath(path, sizeof(path), \"%s\", refname);\n> -\n>  \t\t/*\n\nWhy?\n\n[...]\n> @@ -2532,6 +2531,9 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data)\n>  \treturn 0;\n>  }\n>  \n> +/*\n> + * Must be called with packed refs already locked (and sorted)\n> + */\n>  int repack_without_refs(const char **refnames, int n, struct strbuf *err)\n\nAren't packed refs always sorted?  If it needs mentioning, that seems\nmore like an implementation comment.\n\nThe 'packed refs must be locked' kind of documentation belongs in\nrefs.h since this is part of the API.  Usually when there are API\nchanges like this we like to change the function name or signature to\nmake it easy to catch callers that were introduced without noticing\nthe change --- would that be easy to do here?\n\nE.g. introducing a new repack_without_refs_locked (name is just a\nplaceholder, I'm bad at names) and keeping repack_without_refs with\nthe current semantics as a wrapper around that.\n\n[...]\n> @@ -2544,19 +2546,12 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)\n>  \t\tif (get_packed_ref(refnames[i]))\n>  \t\t\tbreak;\n>  \n> -\t/* Avoid locking if we have nothing to do */\n> +\t/* Avoid processing if we have nothing to do */\n\nThis implies a small speed regression but I don't think anyone would\nmind.\n\n[...]\n> @@ -3692,12 +3689,65 @@ int transaction_commit(struct ref_transaction *transaction,\n>  \t\tgoto cleanup;\n>  \t}\n>  \n> -\t/* Acquire all ref locks while verifying old values */\n> +\t/* Lock packed refs during commit */\n> +\tif (lock_packed_refs(0)) {\n\nI stopped reviewing here but assume the rest is okay. :)\n\nThanks,\nJonathan\n"},{"id":"246747","messageId":"20140725200009.GJ12427@google.com","threadId":"37213","inReplyTo":"1406307521-10339-5-git-send-email-sahlberg@google.com","subject":"Re: [PATCH 4/5] refs.c: update rename_ref to use a transaction","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2014-07-25T20:00:09Z","receivedAt":"2014-07-25T20:00:09Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ronnie Sahlberg wrote:\n\n> Change refs.c to use a single transaction to copy/rename both the refs and\n> its reflog.\n\nYay!\n\n>             Since we are no longer using rename() to move the reflog file\n> we no longer need to disallow rename_ref for refs with a symlink for its\n> reflog so we can remove that test from the testsuite.\n\nIt's generally better to update the testsuite with the new expected\nbehavior instead. :)\n"},{"id":"246809","messageId":"CAL=YDWmSKBnjXiBUJjOb-+M7R8d==mMsN11DjDTDxU2+WAh+vQ@mail.gmail.com","threadId":"37213","inReplyTo":"20140725193728.GG12427@google.com","subject":"Re: [PATCH 1/5] refs.c: allow passing raw git_committer_info as email to _update_reflog","fromName":"Ronnie Sahlberg","fromEmail":"sahlberg@google.com","sentAt":"2014-07-28T18:01:17Z","receivedAt":"2014-07-28T18:01:17Z","isPatch":true,"sender":{"key":"sahlberg@google.com","avatar":"https://avatars.githubusercontent.com/u/7320636?v=4"},"body":"On Fri, Jul 25, 2014 at 12:37 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Ronnie Sahlberg wrote:\n>\n>> Add a new flag REFLOG_EMAIL_IS_COMMITTER to _update_reflog to tell it\n>> that what we pass in as email is already the fully baked committer string\n>> we can use as-is.\n>\n> With and without the new flag, the 'email' argument has two different\n> meanings:\n>\n>  * with the new flag, it should be an ident string, like\n>    'Jonathan Nieder <jrnieder@gmail.com> 1406251347 -0700'\n>\n>  * without it, it should be the name-part of an ident string,\n>    like 'Jonathan Nieder <jrnieder@gmail.com>\n>\n> In neither case is it an email address.  This seems unnecessarily\n> confusing.\n\nTrue.\n\nI have changed it to to be a field named 'id' instead of 'email'.\nI also added changes to update other places in the code to change the\nname for this to 'id' too.\n\nIt is confusing. I too were caught by this a while back when just\nbased on the name for the callback iterators\nI assumed what was passed there was an email address while it was not.\nI didn't fix that then but I fixed it now.\n\n\nThanks!\n\n\n>\n> Is the caller responsible for checking the argument for validity?\n> Do callers do so?  Is this performance-critical or could the\n> transaction_update_reflog function do a sanity-check?\n\nI have added basic sanity checks, such as required strings are non-NULL.\n\n>\n> [...]\n>>  /*\n>>   * Append a reflog entry for refname. If the REFLOG_TRUNCATE flag is set\n>>   * this update will first truncate the reflog before writing the entry.\n>>   * If msg is NULL no update will be written to the log.\n>>   */\n>>  int transaction_update_reflog(struct ref_transaction *transaction,\n>>                                const char *refname,\n>>                                const unsigned char *new_sha1,\n>>                                const unsigned char *old_sha1,\n>>                                const char *email,\n>>                                unsigned long timestamp, int tz,\n>>                                const char *msg, int flags,\n>>                                struct strbuf *err);\n>\n> This is a lot of parameters, some optional, not all documented.  Would\n> it make sense to pack some into a struct?\n\nI changed email,timestamp,tz into a struct\n/*\n * Committer data provided to reflog updates.\n * If flags contain REFLOG_COMMITTER_DATA_IS_VALID then\n * then the structure contains a prebaked committer string\n * just like git_committer_info() would return.\n *\n * If flags does not contain REFLOG_COMMITTER_DATA_IS_VALID\n * then the committer info string will be generated using the passed\n * email, timestamp and tz fields.\n * This is useful for example from reflog iterators where you are passed\n * these fields individually and not as a prebaked git_committer_info()\n * string.\n */\nstruct reflog_committer_info {\nconst char *committer_info;\n\nconst char *id;\nunsigned long timestamp;\nint tz;\n};\n\n>\n> Thanks and hope that helps,\n> Jonathan\n"},{"id":"246826","messageId":"CAL=YDWmCGMKgmc6NOhHuf-1QXFvnF25yT-WgxJBntu+DGAbBmg@mail.gmail.com","threadId":"37213","inReplyTo":"20140725194023.GH12427@google.com","subject":"Re: [PATCH 2/5] refs.c: return error instead of dying when locking fails during transaction","fromName":"Ronnie Sahlberg","fromEmail":"sahlberg@google.com","sentAt":"2014-07-28T19:01:34Z","receivedAt":"2014-07-28T19:01:34Z","isPatch":true,"sender":{"key":"sahlberg@google.com","avatar":"https://avatars.githubusercontent.com/u/7320636?v=4"},"body":"On Fri, Jul 25, 2014 at 12:40 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Ronnie Sahlberg wrote:\n>\n>> --- a/refs.c\n>> +++ b/refs.c\n>> @@ -2214,7 +2214,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n>>                        */\n>>                       goto retry;\n>>               else\n>> -                     unable_to_lock_index_die(ref_file, errno);\n>> +                     goto error_return;\n>\n> Should probably save last_errno so error_return can pass that\n> information back.\n\nDone. Thanks.\n\n>\n> Can the caller recover from this error?  Does it have enough information\n> to produce the same helpful message as unable_to_lock_index_die?\n>\n> If this could be done without regressing behavior (e.g., by passing\n> back error information as a message instead of through errno) then I\n> think it would make sense.\n\nThe callers should all be able to cope with this returning error (and\nnow logging error() since this function is only called from within\ntransaction_commit() and it knows how to deal with these errors.\n\n\n>\n> Jonathan\n"},{"id":"246861","messageId":"CAPig+cRWanM7fUR-fJ7r-zTrTj5jbkKik0=12WOiNGrWwA-JNw@mail.gmail.com","threadId":"37213","inReplyTo":"CAL=YDWmSKBnjXiBUJjOb-+M7R8d==mMsN11DjDTDxU2+WAh+vQ@mail.gmail.com","subject":"Re: [PATCH 1/5] refs.c: allow passing raw git_committer_info as email to _update_reflog","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-07-28T23:39:55Z","receivedAt":"2014-07-28T23:39:55Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Jul 28, 2014 at 2:01 PM, Ronnie Sahlberg <sahlberg@google.com> wrote:\n> On Fri, Jul 25, 2014 at 12:37 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n>> Ronnie Sahlberg wrote:\n>>>  /*\n>>>   * Append a reflog entry for refname. If the REFLOG_TRUNCATE flag is set\n>>>   * this update will first truncate the reflog before writing the entry.\n>>>   * If msg is NULL no update will be written to the log.\n>>>   */\n>>>  int transaction_update_reflog(struct ref_transaction *transaction,\n>>>                                const char *refname,\n>>>                                const unsigned char *new_sha1,\n>>>                                const unsigned char *old_sha1,\n>>>                                const char *email,\n>>>                                unsigned long timestamp, int tz,\n>>>                                const char *msg, int flags,\n>>>                                struct strbuf *err);\n>>\n>> This is a lot of parameters, some optional, not all documented.  Would\n>> it make sense to pack some into a struct?\n>\n> I changed email,timestamp,tz into a struct\n> /*\n>  * Committer data provided to reflog updates.\n>  * If flags contain REFLOG_COMMITTER_DATA_IS_VALID then\n>  * then the structure contains a prebaked committer string\n\ns/then then/then/\n\n>  * just like git_committer_info() would return.\n>  *\n>  * If flags does not contain REFLOG_COMMITTER_DATA_IS_VALID\n>  * then the committer info string will be generated using the passed\n>  * email, timestamp and tz fields.\n>  * This is useful for example from reflog iterators where you are passed\n>  * these fields individually and not as a prebaked git_committer_info()\n>  * string.\n>  */\n> struct reflog_committer_info {\n> const char *committer_info;\n>\n> const char *id;\n> unsigned long timestamp;\n> int tz;\n> };\n>\n>>\n>> Thanks and hope that helps,\n>> Jonathan\n"}]}