{"thread":{"id":"37303","subject":"[PATCH] git-gui: make gc warning threshold match 'git gc --auto'","startedAt":"2014-08-06T18:51:01Z","lastAt":"2014-08-10T10:40:03Z","messageCount":2,"participants":["Karsten Blees","Pat Thoyts"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"247354","messageId":"53E27915.9040305@gmail.com","threadId":"37303","inReplyTo":null,"subject":"[PATCH] git-gui: make gc warning threshold match 'git gc --auto'","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-08-06T18:51:01Z","receivedAt":"2014-08-06T18:51:01Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"The number of loose objects at which git-gui shows a gc warning has\nhistorically been hardcoded to ~2000, or ~200 on Windows. The warning can\nonly be disabled completely via gui.gcwarning=false.\n\nEspecially on Windows, the hardcoded threshold is so ridiculously low that\ngit-gui often complains even immediately after gc (due to loose objects\nonly referenced by the reflog).\n\n'git gc --auto' uses a much bigger threshold to check if gc is necessary.\nAdditionally, the value can be configured via gc.auto (default 6700).\nThere's no special case for Windows.\n\nChange git-gui so that it only warns if 'git gc --auto' would also do an\nautomatic gc, i.e.:\n - calculate the threshold from the gc.auto setting (default 6700,\n   disabled if <= 0)\n - check directory .git/objects/17\n\nWe still check four directories (14-17) if gc.auto is very small, to get a\nbetter estimate.\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\n---\n git-gui/lib/database.tcl | 17 ++++++++++++-----\n 1 file changed, 12 insertions(+), 5 deletions(-)\n\ndiff --git a/git-gui/lib/database.tcl b/git-gui/lib/database.tcl\nindex 1f187ed..212b195 100644\n--- a/git-gui/lib/database.tcl\n+++ b/git-gui/lib/database.tcl\n@@ -89,19 +89,26 @@ proc do_fsck_objects {} {\n }\n \n proc hint_gc {} {\n+\tglobal repo_config\n+\tset auto_gc $repo_config(gc.auto)\n+\tif {$auto_gc eq {}} {\n+\t\tset auto_gc 6700\n+\t} elseif {$auto_gc <= 0} {\n+\t\treturn\n+\t}\n+\n \tset ndirs 1\n-\tset limit 8\n-\tif {[is_Windows]} {\n+\tset limit [expr {($auto_gc + 255) / 256}]\n+\tif {$limit < 4} {\n \t\tset ndirs 4\n-\t\tset limit 1\n \t}\n \n \tset count [llength [glob \\\n \t\t-nocomplain \\\n \t\t-- \\\n-\t\t[gitdir objects 4\\[0-[expr {$ndirs-1}]\\]/*]]]\n+\t\t[gitdir objects 1\\[[expr {8-$ndirs}]-7\\]/*]]]\n \n-\tif {$count >= $limit * $ndirs} {\n+\tif {$count > $limit * $ndirs} {\n \t\tset objects_current [expr {$count * 256/$ndirs}]\n \t\tif {[ask_popup \\\n \t\t\t[mc \"This repository currently has approximately %i loose objects.\n-- \n2.0.3.921.ga7e731a.dirty\n"},{"id":"247547","messageId":"8738d4aarg.fsf@red.patthoyts.tk","threadId":"37303","inReplyTo":"53E27915.9040305@gmail.com","subject":"Re: [PATCH] git-gui: make gc warning threshold match 'git gc --auto'","fromName":"Pat Thoyts","fromEmail":"patthoyts@users.sourceforge.net","sentAt":"2014-08-10T10:40:03Z","receivedAt":"2014-08-10T10:40:03Z","isPatch":true,"sender":{"key":"patthoyts@users.sourceforge.net","avatar":"https://avatars.githubusercontent.com/u/30739?v=4"},"body":"Karsten Blees <karsten.blees@gmail.com> writes:\n\n>The number of loose objects at which git-gui shows a gc warning has\n>historically been hardcoded to ~2000, or ~200 on Windows. The warning can\n>only be disabled completely via gui.gcwarning=false.\n>\n>Especially on Windows, the hardcoded threshold is so ridiculously low that\n>git-gui often complains even immediately after gc (due to loose objects\n>only referenced by the reflog).\n>\n>'git gc --auto' uses a much bigger threshold to check if gc is necessary.\n>Additionally, the value can be configured via gc.auto (default 6700).\n>There's no special case for Windows.\n>\n>Change git-gui so that it only warns if 'git gc --auto' would also do an\n>automatic gc, i.e.:\n> - calculate the threshold from the gc.auto setting (default 6700,\n>   disabled if <= 0)\n> - check directory .git/objects/17\n>\n>We still check four directories (14-17) if gc.auto is very small, to get a\n>better estimate.\n>\n>Signed-off-by: Karsten Blees <blees@dcon.de>\n>---\n> git-gui/lib/database.tcl | 17 ++++++++++++-----\n> 1 file changed, 12 insertions(+), 5 deletions(-)\n>\n>diff --git a/git-gui/lib/database.tcl b/git-gui/lib/database.tcl\n>index 1f187ed..212b195 100644\n>--- a/git-gui/lib/database.tcl\n>+++ b/git-gui/lib/database.tcl\n>@@ -89,19 +89,26 @@ proc do_fsck_objects {} {\n> }\n> \n> proc hint_gc {} {\n>+\tglobal repo_config\n>+\tset auto_gc $repo_config(gc.auto)\n>+\tif {$auto_gc eq {}} {\n>+\t\tset auto_gc 6700\n>+\t} elseif {$auto_gc <= 0} {\n>+\t\treturn\n>+\t}\n>+\n> \tset ndirs 1\n>-\tset limit 8\n>-\tif {[is_Windows]} {\n>+\tset limit [expr {($auto_gc + 255) / 256}]\n>+\tif {$limit < 4} {\n> \t\tset ndirs 4\n>-\t\tset limit 1\n> \t}\n> \n> \tset count [llength [glob \\\n> \t\t-nocomplain \\\n> \t\t-- \\\n>-\t\t[gitdir objects 4\\[0-[expr {$ndirs-1}]\\]/*]]]\n>+\t\t[gitdir objects 1\\[[expr {8-$ndirs}]-7\\]/*]]]\n> \n>-\tif {$count >= $limit * $ndirs} {\n>+\tif {$count > $limit * $ndirs} {\n> \t\tset objects_current [expr {$count * 256/$ndirs}]\n> \t\tif {[ask_popup \\\n> \t\t\t[mc \"This repository currently has approximately %i loose objects.\n\nApplying this to git-gui I get an error raised \n  can't read \"repo_config(gc.auto)\": no such element in array\nwhich occurs because I've never set this config variable and it is not\npresent in the default_config array which is used to initialize repo_config.\n\nThe following should solve this by moving where we ser the default:\n\n>From bdb136cbcb2a3fc0e3441f852e4bf4525ee4cf99 Mon Sep 17 00:00:00 2001\nFrom: Pat Thoyts <patthoyts@users.sourceforge.net>\nDate: Sun, 10 Aug 2014 11:36:47 +0100\nSubject: [PATCH] git-gui: initialize the default value for gc.auto in case it\n is unset.\n\nSigned-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n---\n git-gui.sh       | 1 +\n lib/database.tcl | 4 +---\n 2 files changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex b186329..ee9c47b 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -880,6 +880,7 @@ proc apply_config {} {\n }\n \n set default_config(branch.autosetupmerge) true\n+set default_config(gc.auto) 6700\n set default_config(merge.tool) {}\n set default_config(mergetool.keepbackup) true\n set default_config(merge.diffstat) true\ndiff --git a/lib/database.tcl b/lib/database.tcl\nindex 212b195..d9ba323 100644\n--- a/lib/database.tcl\n+++ b/lib/database.tcl\n@@ -91,9 +91,7 @@ proc do_fsck_objects {} {\n proc hint_gc {} {\n \tglobal repo_config\n \tset auto_gc $repo_config(gc.auto)\n-\tif {$auto_gc eq {}} {\n-\t\tset auto_gc 6700\n-\t} elseif {$auto_gc <= 0} {\n+\tif {$auto_gc <= 0} {\n \t\treturn\n \t}\n \n-- \nPat Thoyts                            http://www.patthoyts.tk/\nPGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD\n"}]}