{"thread":{"id":"43089","subject":"Re: [PATCH] Enable reflogs by default in any repository with a working directory.","startedAt":"2006-12-14T20:35:37Z","lastAt":"2006-12-15T21:55:15Z","messageCount":9,"participants":["Shawn Pearce","J. Bruce Fields","Junio C Hamano","Shawn O. Pearce","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"298663","messageId":"7v1wn243mu.fsf@assigned-by-dhcp.cox.net","threadId":"43089","inReplyTo":"20061214200245.GP1747@spearce.org","subject":"Re: What's in git.git (stable)","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-14T20:35:37Z","receivedAt":"2006-12-14T20:35:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> Does anyone on the mailing list really have an objection to having\n> reflogs on by default?\n\nWhen you talk about potential breakage for existing users, you\nshould not be asking people on THIS list.  You instead should\ntalk with or at least think about people on linux-kernel, x.org\nand wine people, and possibly others.  git is maturing, and we\ncannot expect that most of the users are paying attention to\nwhat is happening on this list anymore.\n\nI 100% agree that it makes sense to have reflog enabled for a\nrepository with an associated worktree.  I would say that we do\nnot even need it to be conditional on the configuration variable\nfor such a repository.\n\nMy answer to your question is:\n\n\tkernel.org:/pub/scm/\n\nI would REALLY be worried to have reflog enabled at a public\ndistribution point where the only ways the owners interact with\nit daily are 'git push' and 'git pull'.  As you mentioned, there\nis one extra potential receive-pack failure, and in general it\nis one more thing that can go wrong, and hard to notice breakage\nbecause it is on the other side of the connection.\n\nWorse yet, there is no easy way to garbage collect.  Even in an\nend-user repository with a worktree, the only way to garbage\ncollect older reflog entries is to edit the reflog files to\nremove the top part.\n\nMaybe a check to say if $GIT_DIR is \".git\" or ends with \"/.git\"\nthen enable it and otherwise honor the configuration variable,\nwithout changing the default in the code (with your patch) nor\nin the default configuration (\"enable for new repositories\" as I\nsuggested) might be a workable compromise.\n"},{"id":"297634","messageId":"20061214224117.GA26374@spearce.org","threadId":"43089","inReplyTo":"7v1wn243mu.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Enable reflogs by default in any repository with a working directory.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-14T22:41:17Z","receivedAt":"2006-12-14T22:41:17Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"New and experienced Git users alike are finding out too late that\nthey forgot to enable reflogs in the current repository, and cannot\nuse the information stored within it to recover from an incorrectly\nentered command such as `git reset --hard HEAD^^^` when they really\nmeant HEAD^^ (aka HEAD~2).\n\nSo enable reflogs by default in all future versions of Git, unless\nthe user specifically disables it with:\n\n  [core]\n    logAllRefUpdates = false\n\nin their .git/config or ~/.gitconfig.\n\nWe only enable reflogs in repositories that have a working directory\nassociated with them, as shared/bare repositories do not have\nan easy means to prune away old log entries, or may fail logging\nentirely if the user's gecos information is not valid during a push.\nThis heuristic was suggested on the mailing list by Junio.\n\nDocumentation was also updated to indicate the new default behavior.\nWe probably should start to teach usuing the reflog to recover\nfrom mistakes in some of the tutorial material, as new users are\nlikely to make a few along the way and will feel better knowing\nthey can recover from them quickly and easily, without fsck-objects'\nlost+found features.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n Documentation/config.txt |    7 +++++--\n builtin-init-db.c        |    4 ++++\n cache.h                  |    1 +\n environment.c            |    9 +++++++++\n 4 files changed, 19 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex a3587f8..8abb082 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -79,8 +79,11 @@ core.logAllRefUpdates::\n \tfile is automatically created for branch heads.\n \n \tThis information can be used to determine what commit\n-\twas the tip of a branch \"2 days ago\".  This value is\n-\tfalse by default (no automated creation of log files).\n+\twas the tip of a branch \"2 days ago\".\n+\n+\tThis value is true by default in a repository that has\n+\ta working directory associated with it, and false by\n+\tdefault in a bare repository.\n \n core.repositoryFormatVersion::\n \tInternal variable identifying the repository format and layout\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 235a0ee..214fc8e 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -239,6 +239,10 @@ static void create_default_files(const char *git_dir, const char *template_path)\n \t\tgit_config_set(\"core.filemode\",\n \t\t\t       filemode ? \"true\" : \"false\");\n \t}\n+\n+\t/* Enable logAllRefUpdates if a working tree is attached */\n+\tgit_config_set(\"core.logallrefupdates\",\n+\t\t!is_bare_git_dir(git_dir) ? \"true\" : \"false\");\n }\n \n static const char init_db_usage[] =\ndiff --git a/cache.h b/cache.h\nindex f2ec5c8..2d3df98 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -123,6 +123,7 @@ extern int cache_errno;\n #define INDEX_ENVIRONMENT \"GIT_INDEX_FILE\"\n #define GRAFT_ENVIRONMENT \"GIT_GRAFT_FILE\"\n \n+extern int is_bare_git_dir(const char *dir);\n extern const char *get_git_dir(void);\n extern char *get_object_directory(void);\n extern char *get_refs_directory(void);\ndiff --git a/environment.c b/environment.c\nindex 84d870c..b7256eb 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -48,6 +48,15 @@ static void setup_git_env(void)\n \tgit_graft_file = getenv(GRAFT_ENVIRONMENT);\n \tif (!git_graft_file)\n \t\tgit_graft_file = xstrdup(git_path(\"info/grafts\"));\n+\tlog_all_ref_updates = !is_bare_git_dir(git_dir);\n+}\n+\n+int is_bare_git_dir (const char *dir)\n+{\n+\tif (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT))\n+\t\treturn 0;\n+\tconst char *s = strrchr(dir, '/');\n+\treturn !s || strcmp(s + 1, DEFAULT_GIT_DIR_ENVIRONMENT);\n }\n \n const char *get_git_dir(void)\n-- \n"},{"id":"295174","messageId":"20061214224421.GD26202@spearce.org","threadId":"43089","inReplyTo":"7v1wn243mu.fsf@assigned-by-dhcp.cox.net","subject":"Re: What's in git.git (stable)","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-14T22:44:21Z","receivedAt":"2006-12-14T22:44:21Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Maybe a check to say if $GIT_DIR is \".git\" or ends with \"/.git\"\n> then enable it and otherwise honor the configuration variable,\n> without changing the default in the code (with your patch) nor\n> in the default configuration (\"enable for new repositories\" as I\n> suggested) might be a workable compromise.\n\nSee my latest patch.  Though that patch also sets the value in the\nconfig file, much as core.filemode is also set in the config file,\nbased on the guess determined by init-db at the time it was executed.\n\n-- \n"},{"id":"298708","messageId":"20061214231038.GC5147@fieldses.org","threadId":"43089","inReplyTo":"20061214224117.GA26374@spearce.org","subject":"Re: [PATCH] Enable reflogs by default in any repository with a working directory.","fromName":"J. Bruce Fields","fromEmail":"bfields@fieldses.org","sentAt":"2006-12-14T23:10:38Z","receivedAt":"2006-12-14T23:10:38Z","isPatch":true,"sender":{"key":"bfields@citi.umich.edu","avatar":null},"body":"On Thu, Dec 14, 2006 at 05:41:17PM -0500, Shawn O. Pearce wrote:\n> New and experienced Git users alike are finding out too late that\n> they forgot to enable reflogs in the current repository, and cannot\n> use the information stored within it to recover from an incorrectly\n> entered command such as `git reset --hard HEAD^^^` when they really\n> meant HEAD^^ (aka HEAD~2).\n\nStupid question--I assume a mention in the reflog doesn't count as a\nreal reference to an object, so they won't save you in the case when you\npruned recently?\n\n"},{"id":"298258","messageId":"20061214231832.GF26202@spearce.org","threadId":"43089","inReplyTo":"20061214231038.GC5147@fieldses.org","subject":"Re: [PATCH] Enable reflogs by default in any repository with a working directory.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-14T23:18:32Z","receivedAt":"2006-12-14T23:18:32Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"\"J. Bruce Fields\" <bfields@fieldses.org> wrote:\n> On Thu, Dec 14, 2006 at 05:41:17PM -0500, Shawn O. Pearce wrote:\n> > New and experienced Git users alike are finding out too late that\n> > they forgot to enable reflogs in the current repository, and cannot\n> > use the information stored within it to recover from an incorrectly\n> > entered command such as `git reset --hard HEAD^^^` when they really\n> > meant HEAD^^ (aka HEAD~2).\n> \n> Stupid question--I assume a mention in the reflog doesn't count as a\n> real reference to an object, so they won't save you in the case when you\n> pruned recently?\n\nNot a stupid question.  Your assumption is correct, its not a real\nreference, so prune will remove things that the log mentions but\nthat refs don't currently mention.\n\n-- \n"},{"id":"293911","messageId":"20061214234253.GD5147@fieldses.org","threadId":"43089","inReplyTo":"20061214231832.GF26202@spearce.org","subject":"Re: [PATCH] Enable reflogs by default in any repository with a working directory.","fromName":"J. Bruce Fields","fromEmail":"bfields@fieldses.org","sentAt":"2006-12-14T23:42:53Z","receivedAt":"2006-12-14T23:42:53Z","isPatch":true,"sender":{"key":"bfields@citi.umich.edu","avatar":null},"body":"On Thu, Dec 14, 2006 at 06:18:32PM -0500, Shawn Pearce wrote:\n> \"J. Bruce Fields\" <bfields@fieldses.org> wrote:\n> > Stupid question--I assume a mention in the reflog doesn't count as a\n> > real reference to an object, so they won't save you in the case when you\n> > pruned recently?\n> \n> Not a stupid question.  Your assumption is correct, its not a real\n> reference, so prune will remove things that the log mentions but\n> that refs don't currently mention.\n\nOK, thanks.  So we just need to make sure that's documented someplace.\n\n"},{"id":"298227","messageId":"Pine.LNX.4.63.0612150112010.3635@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43089","inReplyTo":"20061214224117.GA26374@spearce.org","subject":"Re: [PATCH] Enable reflogs by default in any repository with a working directory.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-15T00:13:50Z","receivedAt":"2006-12-15T00:13:50Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 14 Dec 2006, Shawn O. Pearce wrote:\n\n> +int is_bare_git_dir (const char *dir)\n> +{\n> +\tif (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT))\n> +\t\treturn 0;\n> +\tconst char *s = strrchr(dir, '/');\n> +\treturn !s || strcmp(s + 1, DEFAULT_GIT_DIR_ENVIRONMENT);\n>  }\n\nThis function does not really determine if the repo is bare. I have no \nbetter name for it, though.\n\nCiao,\nDscho\n"},{"id":"293831","messageId":"20061215002015.GI26202@spearce.org","threadId":"43089","inReplyTo":"Pine.LNX.4.63.0612150112010.3635@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Enable reflogs by default in any repository with a working directory.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-15T00:20:15Z","receivedAt":"2006-12-15T00:20:15Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n> \n> On Thu, 14 Dec 2006, Shawn O. Pearce wrote:\n> \n> > +int is_bare_git_dir (const char *dir)\n> > +{\n> > +\tif (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT))\n> > +\t\treturn 0;\n> > +\tconst char *s = strrchr(dir, '/');\n> > +\treturn !s || strcmp(s + 1, DEFAULT_GIT_DIR_ENVIRONMENT);\n> >  }\n> \n> This function does not really determine if the repo is bare. I have no \n> better name for it, though.\n\nguess_if_bare_git_dir ?\n\nI struggled to name that thing because it can't really tell, its just\nguessing... but it is going to be right most of the time.  Of course\nI'm sure there's some Git user somewhere who will confuse it.\n\n-- \n"},{"id":"297571","messageId":"7vodq4n7ss.fsf@assigned-by-dhcp.cox.net","threadId":"43089","inReplyTo":"20061215002015.GI26202@spearce.org","subject":"Re: [PATCH] Enable reflogs by default in any repository with a working directory.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-15T21:55:15Z","receivedAt":"2006-12-15T21:55:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>> Hi,\n>> \n>> On Thu, 14 Dec 2006, Shawn O. Pearce wrote:\n>> \n>> > +int is_bare_git_dir (const char *dir)\n>> > +{\n>> > +\tif (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT))\n>> > +\t\treturn 0;\n>> > +\tconst char *s = strrchr(dir, '/');\n>> > +\treturn !s || strcmp(s + 1, DEFAULT_GIT_DIR_ENVIRONMENT);\n>> >  }\n>> \n>> This function does not really determine if the repo is bare. I have no \n>> better name for it, though.\n>\n> guess_if_bare_git_dir ?\n>\n> I struggled to name that thing because it can't really tell, its just\n> guessing... but it is going to be right most of the time.  Of course\n> I'm sure there's some Git user somewhere who will confuse it.\n\nI think the name is fine, but probably a comment in front would\nhelp unconfuse people.\n\n\t/* Does it look like a repository without a working tree? */\n\nUnfortunately there currently are public bare repositories that\nhave index under them because they were primed by rsync from\ndevelopers' working repositories.  I do not think it is\nunreasonable to persuade owners of them to drop index -- then we\ncould use absence of $GIT_DIR/index as a strong clue that the\nrepository is bare.\n"}]}