{"thread":{"id":"25345","subject":"[TopGit PATCH] hooks/pre-commit: check for cycles in dependencies","startedAt":"2010-10-04T21:07:27Z","lastAt":"2010-10-04T21:22:17Z","messageCount":3,"participants":["Bert Wesarg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"152598","messageId":"1286226447-3390-1-git-send-email-bert.wesarg@googlemail.com","threadId":"25345","inReplyTo":null,"subject":"[TopGit PATCH] hooks/pre-commit: check for cycles in dependencies","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2010-10-04T21:07:27Z","receivedAt":"2010-10-04T21:07:27Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"We need only to consider newly added dependencies.  For each of these deps we\nneed to check if there is a path from this dep to the current HEAD.\n\nWe use recursive_dep() for this task.  Even if recursive_dep() uses a DFS\ntraversal it will not run into an endless loop if there would be a cycle,\nbecause recursive_dep() takes .topdeps only from committed trees.  And we\nrequire that the committed dependency graph has no cycles.\n\nSigned-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n\n---\n\nNote, the dependency on bw/tred is only historical, it only depends on master.\n\n hooks/pre-commit.sh |   35 +++++++++++++++++++++++++++++++++--\n 1 files changed, 33 insertions(+), 2 deletions(-)\n\ndiff --git a/hooks/pre-commit.sh b/hooks/pre-commit.sh\nindex 9d677e9..fd960a4 100644 hooks/pre-commit.sh\n--- a/hooks/pre-commit.sh\n+++ b/hooks/pre-commit.sh\n@@ -20,7 +20,8 @@ tg_util\n if head_=$(git symbolic-ref -q HEAD); then\n \tcase \"$head_\" in\n \t\trefs/heads/*)\n-\t\t\tgit rev-parse -q --verify \"refs/top-bases${head_#refs/heads}\" >/dev/null || exit 0;;\n+\t\t\thead_=\"${head_#refs/heads/}\"\n+\t\t\tgit rev-parse -q --verify \"refs/top-bases/$head_\" >/dev/null || exit 0;;\n \t\t*)\n \t\t\texit 0;;\n \tesac\n@@ -35,4 +36,34 @@ fi\n [ -s \"$root_dir/.topmsg\" ] ||\n \tdie \".topmsg is missing\"\n \n-# TODO: Verify .topdeps for valid branch names and against cycles\n+check_cycle_name()\n+{\n+\t[ \"$head_\" != \"$_dep\" ] ||\n+\t\tdie \"TopGit dependencies form a cycle: perpetrator is $_name\"\n+}\n+\n+# we only need to check newly added deps and for these if a path exists to the\n+# current HEAD\n+git diff --cached \"$root_dir/.topdeps\" |\n+\tawk '\n+BEGIN      { in_hunk = 0; }\n+/^@@ /     { in_hunk = 1; }\n+/^\\+/      { if (in_hunk == 1) printf(\"%s\\n\", substr($0, 2)); }\n+/^[^@ +-]/ { in_hunk = 0; }\n+' |\n+\twhile read newly_added; do\n+\t\t# check for self as dep\n+\t\t[ \"$head_\" != \"$newly_added\" ] ||\n+\t\t\tdie \"Can't have myself as dep\"\n+\n+\t\t# deps can be non-tgish but we can't run recurse_deps() on them\n+\t\tref_exists \"refs/top-bases/$newly_added\" ||\n+\t\t\tcontinue\n+\n+\t\t# recurse_deps uses dfs but takes the .topdeps from the tree,\n+\t\t# therefore no endless loop in the cycle-check\n+\t\tno_remotes=1 recurse_deps check_cycle_name \"$newly_added\"\n+\tdone\n+\n+\n+# TODO: Verify .topdeps for valid branch names\n-- \ntg: (550c37a..) bw/check-for-dep-cycle (depends on: bw/tred)\n"},{"id":"152601","messageId":"1286227130-8306-1-git-send-email-bert.wesarg@googlemail.com","threadId":"25345","inReplyTo":"1286226447-3390-1-git-send-email-bert.wesarg@googlemail.com","subject":"[TopGit PATCH] pre-commit: check .topdeps for valid branches","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2010-10-04T21:18:50Z","receivedAt":"2010-10-04T21:18:50Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n\n---\n hooks/pre-commit.sh |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/hooks/pre-commit.sh b/hooks/pre-commit.sh\nindex fd960a4..f6901e4 100644 hooks/pre-commit.sh\n--- a/hooks/pre-commit.sh\n+++ b/hooks/pre-commit.sh\n@@ -52,6 +52,9 @@ BEGIN      { in_hunk = 0; }\n /^[^@ +-]/ { in_hunk = 0; }\n ' |\n \twhile read newly_added; do\n+\t\tref_exists \"$newly_added\" ||\n+\t\t\tdie \"Invalid branch as dependent: $newly_added\"\n+\n \t\t# check for self as dep\n \t\t[ \"$head_\" != \"$newly_added\" ] ||\n \t\t\tdie \"Can't have myself as dep\"\n@@ -64,6 +67,3 @@ BEGIN      { in_hunk = 0; }\n \t\t# therefore no endless loop in the cycle-check\n \t\tno_remotes=1 recurse_deps check_cycle_name \"$newly_added\"\n \tdone\n-\n-\n-# TODO: Verify .topdeps for valid branch names\n-- \ntg: (d4c1eaf..) bw/check-valid-deps (depends on: bw/check-for-dep-cycle)\n"},{"id":"152602","messageId":"1286227337-8934-1-git-send-email-bert.wesarg@googlemail.com","threadId":"25345","inReplyTo":"1286227130-8306-1-git-send-email-bert.wesarg@googlemail.com","subject":"[TopGit PATCH] hooks/pre-commit: check for deps repititions","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2010-10-04T21:22:17Z","receivedAt":"2010-10-04T21:22:17Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"A dep should only be listed once in .topdeps, force this.\n\nSigned-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n\n---\n hooks/pre-commit.sh |   12 ++++++++++++\n 1 files changed, 12 insertions(+), 0 deletions(-)\n\ndiff --git a/hooks/pre-commit.sh b/hooks/pre-commit.sh\nindex f6901e4..e8986d6 100644 hooks/pre-commit.sh\n--- a/hooks/pre-commit.sh\n+++ b/hooks/pre-commit.sh\n@@ -67,3 +67,15 @@ BEGIN      { in_hunk = 0; }\n \t\t# therefore no endless loop in the cycle-check\n \t\tno_remotes=1 recurse_deps check_cycle_name \"$newly_added\"\n \tdone\n+\n+# check for repititions of deps\n+depdir=\"$(mktemp -t -d tg-depdir.XXXXXX)\" ||\n+\tdie \"Can't check for mulitple occurrences of deps\"\n+trap \"rm -rf '$depdir'\" 0\n+cat_file \"(i):.topdeps\" |\n+\twhile read dep; do\n+\t\t[ ! -d \"$depdir/$dep\" ] ||\n+\t\t\tdie \"Mulitple occurrences of the same dep: $dep\"\n+\t\tmkdir -p \"$depdir/$dep\" ||\n+\t\t\tdie \"Can't check for mulitple occurrences of deps\"\n+\tdone\n-- \ntg: (a2bfc32..) bw/check-for-repetitions (depends on: bw/check-valid-deps)\n"}]}