git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/9] Fix issues of reference-transaction hook for various git commands

From
Jiang Xin <worldhello.net@gmail.com>
Date
Jul 29, 2022, 10:12 UTC
Message-ID
<20220729101245.6469-1-worldhello.net@gmail.com>
From: Jiang Xin <zhiyou.jx@alibaba-inc.com>

Before Patrick introduced the reference-transaction hook in git 2.28, We had implemented some internal transaction hooks "pre-txn" and "post-txn" for our internal git infrastructure. The "pre-txn" hook is used to check our site-wide lockfile to disable write services for the repository. The "post-txn" hook is used to update the timestamp and checksum of the repository. Recently I wanted to migrate our internal implementation to use ref-txn hooks, but I ran into the same issues reported by Michael and Bryan:

 * https://lore.kernel.org/git/CAGyf7-GYYA2DOnAVYW--=QEc2WjSHzUhp2OQyuyOr3EOtFDm6g@mail.gmail.com/
 * https://lore.kernel.org/git/pull.1228.git.1651676435634.gitgitgadget@gmail.com/
This patch series try to fix the issues I encountered.
Patch 1/9 adds more testcases in t1416:
 * Some commands failed because the expected "<old-oid>" was
 * "<zero-oid>".
   Such as: "git update-ref -d <ref>".
 * Some commands failed because the "reference-transaction committed"
   command was repeated multiple times for the same changes. Such as:
   "git update-ref -d <ref>" and "git tag -d <tag>".
 * Some commands should not trigger the "reference-transaction" hook
   because no real changes have occurred to the repository. Such as:
   "git pack-refs --all" and "git gc".
 * Some commands did not execute the "reference-transaction" hook at
 * all.
   Such as: "git branch -c <src> <dest>", "git branch -m <old> <new>"

Patch 2/9 propagates real old-oid found in lockfile to the update entry for txn, so we can get proper old-oid in "prepared" and "committed" stage for ref-txn hook.

Patch 3/9 adds a new flag in transaction, and we can turn off running the entire hook for git-pack-refs in patch 4/9. We can also turn off the "committed" and "aborted" stages of the ref-txn hook for "packed-ref-store", but we can still run "prepared" stage of the hook. See patch 5/9.

Patch 6/9 and 7/9 create an extended function "ref_transaction_update_extended()" to be used in patch 8/9 to reimplement branch copy and rename.

Patch 9/9 reimplents "files_delete_refs()" to fix failed testcases for "git branch -d" and "git tag -d".

--
Jiang Xin (9):
  t1416: more testcases for reference-transaction hook
  refs: update missing old-oid in transaction from lockfile
  refs: add new field in transaction for running transaction hook
  refs: do not run transaction hook for git-pack-refs
  refs: avoid duplicate running of the reference-transaction hook
  refs: add reflog_info to hold more fields for reflog entry
  refs: get error message via refs_update_ref_extended()
  refs: reimplement files_copy_or_rename_ref() to run hook
  refs: reimplement refs_delete_refs() and run hook once
 refs.c                           |   99 ++-
 refs.h                           |   23 +
 refs/debug.c                     |    2 +-
 refs/files-backend.c             |  158 ++---
 refs/packed-backend.c            |   51 +-
 refs/refs-internal.h             |   25 +-
 t/t1416-ref-transaction-hooks.sh | 1072 +++++++++++++++++++++++++++++-
 t/t5510-fetch.sh                 |   17 +
 8 files changed, 1264 insertions(+), 183 deletions(-)
-- 
2.36.1.25.gc87d5ad63a.dirty
Next: Jiang Xin
Message 1 of 27 in “Fix issues of reference-transaction hook for various git commands”
  1. 0/9 Fix issues of reference-transaction hook for various git commandsJiang Xin, Jul 29, 2022
  2. 2/9 refs: update missing old-oid in transaction from lockfileJiang Xin, Jul 29, 2022
  3. 3/9 refs: add new field in transaction for running transaction hookJiang Xin, Jul 29, 2022
  4. 1/9 t1416: more testcases for reference-transaction hookJiang Xin, Jul 29, 2022
  5. Eric SunshineJul 30, 2022
  6. Jiang XinJul 31, 2022
  7. 4/9 refs: do not run transaction hook for git-pack-refsJiang Xin, Jul 29, 2022
  8. 5/9 refs: avoid duplicate running of the reference-transaction hookJiang Xin, Jul 29, 2022
  9. Michael HeemskerkAug 2, 2022
  10. Jiang XinAug 5, 2022
  11. 0/9 Fix issues of refx-txn hook for various git commandsJiang Xin, Aug 19, 2022
  12. 2/9 refs: update missing old-oid in transaction from lockfileJiang Xin, Aug 19, 2022
  13. 3/9 refs: add new field in transaction for running transaction hookJiang Xin, Aug 19, 2022
  14. 1/9 t1416: more testcases for reference-transaction hookJiang Xin, Aug 19, 2022
  15. 4/9 refs: do not run transaction hook for git-pack-refsJiang Xin, Aug 19, 2022
  16. 5/9 refs: avoid duplicate running of the reference-transaction hookJiang Xin, Aug 19, 2022
  17. 6/9 refs: add reflog_info to hold more fields for reflog entryJiang Xin, Aug 19, 2022
  18. 9/9 refs: reimplement refs_delete_refs() and run hook onceJiang Xin, Aug 19, 2022
  19. 7/9 refs: get error message via refs_update_ref_extended()Jiang Xin, Aug 19, 2022
  20. 8/9 refs: reimplement files_copy_or_rename_ref() to run refs-txn hookJiang Xin, Aug 19, 2022
  21. 6/9 refs: add reflog_info to hold more fields for reflog entryJiang Xin, Jul 29, 2022
  22. Jiang XinAug 1, 2022
  23. 7/9 refs: get error message via refs_update_ref_extended()Jiang Xin, Jul 29, 2022
  24. 8/9 refs: reimplement files_copy_or_rename_ref() to run hookJiang Xin, Jul 29, 2022
  25. 9/9 refs: reimplement refs_delete_refs() and run hook onceJiang Xin, Jul 29, 2022
  26. Michael HeemskerkAug 2, 2022
  27. Patrick SteinhardtAug 9, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.