{"thread":{"id":"4211","subject":"[PATCH 5/5] Enable ref log creation in git checkout -b.","startedAt":"2006-05-19T09:17:16Z","lastAt":"2006-05-24T23:36:46Z","messageCount":7,"participants":["Shawn Pearce","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"20285","messageId":"20060519091716.GM22257@spearce.org","threadId":"4211","inReplyTo":null,"subject":"[PATCH 5/5] Enable ref log creation in git checkout -b.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-05-19T09:17:16Z","receivedAt":"2006-05-19T09:17:16Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Switch git checkout -b to use git-update-ref rather than echo and\na shell I/O redirection.  This is more in line with typical GIT\ncommands and allows -b to be logged according to the normal ref\nlogging rules.\n\nAdded -l option to allow users to create the ref log at the same\ntime as creating a branch.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n\n---\n\n Documentation/git-checkout.txt |    7 ++++++-\n git-checkout.sh                |   19 +++++++++++++++----\n 2 files changed, 21 insertions(+), 5 deletions(-)\n\n46409624159100ad958c3168b13e384168c12713\ndiff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt\nindex 0951289..0643943 100644\n--- a/Documentation/git-checkout.txt\n+++ b/Documentation/git-checkout.txt\n@@ -8,7 +8,7 @@ git-checkout - Checkout and switch to a \n SYNOPSIS\n --------\n [verse]\n-'git-checkout' [-f] [-b <new_branch>] [-m] [<branch>]\n+'git-checkout' [-f] [-b <new_branch> [-l]] [-m] [<branch>]\n 'git-checkout' [-m] [<branch>] <paths>...\n \n DESCRIPTION\n@@ -37,6 +37,11 @@ OPTIONS\n -b::\n \tCreate a new branch and start it at <branch>.\n \n+-l::\n+\tCreate the new branch's ref log.  This activates recording of\n+\tall changes to made the branch ref, enabling use of date\n+\tbased sha1 expressions such as \"<branchname>@{yesterday}\".\n+\n -m::\n \tIf you have local modifications to one or more files that\n \tare different between the current branch and the branch to\ndiff --git a/git-checkout.sh b/git-checkout.sh\nindex a11c939..360aabf 100755\n--- a/git-checkout.sh\n+++ b/git-checkout.sh\n@@ -5,10 +5,13 @@ SUBDIRECTORY_OK=Sometimes\n . git-sh-setup\n \n old=$(git-rev-parse HEAD)\n+old_name=HEAD\n new=\n+new_name=\n force=\n branch=\n newbranch=\n+newbranch_log=\n merge=\n while [ \"$#\" != \"0\" ]; do\n     arg=\"$1\"\n@@ -24,6 +27,9 @@ while [ \"$#\" != \"0\" ]; do\n \t\tgit-check-ref-format \"heads/$newbranch\" ||\n \t\t\tdie \"git checkout: we do not like '$newbranch' as a branch name.\"\n \t\t;;\n+\t\"-l\")\n+\t\tnewbranch_log=1\n+\t\t;;\n \t\"-f\")\n \t\tforce=1\n \t\t;;\n@@ -44,6 +50,7 @@ while [ \"$#\" != \"0\" ]; do\n \t\t\t\texit 1\n \t\t\tfi\n \t\t\tnew=\"$rev\"\n+\t\t\tnew_name=\"$arg^0\"\n \t\t\tif [ -f \"$GIT_DIR/refs/heads/$arg\" ]; then\n \t\t\t\tbranch=\"$arg\"\n \t\t\tfi\n@@ -51,9 +58,11 @@ while [ \"$#\" != \"0\" ]; do\n \t\tthen\n \t\t\t# checking out selected paths from a tree-ish.\n \t\t\tnew=\"$rev\"\n+\t\t\tnew_name=\"$arg^{tree}\"\n \t\t\tbranch=\n \t\telse\n \t\t\tnew=\n+\t\t\tnew_name=\n \t\t\tbranch=\n \t\t\tset x \"$arg\" \"$@\"\n \t\t\tshift\n@@ -114,7 +123,7 @@ then\n \tcd \"$cdup\"\n fi\n \n-[ -z \"$new\" ] && new=$old\n+[ -z \"$new\" ] && new=$old && new_name=\"$old_name\"\n \n # If we don't have an old branch that we're switching to,\n # and we don't have a new branch name for the target we\n@@ -187,9 +196,11 @@ # be based on them, since we re-set the \n #\n if [ \"$?\" -eq 0 ]; then\n \tif [ \"$newbranch\" ]; then\n-\t\tleading=`expr \"refs/heads/$newbranch\" : '\\(.*\\)/'` &&\n-\t\tmkdir -p \"$GIT_DIR/$leading\" &&\n-\t\techo $new >\"$GIT_DIR/refs/heads/$newbranch\" || exit\n+\t\tif [ \"$newbranch_log\" ]; then\n+\t\t\tmkdir -p $(dirname \"$GIT_DIR/logs/refs/heads/$branchname\")\n+\t\t\ttouch \"$GIT_DIR/logs/refs/heads/$branchname\"\n+\t\tfi\n+\t\tgit-update-ref -m \"checkout: Created from $new_name\" \"refs/heads/$newbranch\" $new || exit\n \t\tbranch=\"$newbranch\"\n \tfi\n \t[ \"$branch\" ] &&\n-- \n1.3.2.g7278\n"},{"id":"20390","messageId":"7vk68fyarn.fsf@assigned-by-dhcp.cox.net","threadId":"4211","inReplyTo":"20060519091716.GM22257@spearce.org","subject":"Re: [PATCH 5/5] Enable ref log creation in git checkout -b.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-21T09:42:20Z","receivedAt":"2006-05-21T09:42:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I've swallowed all 10 and pushed them out in \"pu\", but could you\nadd tests to check the Porcelainish commands you touched with\nthis series to make sure they all log correctly?\n\nBTW, I noticed that a patch earlier in the series depended on\nsomething not in \"master\" (it's rfc2822_date from js/fmt-patch\nseries).  Generally I do not want to make a branch hostage of\nanother branch by introducing a dependency, but for now I'll\npull in early part of js/fmt-patch branch into sp/reflog branch\nand see what happens.\n\nIf sp/reflog branch graduates to the \"master\" first, it will\npull early parts of js/fmt-patch along with it, but the built-in\nwill be called \"git fmt-patch\" in the result, so it wouldn't\naffect the use of \"git format-patch\".\n"},{"id":"20605","messageId":"20060524035234.GA13329@spearce.org","threadId":"4211","inReplyTo":"7vk68fyarn.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 5/5] Enable ref log creation in git checkout -b.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-05-24T03:52:34Z","receivedAt":"2006-05-24T03:52:34Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> I've swallowed all 10 and pushed them out in \"pu\", but could you\n> add tests to check the Porcelainish commands you touched with\n> this series to make sure they all log correctly?\n\nSure.  I've been putting it off as I've been busy the past few days\nand have also been thinking about trying to rebuild reflog using a\ntag/annotation branch style, which might be more generally useful\nto others.  So I've been debating about whether or not I should\nask you to pop reflog out of pu indefinately.\n\n> BTW, I noticed that a patch earlier in the series depended on\n> something not in \"master\" (it's rfc2822_date from js/fmt-patch\n> series).  Generally I do not want to make a branch hostage of\n> another branch by introducing a dependency, but for now I'll\n> pull in early part of js/fmt-patch branch into sp/reflog branch\n> and see what happens.\n\nDoh.  Sorry about that one.  I saw it in date.c and used it, not\nrealizing it was only in pu.\n \n-- \nShawn.\n"},{"id":"20606","messageId":"7vsln0qbz7.fsf@assigned-by-dhcp.cox.net","threadId":"4211","inReplyTo":"20060524035234.GA13329@spearce.org","subject":"Re: [PATCH 5/5] Enable ref log creation in git checkout -b.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-24T04:32:28Z","receivedAt":"2006-05-24T04:32:28Z","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> Sure.  I've been putting it off as I've been busy the past few days\n> and have also been thinking about trying to rebuild reflog using a\n> tag/annotation branch style, which might be more generally useful\n> to others.  So I've been debating about whether or not I should\n> ask you to pop reflog out of pu indefinately.\n\nHeh, too late for that -- it looked OK so now they are part of\n\"next\" to get wider exposure.\n"},{"id":"20651","messageId":"7vy7wr3tc3.fsf@assigned-by-dhcp.cox.net","threadId":"4211","inReplyTo":"20060524035234.GA13329@spearce.org","subject":"Re: [PATCH 5/5] Enable ref log creation in git checkout -b.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-24T23:18:20Z","receivedAt":"2006-05-24T23:18:20Z","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> Junio C Hamano <junkio@cox.net> wrote:\n>> I've swallowed all 10 and pushed them out in \"pu\", but could you\n>> add tests to check the Porcelainish commands you touched with\n>> this series to make sure they all log correctly?\n>\n> Sure.  I've been putting it off as I've been busy the past few days\n> and have also been thinking about trying to rebuild reflog using a\n> tag/annotation branch style, which might be more generally useful\n> to others.\n\nIt appears that there is more serious breakage caused by the\nlock_ref change.  http-fetch in \"next\" fails to clone, because\nthe call to lock-ref-sha1 in fetch.c::pull() forgets that the\nprogram might be creating a new ref.\n\nAnother breakage I found (not related to ref-log) is that it\nappears fetch.c, even in \"master\" branch [*1*], has current_ref\nvariable and does things depending on it, but nobody seems to\nset that variable, so there are a lot of dead code that looks as\nif they are doing something useful, enclosed in sections like:\n\n\tif (somethingelse && current_ref) {\n        \tdead code\n\t}\n\nI'll probably revert the ref-log series from \"next\" in the next\nround of updates, while killing the current_ref variable from\n\"master\".\n\n\n[Footnotes]\n\n*1* It actually is worse than that.  Commit cd541a6 introduced\nthis variable but nobody touches it ever in the development\nhistory of that variable.  I wonder what the original author and\nthe maintainer were smoking back then...\n"},{"id":"20652","messageId":"20060524232506.GB3554@spearce.org","threadId":"4211","inReplyTo":"7vy7wr3tc3.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 5/5] Enable ref log creation in git checkout -b.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-05-24T23:25:06Z","receivedAt":"2006-05-24T23:25:06Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Shawn Pearce <spearce@spearce.org> writes:\n> \n> > Junio C Hamano <junkio@cox.net> wrote:\n> >> I've swallowed all 10 and pushed them out in \"pu\", but could you\n> >> add tests to check the Porcelainish commands you touched with\n> >> this series to make sure they all log correctly?\n> >\n> > Sure.  I've been putting it off as I've been busy the past few days\n> > and have also been thinking about trying to rebuild reflog using a\n> > tag/annotation branch style, which might be more generally useful\n> > to others.\n> \n> It appears that there is more serious breakage caused by the\n> lock_ref change.  http-fetch in \"next\" fails to clone, because\n> the call to lock-ref-sha1 in fetch.c::pull() forgets that the\n> program might be creating a new ref.\n\nHmm.  I thought I was doing the same thing fetch used to do which\nappeared to only work on refs which already exist, and not creating\nnew refs...\n \n> Another breakage I found (not related to ref-log) is that it\n> appears fetch.c, even in \"master\" branch [*1*], has current_ref\n> variable and does things depending on it, but nobody seems to\n> set that variable, so there are a lot of dead code that looks as\n> if they are doing something useful, enclosed in sections like:\n> \n> \tif (somethingelse && current_ref) {\n>         \tdead code\n> \t}\n \nI wondered about that code...\n\n-- \nShawn.\n"},{"id":"20654","messageId":"20060524233646.GC3554@spearce.org","threadId":"4211","inReplyTo":"7vy7wr3tc3.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 5/5] Enable ref log creation in git checkout -b.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-05-24T23:36:46Z","receivedAt":"2006-05-24T23:36:46Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Shawn Pearce <spearce@spearce.org> writes:\n> \n> > Junio C Hamano <junkio@cox.net> wrote:\n> >> I've swallowed all 10 and pushed them out in \"pu\", but could you\n> >> add tests to check the Porcelainish commands you touched with\n> >> this series to make sure they all log correctly?\n> >\n> > Sure.  I've been putting it off as I've been busy the past few days\n> > and have also been thinking about trying to rebuild reflog using a\n> > tag/annotation branch style, which might be more generally useful\n> > to others.\n> \n> It appears that there is more serious breakage caused by the\n> lock_ref change.  http-fetch in \"next\" fails to clone, because\n> the call to lock-ref-sha1 in fetch.c::pull() forgets that the\n> program might be creating a new ref.\n\nThe breakage is because of current_ref always being null.  The old\ncode would allow locking a non-existant ref in this case while the\nnew code was failing.  A simple change such as the following should\nfix it:\n\n-->8--\nFix fetch when using reflog.\n\nPreviously fetch was permitted to create refs if they did not exist;\nthis only worked as current_ref was always NULL and thus never\nwould get compared against the existing ref.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n\n---\n\n2dad4178db978c01257fde949d808361589ee003\n fetch.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\n2dad4178db978c01257fde949d808361589ee003\ndiff --git a/fetch.c b/fetch.c\nindex fd57684..15110b8 100644\n--- a/fetch.c\n+++ b/fetch.c\n@@ -213,7 +213,7 @@ int pull(char *target)\n \tsave_commit_buffer = 0;\n \ttrack_object_refs = 0;\n \tif (write_ref) {\n-\t\tlock = lock_ref_sha1(write_ref, current_ref, 1);\n+\t\tlock = lock_ref_sha1(write_ref, current_ref, 0);\n \t\tif (!lock) {\n \t\t\terror(\"Can't lock ref %s\", write_ref);\n \t\t\treturn -1;\n-- \n1.3.3.gfad60\n"}]}