{"thread":{"id":"25402","subject":"[TopGit PATCH] provide global temporary directory","startedAt":"2010-10-09T20:20:20Z","lastAt":"2010-10-09T20:20:20Z","messageCount":1,"participants":["Bert Wesarg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"153076","messageId":"c6914b6c0299420aa4fecc5c7a511e64e0cb8844.1286620937.git.bert.wesarg@googlemail.com","threadId":"25402","inReplyTo":null,"subject":"[TopGit PATCH] provide global temporary directory","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2010-10-09T20:20:20Z","receivedAt":"2010-10-09T20:20:20Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"The standard procedure 'tmp=mktemp; trap \"rm $tmp\" 0' was broken with the\nintroduction of the pager. Which overwrites the trap itself to close and\nremove the pager fifo.\n\nNow tg provides a temp playground and all other temp files should be created\ninside this directory and only this directory will be removed with the exit\ntrap. setup_pager still overwrites the trap, but keeps the rm command from\nthe global temp directory. To simplify this the new function get_temp() is\nprovided.\n\nSigned-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n---\n tg-export.sh  |    3 +--\n tg-info.sh    |    3 +--\n tg-mail.sh    |    4 +---\n tg-patch.sh   |    3 +--\n tg-push.sh    |    3 +--\n tg-summary.sh |    3 +--\n tg-update.sh  |    3 +--\n tg.sh         |   27 +++++++++++++++++++--------\n 8 files changed, 26 insertions(+), 23 deletions(-)\n\ndiff --git a/tg-export.sh b/tg-export.sh\nindex 6d82d55..921e933 100644\n--- a/tg-export.sh\n+++ b/tg-export.sh\n@@ -57,8 +57,7 @@ if [ -z \"$branches\" ]; then\n fi\n \n \n-playground=\"$(mktemp -d -t tg-export.XXXXXX)\"\n-trap 'rm -rf \"$playground\"' EXIT\n+playground=\"$(get_temp tg-export -d)\"\n \n \n ## Collapse driver\ndiff --git a/tg-info.sh b/tg-info.sh\nindex 7d6a34c..10e257e 100644\n--- a/tg-info.sh\n+++ b/tg-info.sh\n@@ -51,7 +51,7 @@ fi\n git cat-file blob \"$name:.topdeps\" |\n \tsed '1{ s/^/Depends: /; n; }; s/^/         /;'\n \n-depcheck=\"$(mktemp -t tg-depcheck.XXXXXX)\"\n+depcheck=\"$(get_temp tg-depcheck)\"\n missing_deps=\n needs_update \"$name\" >\"$depcheck\" || :\n if [ -n \"$missing_deps\" ]; then\n@@ -72,6 +72,5 @@ if [ -s \"$depcheck\" ]; then\n else\n \techo \"Up-to-date.\"\n fi\n-rm \"$depcheck\"\n \n # vim:noet\ndiff --git a/tg-mail.sh b/tg-mail.sh\nindex 8167ade..dd4a95a 100644\n--- a/tg-mail.sh\n+++ b/tg-mail.sh\n@@ -34,7 +34,7 @@ if [ -n \"$in_reply_to\" ]; then\n fi\n \n \n-patchfile=\"$(mktemp -t tg-mail.XXXXXX)\"\n+patchfile=\"$(get_temp tg-mail)\"\n \n $tg patch \"$name\" >\"$patchfile\"\n \n@@ -54,6 +54,4 @@ people=\n # NOTE: git-send-email handles cc itself\n eval git send-email $send_email_args \"$people\" \"$patchfile\"\n \n-rm \"$patchfile\"\n-\n # vim:noet\ndiff --git a/tg-patch.sh b/tg-patch.sh\nindex 7bafdfe..68efcf0 100644\n--- a/tg-patch.sh\n+++ b/tg-patch.sh\n@@ -51,7 +51,7 @@ echo\n [ -n \"$(git grep $diff_opts '^[-]--' ${diff_committed_only:+\"$name\"} -- \".topmsg\")\" ] || echo '---'\n \n # Evil obnoxious hack to work around the lack of git diff --exclude\n-git_is_stupid=\"$(mktemp -t tg-patch-changes.XXXXXX)\"\n+git_is_stupid=\"$(get_temp tg-patch-changes)\"\n git diff --name-only $diff_opts \"$base_rev\" ${diff_committed_only:+\"$name\"} -- |\n \tfgrep -vx \".topdeps\" |\n \tfgrep -vx \".topmsg\" >\"$git_is_stupid\" || : # fgrep likes to fail randomly?\n@@ -61,7 +61,6 @@ if [ -s \"$git_is_stupid\" ]; then\n else\n \techo \"No changes.\"\n fi\n-rm \"$git_is_stupid\"\n \n echo '-- '\n echo \"tg: ($base_rev..) $name (depends on: $(cat_file \"$topic:.topdeps\" | paste -s -d' '))\"\ndiff --git a/tg-push.sh b/tg-push.sh\nindex 199d738..a928fba 100644\n--- a/tg-push.sh\n+++ b/tg-push.sh\n@@ -45,8 +45,7 @@ for name in $branches; do\n \tref_exists \"$name\" || die \"detached HEAD? Can't push $name\"\n done\n \n-_listfile=\"$(mktemp -t tg-push-listfile.XXXXXX)\"\n-trap \"rm -f \\\"$_listfile\\\"\" 0\n+_listfile=\"$(get_temp tg-push-listfile)\"\n \n push_branch()\n {\ndiff --git a/tg-summary.sh b/tg-summary.sh\nindex af16888..612bd27 100644\n--- a/tg-summary.sh\n+++ b/tg-summary.sh\n@@ -55,10 +55,9 @@ EOT\n fi\n \n if [ -n \"$sort\" ]; then\n-\ttsort_input=`mktemp`\n+\ttsort_input=\"$(get_temp tg-summary-sort)\"\n \texec 4>$tsort_input\n \texec 5<$tsort_input\n-\trm $tsort_input\n fi\n \n ## List branches\ndiff --git a/tg-update.sh b/tg-update.sh\nindex b256c7c..5162c52 100644\n--- a/tg-update.sh\n+++ b/tg-update.sh\n@@ -27,7 +27,7 @@ base_rev=\"$(git rev-parse --short --verify \"refs/top-bases/$name\" 2>/dev/null)\"\n \n ## First, take care of our base\n \n-depcheck=\"$(mktemp -t tg-depcheck.XXXXXX)\"\n+depcheck=\"$(get_temp tg-depcheck)\"\n missing_deps=\n needs_update \"$name\" >\"$depcheck\" || :\n [ -z \"$missing_deps\" ] || die \"some dependencies are missing: $missing_deps\"\n@@ -96,7 +96,6 @@ if [ -s \"$depcheck\" ]; then\n else\n \tinfo \"The base is up-to-date.\"\n fi\n-rm \"$depcheck\"\n \n # Home, sweet home...\n # (We want to always switch back, in case we were on the base from failed\ndiff --git a/tg.sh b/tg.sh\nindex 3718702..abcfe1f 100644\n--- a/tg.sh\n+++ b/tg.sh\n@@ -152,7 +152,7 @@ recurse_deps()\n \t_name=\"$1\"; # no shift\n \t_depchain=\"$*\"\n \n-\t_depsfile=\"$(mktemp -t tg-depsfile.XXXXXX)\"\n+\t_depsfile=\"$(get_temp tg-depsfile)\"\n \t# If no_remotes is unset check also our base against remote base.\n \t# Checking our head against remote head has to be done in the helper.\n \tif test -z \"$no_remotes\" && has_remote \"top-bases/$_name\"; then\n@@ -185,7 +185,6 @@ recurse_deps()\n \t\teval \"$_cmd\"\n \tdone <\"$_depsfile\"\n \tmissing_deps=\"${missing_deps# }\"\n-\trm \"$_depsfile\"\n \treturn $_ret\n }\n \n@@ -336,19 +335,28 @@ setup_pager()\n \t# now spawn pager\n \texport LESS=\"${LESS:-FRSX}\"\t# as in pager.c:pager_preexec()\n \n-\t_pager_fifo_dir=\"$(mktemp -t -d tg-pager-fifo.XXXXXX)\"\n-\t_pager_fifo=\"$_pager_fifo_dir/0\"\n-\tmkfifo -m 600 \"$_pager_fifo\"\n+\t# setup_pager should be called only once per command\n+\tpager_fifo=\"$tg_tmp_dir/pager\"\n+\tmkfifo -m 600 \"$pager_fifo\"\n \n-\t\"$TG_PAGER\" < \"$_pager_fifo\" &\n-\texec > \"$_pager_fifo\"\t\t# dup2(pager_fifo.in, 1)\n+\t\"$TG_PAGER\" < \"$pager_fifo\" &\n+\texec > \"$pager_fifo\"\t\t# dup2(pager_fifo.in, 1)\n \n \t# this is needed so e.g. `git diff` will still colorize it's output if\n \t# requested in ~/.gitconfig with color.diff=auto\n \texport GIT_PAGER_IN_USE=1\n \n \t# atexit(close(1); wait pager)\n-\ttrap \"exec >&-; rm \\\"$_pager_fifo\\\"; rmdir \\\"$_pager_fifo_dir\\\"; wait\" EXIT\n+\t# deliberately overwrites the global EXIT trap\n+\ttrap \"exec >&-; rm -rf \\\"$tg_tmp_dir\\\"; wait\" EXIT\n+}\n+\n+# get_temp NAME [-d]\n+# creates a new temporary file (or directory with -d) in the global\n+# temporary directory $tg_tmp_dir with pattern prefix NAME\n+get_temp()\n+{\n+\tmktemp ${2-} \"$tg_tmp_dir/$1.XXXXXX\"\n }\n \n ## Startup\n@@ -368,6 +376,9 @@ tg=\"tg\"\n # make sure merging the .top* files will always behave sanely\n setup_ours\n setup_hook \"pre-commit\"\n+# create global temporary directories, inside GIT_DIR\n+tg_tmp_dir=\"$(mktemp -d \"$git_dir/tg-tmp.XXXXXX\")\"\n+trap \"rm -rf \\\"$tg_tmp_dir\\\"\" EXIT\n \n ## Dispatch\n \n-- \n1.7.1.1067.g5aeb7\n"}]}