{"thread":{"id":"3148","subject":"[RFD] remembering hand resolve...","startedAt":"2006-01-25T13:00:45Z","lastAt":"2006-01-29T09:10:52Z","messageCount":14,"participants":["Junio C Hamano","Andreas Ericsson","Mathieu Chouquet-Stringer","Josef Weidendorfer","J. Bruce Fields"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"15115","messageId":"7v4q3ssbr6.fsf@assigned-by-dhcp.cox.net","threadId":"3148","inReplyTo":null,"subject":"[RFD] remembering hand resolve...","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-25T13:00:45Z","receivedAt":"2006-01-25T13:00:45Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As people on the list may know, I keep many mini topic-branches\nand keep combining them on top of then-current master to publish\n\"pu\".  This involves resolving merge conflicts by hand, when the\nareas topic-branches touch overlap.\n\nThe thing is, I find myself resolving the same conflicts over\nand over.  This is because the master branch tends to advance\nfaster than topic branches that touch an overlapping area.  I'd\ntake more time than I usually do to decide what to do with them;\nas a result, overlapping topic branches tend to stay unmerged\ninto \"master\" longer than other topic branches.\n\nIf I linearize topic-branches that conflict with each other in\nsome way, say base topic B on top of topic A, I would not have\nproblem merging them into \"pu\" as long as I do not change my\nmind later and try to merge only topic B without topic A.  But\nthat defeats the whole point of having independent topic\nbranches.\n\nI would imagine that people who use StGIT or quilt would have\nsimilar issues.  If they are in the same series, then inside of\nthat queue the patches are already ordered to be in some way,\nprobably conflict is resolved once when the patch is refreshed\nand they stay applicable as long as the base part cleanly\napplies to the updated base version, but patches in the queue\nthen depend on the earlier ones in the same series, and\nextracting and applying only the later parts of the queue would\nneed you to manually un-resolve the conflict you earlier\nresolved.  If you keep different topics in separate queues, on\nthe other hand, I would imagine you would have exactly the same\n\"oh, I know this and that patch conflict with each other and I\nrecall I resolved that last time I merged everything up\" issue.\n\nHow do people on patch-queue based systems like StGIT and quilt\ndeal with this?  I am wondering if somebody have a clever idea\nto record and reuse an earlier conflict resolution.\n\nA trivial solution would be to save the diff between conflicted\nautomerge result before hand resolving, and the result of my\nhand resolve, and apply with \"patch\" when I see a conflicted\nautomerge the next time.  I've tried this by hand and it worked\nquite well tonight, but I felt it was somewhat kludgy.  We\nshould be able to do better than that, with some tool support.\n\nAnother obvious way is to avoid rebuilding \"pu\"; instead I could\npull \"master\" into \"pu\" every time I have added something new to\n\"master\".  That would work most of the time, until I decide to\nchange the order the topic branches are merged into \"pu\" (or\ndrop one of them).\n"},{"id":"15117","messageId":"43D7810D.9010508@op5.se","threadId":"3148","inReplyTo":"7v4q3ssbr6.fsf@assigned-by-dhcp.cox.net","subject":"Re: [RFD] remembering hand resolve...","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2006-01-25T13:45:49Z","receivedAt":"2006-01-25T13:45:49Z","isPatch":false,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> As people on the list may know, I keep many mini topic-branches\n> and keep combining them on top of then-current master to publish\n> \"pu\".  This involves resolving merge conflicts by hand, when the\n> areas topic-branches touch overlap.\n> \n> The thing is, I find myself resolving the same conflicts over\n> and over.  This is because the master branch tends to advance\n> faster than topic branches that touch an overlapping area.\n\n\nHow can that be possible? If the area of code in master is modified \nbeyond simple merging from the topic-branches, the resulting diff (which \nhas to be against master's HEAD) should apply cleanly so long as there \naren't *new* changes to master, in which case the pu commit needs \nadaptation again, so it wouldn't really be the same conflict (or even \nnecessarily a similar one), would it?\n\n\n> If I linearize topic-branches that conflict with each other in\n> some way, say base topic B on top of topic A, I would not have\n> problem merging them into \"pu\" as long as I do not change my\n> mind later and try to merge only topic B without topic A.  But\n> that defeats the whole point of having independent topic\n> branches.\n> \n\nWouldn't cherry-pick be useful here? If it isn't, I fail to understand \nhow a merge can solve it for you. Admittedly, I know little of the inner \nworkings of git.\n\n> \n> A trivial solution would be to save the diff between conflicted\n> automerge result before hand resolving, and the result of my\n> hand resolve, and apply with \"patch\" when I see a conflicted\n> automerge the next time.  I've tried this by hand and it worked\n> quite well tonight, but I felt it was somewhat kludgy.  We\n> should be able to do better than that, with some tool support.\n> \n\n> Another obvious way is to avoid rebuilding \"pu\"; instead I could\n> pull \"master\" into \"pu\" every time I have added something new to\n> \"master\".  That would work most of the time, until I decide to\n> change the order the topic branches are merged into \"pu\" (or\n> drop one of them).\n> \n\nCouldn't you do something like this:\n\nfor t in $topic_branches; do\n\tcheckout $t\n\tgit rebase master\ndone\ngit checkout master\ngit branch -D pu\ngit checkout -b pu\ngit pull . $topic_branches\n\nThat's what I thought you were doing right now, but I can't imagine that \nflow leading to the same conflicts over and over, so I must be mistaken \nsomehow.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"15128","messageId":"7v1wyvn9pc.fsf@assigned-by-dhcp.cox.net","threadId":"3148","inReplyTo":"43D7810D.9010508@op5.se","subject":"Re: [RFD] remembering hand resolve...","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-25T23:56:15Z","receivedAt":"2006-01-25T23:56:15Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Ericsson <ae@op5.se> writes:\n\n> Junio C Hamano wrote:\n>> The thing is, I find myself resolving the same conflicts over\n>> and over.  This is because the master branch tends to advance\n>> faster than topic branches that touch an overlapping area.\n>\n> How can that be possible? If the area of code in master is modified\n> beyond simple merging from the topic-branches, the resulting diff\n> (which has to be against master's HEAD) should apply cleanly so long\n> as there aren't *new* changes to master, in which case the pu commit\n> needs adaptation again, so it wouldn't really be the same conflict (or\n> even necessarily a similar one), would it?\n\nIn general, you are right.  When the change that advances\n\"master\" touches the same area as those held-back topic branches\ntouch, the earlier resolution between topic branches may not help.\n\nHowever, the change to the \"master\" that leap-frogs these\nheld-back topic branches is often independent from the changes\nin these held-back topic branches.\n\nFor example, as of this morning, my \"master\" and \"pu\" were like\nthis:\n\n        $ git show-branch master pu\n        * [master] Merge branches 'jc/clone', 'md/env' and 'mo/path'\n         ! [pu] Merge jc/revparse,jc/abbrev\n        --\n         - [pu] Merge jc/revparse,jc/abbrev\n         - [pu^] Merge lt/revlist,jc/diff,jc/bind\n         + [pu^^3] combine-diff: fix appending at the tail of a list.\n         + [pu^2] rev-parse --flags/--no-flags usability fix.\n         + [pu^3] diff-tree: abbreviate merge parent object names wit...\n         + [pu^^2] rev-list: stop when the file disappears\n         + [pu^^3^] diff-tree --cc: denser combined diff output for a...\n         + [pu^^3~2] diff-tree -c: show a merge commit a bit more sen...\n         + [pu^^4] fsck-objects, convert-objects: understand bound co...\n         + [pu^^4^] rev-list: understand bound commits.\n         + [pu^^4~2] rev-list: simplify --object list generation.\n         + [pu^^4~3] commit-tree: --bind <sha1> <path>/ option.\n         + [pu^^4~4] write-tree: --prefix=<path>/ and --exclude=<pref...\n         + [pu^^4~5] read-tree: --prefix=<path>/ option.\n         + [pu^3^] rev-parse: --abbrev option.\n         + [pu^3~2] abbrev cleanup: use symbolic constants\n        -- [master] Merge branches 'jc/clone', 'md/env' and 'mo/path'\n\nThe two merges at the tip of \"pu\" shows that I merged lt/revlist\n(Linus' \"stop at disappearance\"), jc/diff (\"combined diff\") and\njc/bind (\"bound commit') first because I felt they are more or\nless ready, and then jc/revparse and jc/abbrev on top of it.\n\nTwo topic branches, jc/abbrev and jc/bind, touch the same area\nin commit.c.  The former changes the formatting of \"Merge:\" line\nfrom prettyprinted commit (we did not honor --abbrev option to\ndiff-tree when we used that function).  The latter changes the\nsame function to include a call to add the new \"Bind: \" lines.\nWhen I made the last merge for the tip of \"pu\", I had to hand\nresolve conflicts in the file.\n\nNow suppose I feel topic branches lt/revlist, jc/diff and\njc/revparse are ready, and want to have them graduate to the\n\"master\" branch.  Also I may get a patch from you fixing\nDocumentation/Makefile, which none of my topic branches touch,\nso I would advance \"master\" this way:\n\n\t$ git checkout master\n        $ git pull . lt/revlist\n        $ git pull . jc/diff\n        $ git pull . jc/revparse\n\t$ git am -3 -s ./+ae-doc-make.email\n\nWhat I would do after this step to rebuild \"pu\" would be to\nmerge jc/bind and jc/abbrev branches, in some order.  But in\nwhatever order I merge, I would get the conflict in commit.c\nas before:\n\n\t$ git checkout pu\n        $ git reset --hard master\n        $ git pull . jc/bind\n        $ git pull . jc/abbrev\n\nIf I swap the order I pull in jc/bind and jc/abbrev, the\nsections marked with conflict markers <<< === >>> would be\nswapped, so the conflict would not be exactly the same, but\nthe result of the resolution is the same.  I end up making the\nresult logically the same by hand resolving.\n\nAlthough I happen to do Octopus when building \"pu\" but the issue\ndoes not change if the merges were made one branch at a time.\n\n>> If I linearize topic-branches that conflict with each other in\n>> some way, say base topic B on top of topic A, I would not have\n>> problem merging them into \"pu\" as long as I do not change my\n>> mind later and try to merge only topic B without topic A.  But\n>> that defeats the whole point of having independent topic\n>> branches.\n>\n> Wouldn't cherry-pick be useful here? If it isn't, I fail to understand\n> how a merge can solve it for you....\n\nSuppose instead of having\n\n              A---B---C jc/bind\n             /    \n  master ---O\n             \\    \n              D---E---F jc/abbrev\n\nI made this:\n\n              A'--B'--C'--D---E---F\n             /        ^jc/bind    ^jc/abbrev\n  master ---O\n\nWhen converting the two topic branches into this sequence,\nobviously I have to hand merge the changes A-B-C makes and the\nchanges D-E-F makes to commit.c file.\n\nI can later attempt to cherry-pick D-E-F on top of updated\n\"master\".  I think that is what you mean by \"cherry-picking\",\nbut that would have the same \"I've resolved this before\" issue.\nBecause the change D-E-F brings in now depends on the change\nA'-B'-C' brings in. But on the tip of the master branch, that\nchange is not there yet. The cherry-picked changes on top of O\nwould not cleanly apply.  Even with the 3-way merge fallback,\nthis is a merge of F and O using C' as the merge base, and we\nwill see conflicts.\n\nHowever, as long as I do not have to merge the contents of\njc/abbrev branch in without the contents of jc/bind branch, a\nmerge to an updated master would not have any conflict between\nA'-B'-C' chain and D-E-F chain, and often even after jc/bind and\njc/abbrev advances:\n\n                        G---H jc/bind\n                       /\n              A'--B'--C'--D---E---F\n             /                    ^jc/abbrev\n  master ---O---I---J\n\nPulling jc/bind to master and then jc/abbrev on top it may have\nconflicts between the changes O-I-J and C'-G-H bring in, but at\nleast I would not have to re-resolve the conflicts between\nA'-B'-C' and D-E-F chains.  That is what I meant to say.  The\nmerge is helped by making jc/abbrev topic branch dependent on\nthe earlier part of jc/bind topic branch.\n\n> Couldn't you do something like this:\n>\n> for t in $topic_branches; do\n> \tcheckout $t\n> \tgit rebase master\n> done\n> git checkout master\n> git branch -D pu\n> git checkout -b pu\n> git pull . $topic_branches\n>\n> That's what I thought you were doing right now, but I can't imagine\n> that flow leading to the same conflicts over and over, so I must be\n> mistaken somehow.\n\nThat is exactly what I am doing [*1*]\n\n\n[Footnote]\n\n*1* In my primary development working tree, I have a checked-out\ntree of \"todo\" branch at Meta/ directory.  The \"pu\" is built by\nrunning Meta/PU (that is \"PU\" file in the \"todo\" branch) from\nthe toplevel and picking topic branches to merge on top of the\nmaster branch, which essentially does what you just described.\n\nTo take a peek at how my primary development working tree looks\nlike, you could do this:\n\n\t$ git clone git://git.kernel.org/pub/scm/git/git GIT\n        $ cd GIT\n        $ git clone -l -s -n .git Meta\n        $ cd Meta\n        $ git checkout todo\n        $ cd ..\n\t$ rm Meta/.git/refs/heads/[a-p]* ;# leave only \"todo\"\n        $ rm -f .git/refs/heads/{html,man,todo}\n\nThis would give a rough approximation of where I work.\n\nThe above clone would not have any of the topic branches; but\ntheir heads appear on merge commits between master and pu.  For\nexample, in the earlier show-branch output, the tip of \"pu\" says\n\"Merge jc/revparse,jc/abbrev\", which means pu^1 was the tip of\npu when this merge was made, pu^2 is the tip of jc/revparse\ntopic, and pu^3 is jc/abbrev.  You can take them apart like so:\n\n\t$ git branch jc/revparse pu^2\n\t$ git branch jc/abbrev pu^3\n"},{"id":"15142","messageId":"m37j8n9rat.fsf_-_@localhost.localdomain","threadId":"3148","inReplyTo":"7v1wyvn9pc.fsf@assigned-by-dhcp.cox.net","subject":"How to create and keep up to date a naked/bare repository?","fromName":"Mathieu Chouquet-Stringer","fromEmail":"ml2news@free.fr","sentAt":"2006-01-26T11:12:10Z","receivedAt":"2006-01-26T11:12:10Z","isPatch":false,"sender":{"key":"ml2news@free.fr","avatar":null},"body":"        Hello,\n\nI've got a couple of questions and reading (some of the files in) the\nDocumentation directory didn't really enlighten me...\n\nLet's say I want to maintain a private (read-only) copy of a git repository\n(eg git.git or linus-2.6.git). Because this repository is shared\ninternally (used by a bunch of boxes), I'd like to clone it as a bare\nrepo, no need to have the files checked out on my local master.\n\nCloning is done by running the following:\ngit clone --naked git://www.kernel.org/pub/scm/git/git.git git.git\n\nNow I've got my repository. Because I'll share it with git-daemon, I touch\nthe git-daemon-export-ok file to export it.\n\nThe first problem arises when I try to keep this repo up to date.\n\nIf I try a git fetch or pull (more on that later), git complains because it\ncan't find a .git directory (which is correct as in a bare repository the\nrepository directory is the .git directory).\n\nI can do a: GIT_DIR=. git fetch and it works but that's kind of ugly. I\ncan also link . to .git but it's as disgusting as the previous hack.\n\nMaybe I'm missing something obvious here, is there an option to tell\nfetch/pull that it's working with a bare repository?\n\nThe second question is I'd think I would have to use git fetch instead of\ngit pull as a pull is fetch + merge and merging wouldn't make much sense as\nI didn't check out any files. Does it make any sense?\n\nThe third thing (can't reproduce ATM as I just got a fresh new clone) is\nthat git fetch was just fetching over and over the same objects...\n\nCan anyone tell me what I'm doing wrong?\n\n-- \nMathieu Chouquet-Stringer\n    \"Le disparu, si l'on vénère sa mémoire, est plus présent et\n                 plus puissant que le vivant\".\n           -- Antoine de Saint-Exupéry, Citadelle --\n"},{"id":"15148","messageId":"7v64o7fac1.fsf@assigned-by-dhcp.cox.net","threadId":"3148","inReplyTo":"m37j8n9rat.fsf_-_@localhost.localdomain","subject":"Re: How to create and keep up to date a naked/bare repository?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-26T12:22:06Z","receivedAt":"2006-01-26T12:22:06Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mathieu Chouquet-Stringer <ml2news@free.fr> writes:\n\n> I can do a: GIT_DIR=. git fetch and it works.\n\nThat is the right way of doing it.\n\n> The second question is I'd think I would have to use git fetch instead of\n> git pull as a pull is fetch + merge and merging wouldn't make much sense as\n> I didn't check out any files. Does it make any sense?\n\nAbsolutely.  Bare repositories are either to be pushed into or\nfetched into.\n\n> The third thing (can't reproduce ATM as I just got a fresh new clone) is\n> that git fetch was just fetching over and over the same objects...\n\nIt sounds like you are not telling fetch to update the refs you\ntrack from outside.  Perhaps, this may help (untested):\n\n\t$ GIT_DIR=/pub/scm/git/git.git git fetch \\\n        \t--update-head-ok $remote master:master\n"},{"id":"15152","messageId":"m3vew781na.fsf@localhost.localdomain","threadId":"3148","inReplyTo":"7v64o7fac1.fsf@assigned-by-dhcp.cox.net","subject":"Re: How to create and keep up to date a naked/bare repository?","fromName":"Mathieu Chouquet-Stringer","fromEmail":"ml2news@free.fr","sentAt":"2006-01-26T15:11:37Z","receivedAt":"2006-01-26T15:11:37Z","isPatch":false,"sender":{"key":"ml2news@free.fr","avatar":null},"body":"junkio@cox.net (Junio C Hamano) writes:\n> Mathieu Chouquet-Stringer <ml2news@free.fr> writes:\n> > I can do a: GIT_DIR=. git fetch and it works.\n> \n> That is the right way of doing it.\n\nOk.\n \n> > The second question is I'd think I would have to use git fetch instead of\n> > git pull as a pull is fetch + merge and merging wouldn't make much sense as\n> > I didn't check out any files. Does it make any sense?\n> \n> Absolutely.  Bare repositories are either to be pushed into or\n> fetched into.\n\nGreat I ain't totally lost then!\n \n> > The third thing (can't reproduce ATM as I just got a fresh new clone) is\n> > that git fetch was just fetching over and over the same objects...\n> \n> It sounds like you are not telling fetch to update the refs you\n> track from outside.  Perhaps, this may help (untested):\n> \n> \t$ GIT_DIR=/pub/scm/git/git.git git fetch \\\n>         \t--update-head-ok $remote master:master\n\nI'll try that and will let you know...\n\nThanks Junio for getting back to me.\n-- \nMathieu Chouquet-Stringer\n    \"Le disparu, si l'on vénère sa mémoire, est plus présent et\n                 plus puissant que le vivant\".\n           -- Antoine de Saint-Exupéry, Citadelle --\n"},{"id":"15156","messageId":"m34q3q9759.fsf@localhost.localdomain","threadId":"3148","inReplyTo":"7v64o7fac1.fsf@assigned-by-dhcp.cox.net","subject":"Re: How to create and keep up to date a naked/bare repository?","fromName":"Mathieu Chouquet-Stringer","fromEmail":"ml2news@free.fr","sentAt":"2006-01-26T18:27:30Z","receivedAt":"2006-01-26T18:27:30Z","isPatch":false,"sender":{"key":"ml2news@free.fr","avatar":null},"body":"junkio@cox.net (Junio C Hamano) writes:\n> It sounds like you are not telling fetch to update the refs you\n> track from outside.  Perhaps, this may help (untested):\n> \n> \t$ GIT_DIR=/pub/scm/git/git.git git fetch \\\n>         \t--update-head-ok $remote master:master\n\nI guess I'm a little bit confused here as I'm not quite sure what I'm\ntrying to accomplish...\n\nHere's what I ran:\n% GIT_DIR=. git fetch \\\n--update-head-ok git://www.kernel.org/pub/scm/git/git master:master\n\nIsn't git supposed to fetch master:origin as my remotes/origin file\ncontains (I actually tried both and refs/heads/origin and refs/heads/master\nhave the same value):\n\nURL: git://www.kernel.org/pub/scm/git/git.git\nPull: master:origin\nPull: todo:todo\nPull: html:html\nPull: maint:maint\nPull: man:man\nPull: pu:pu\n\nSo it knows about the repository and the ref spec so all I need would be\nthe --update-head-ok flag then, no?\n\n-- \nMathieu Chouquet-Stringer\n    \"Le disparu, si l'on vénère sa mémoire, est plus présent et\n                 plus puissant que le vivant\".\n           -- Antoine de Saint-Exupéry, Citadelle --\n"},{"id":"15158","messageId":"7vd5ie735a.fsf@assigned-by-dhcp.cox.net","threadId":"3148","inReplyTo":"m34q3q9759.fsf@localhost.localdomain","subject":"Re: How to create and keep up to date a naked/bare repository?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-27T03:36:49Z","receivedAt":"2006-01-27T03:36:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mathieu Chouquet-Stringer <ml2news@free.fr> writes:\n\n> junkio@cox.net (Junio C Hamano) writes:\n>> It sounds like you are not telling fetch to update the refs you\n>> track from outside.  Perhaps, this may help (untested):\n>> \n>> \t$ GIT_DIR=/pub/scm/git/git.git git fetch \\\n>>         \t--update-head-ok $remote master:master\n>\n> I guess I'm a little bit confused here as I'm not quite sure what I'm\n> trying to accomplish...\n>\n> Here's what I ran:\n> % GIT_DIR=. git fetch \\\n> --update-head-ok git://www.kernel.org/pub/scm/git/git master:master\n>\n> Isn't git supposed to fetch master:origin as my remotes/origin file\n> contains (I actually tried both and refs/heads/origin and refs/heads/master\n> have the same value):\n>\n> URL: git://www.kernel.org/pub/scm/git/git.git\n> Pull: master:origin\n> Pull: todo:todo\n> Pull: html:html\n> Pull: maint:maint\n> Pull: man:man\n> Pull: pu:pu\n>\n> So it knows about the repository and the ref spec so all I need would be\n> the --update-head-ok flag then, no?\n\nTrue.\n\nThe latest git-clone.sh stopped creating both refs/heads/origin\nand remotes/origin.  The former was to prevent common mistake\nwhen using it as a shared repository, but removal of the latter\nmight have been a mistake.  I dunno.\n\n\nLet's step back a bit and think about the modes of usage for a\nbare cloned repository.\n\n - A central distribution point for a (sub)project.\n\n   This is the original mode of operation bare repositories were\n   to be used.  Think of bare repositories on kernel.org public\n   machines.  Subsystem maintainers never work in them; the\n   maintainers push into them from their private development\n   trees.  Most importantly, fetching into them is not usually\n   done.  Fetching from upstream or sibling is done first into\n   maintainers' private development trees, and then either\n   vanilla upstream tip and/or merge result with it are pushed\n   into this bare repository.\n\n - A shared repository, CVS style.\n\n   This is a natural extension of the above, but instead of\n   having one person (the owner of the central distribution\n   point for the subproject, aka subsystem maintainer), members\n   of a group push into it.  Other aspects of the repository are\n   not different from the above.  For example, if the project\n   has an upstream, the changes from the upstream is fetched by\n   people into their own development tree, merged appropriately\n   and pushed back to the shared repository.\n\n - A mirror of somebody else's work.\n\n   I suspect this is what you are doing.  Instead of individual\n   developers pulling directly from upstream, you would want to\n   fetch and update the bare cloned repository and have your\n   developers fetch from it.\n\nThe first two forms are equivalent.  The first one is a special\ncase of having only one user of the shared repository.  The\nmirror usage can be combined with the shared repository style.\n\nLet's outline how.\n\nWhat I would suggest is to arrange things like this:\n\n   +-------------------------------------------+\n   | Your upstream repository                  |\n   | git://git.kernel.org/pub/scm/git/git.git/ |\n   +-------------------------------------------+ \n      |                                      ^\n      | (1)                                  | (5)\n      |                                      |\n      v                                      |\n   +-----------------+                     +----------------+\n   | Your central    |        (4)          | My development |\n   | bare repository |-------------------->| tree           |\n   +-----------------+                     +----------------+\n      |      ^\n      | (2)  | (3)\n      |      |\n      v      |\n   +------------------+\n   | Your developers' |+\n   | trees            ||+\n   +------------------+||\n     +-----------------+|\n      +-----------------+\n\n(1) is initially done with \"clone --bare\".  You have already\n    done this.  To let your developers fetch the upstream\n    without directly going to kernel.org/, you would need a\n    mirror, which means you would want to keep all branches from\n    the upstream that your developers might be interested in.\n\n    So I would suggest to have something like this in this\n    repository:\n\n        $ cat remotes/origin\n        URL: git://git.kernel.org/pub/scm/git/git.git/\n        Pull: master:mirror\n        Pull: maint:maint\n        Pull: +pu:pu\n        Pull: todo:todo\n        Pull: html:html\n        Pull: man:man\n\t$ mv refs/heads/origin refs/heads/mirror\n\n    You may not particularly interested in the last three, in\n    which case you can safely omit them.  Also note that I\n    renamed \"origin\" to \"mirror\" here.\n\n    I imagine that your developers would be making updates to\n    git, and wish to share the changes with outside world (the\n    repository is not strict a mirror in that sense), so you\n    would need your own branch or two.  Your \"master\" branch is\n    used for that.\n\n    Periodically, you could mirror me with:\n\n\t$ GIT_DIR=. git fetch\n\n    Which would update the branch heads listed on the RHS of\n    Pull: lines above.  Note that the branch HEAD points at is\n    refs/heads/master and is not listed on the RHS of Pull:\n    lines, so --update-ok is not needed.  My \"master\" will be\n    mirrored as \"mirror\" in this repository.\n\n(2) is created by \"git clone\" from your \"central bare repository\", and\n    maintained by subsequent \"git pull\".  I am not offhand certain\n    what remotes/origin file they would get by default, but I would\n    recommend having something like this in their trees:\n\n\t$ cat .git/remotes/origin\n        URL: git://your.host/your/git.git\n\tPush: master:master\n        Pull: master:public\n        Pull: mirror:mirror\n\tPull: +pu:pu\n\n    Again, you may not particularly interested in all my branches, so\n    I've omitted most from the above.  Your developers should never\n    touch branches that are used to keep track of outside branches in\n    their repositories (they are \"public\", \"mirror\" and \"pu\" in the\n    above example).  Have them work on their \"master\" branch.\n\n\t$ git pull\n\n    would fetch from the \"master\" of your central bare repository and\n    keep track of it as the \"public\" branch [*1*][*2], and merge the\n    result of other developers in your group into the \"master\" branch.\n    If you would want to see how well your work works with the latest\n    upstream:\n\n\t$ git branch -f test mirror\n    \t$ git checkout test\n        $ git pull . master\n\n    would create a \"test\" branch based on my tip of \"master\", and\n    merge your development histories into it.  Substitute \"mirror\"\n    with \"pu\" if you want to see how well your development works with\n    the tip of \"pu\" branch.\n\n(3) Your developers will make commits to their own \"master\" branch,\n    and when things are ready, push the branch back:\n\n\t$ git push origin\n\n    which would attempt to update \"master\" in your central bare\n    repository with developer's \"master\".  This will fail if the\n    developer is not up to date --- in which case another git\n    pull and a merge would be needed to incorporate other developer's\n    changes.\n\n(4) If you got fixes and enhancements for public consumption,\n    drop me a \"please pull from here\" note.  I'll pull your\n    changes into my development tree [*3*].\n\n(5) And I would push them out to the public repository.  The\n    next fetch from me by your central bare repository and then\n    your developer's pull from it would complete the full\n    circle.\n\n\nDoes this make sense now?\n\n\n[Footnotes]\n\n*1* The \"public\" branch represents what other developers in your\n    group have done.\n\n*2* At the same time, it would fetch \"mirror\", which is my\n    \"master\", and keep track of it as the \"mirror\" branch head,\n    and \"pu\", which is also my \"pu\", and stores it as \"pu\".\n\n    So if you are interested in what I've done in the past\n    couple of days, you could:\n\n\t$ git whatchanged --since=3.days pu ;# everything\n\t$ git whatchanged --since=3.days mirror ;# my \"master\"\n\n*3* This is one reason I did not recommend frequent merging from\n    \"mirror\" to \"master\" in workflow (2).  If you do not expect me to\n    pull from you, merging \"mirror\" into \"master\" to update the\n    development base might be easier to handle for your developers.\n"},{"id":"15165","messageId":"200601271130.50322.Josef.Weidendorfer@gmx.de","threadId":"3148","inReplyTo":"7vd5ie735a.fsf@assigned-by-dhcp.cox.net","subject":"Refs naming after clone (was: Re: How to create and keep up to date a naked/bare repository?)","fromName":"Josef Weidendorfer","fromEmail":"josef.weidendorfer@gmx.de","sentAt":"2006-01-27T10:30:50Z","receivedAt":"2006-01-27T10:30:50Z","isPatch":false,"sender":{"key":"josef.weidendorfer@gmx.de","avatar":null},"body":"Hi,\n\nOn Friday 27 January 2006 04:36, Junio wrote:\n> The latest git-clone.sh stopped creating both refs/heads/origin\n> and remotes/origin.  The former was to prevent common mistake\n> when using it as a shared repository, but removal of the latter\n> might have been a mistake.  I dunno.\n\nIMHO it is convenient if git-clone remembers the origin repository\nin any case.\n \n> Let's step back a bit and think about the modes of usage for a\n> bare cloned repository.\n\nIt would be nice to have a default which is working nice in all cases\n(not only bare ones as discussed here).\n\nIMHO the main problem with the current default (creating master and origin\nheads after cloning) is that two namespaces are mixed up:\n(1) local (possible development) heads\n(2) and heads tracking remote heads\n\nAny compatibility issues aside, wouldn't it be better to have another\nnamespace for (2), similar to the proposed ref namespaces for subprojects,\nlike refs/remote/<remote-shortcut>/heads/<remote-head> ?\nClone would create a head refs/remote/origin/heads/master to track the\nmaster of the origin remote repo.\n\nIn the case of a the mirror discussed here, you would default to\nquite cumbersome long head names:\nTracking master of git://git.kernel.org/pub/scm/git/git.git in\nthe central mirroring repository would be done on \"remote/origin/heads/master\",\nand tracking this mirror head in developer repos would give a head\nname \"remote/origin/remote/origin/heads/master\".\n\nStill, I think this is nice because everybody can see that above head\nis tracking a remote head which is tracking itself another remote\nhead. gitk could give remote tracking heads another color.\n\nNote that I talk only about the default setup, which of course can be\nchanged by changing .git/remotes/origin.\nEg. in the mirror case, you probably want local and remote namespace\nbeing the same, ie. .git/refs/heads/* -> .git/refs/remote/origin/heads/*\n\nPerhaps a command to rename head names, which automatically updates\npull/push lines of .git/remotes/ accordingly would be nice here.\nAlso a command to rename remote shortcuts (e.g. origin to gitmain),\nrenaming above proposed head names accordingly would be nice.\n\nJosef\n"},{"id":"15166","messageId":"m34q3p7q1n.fsf@localhost.localdomain","threadId":"3148","inReplyTo":"7vd5ie735a.fsf@assigned-by-dhcp.cox.net","subject":"Re: How to create and keep up to date a naked/bare repository?","fromName":"Mathieu Chouquet-Stringer","fromEmail":"ml2news@free.fr","sentAt":"2006-01-27T13:34:28Z","receivedAt":"2006-01-27T13:34:28Z","isPatch":false,"sender":{"key":"ml2news@free.fr","avatar":null},"body":"Thanks and sorry for making you write this long message...\n\njunkio@cox.net (Junio C Hamano) writes:\n> [...]\n>  - A mirror of somebody else's work.\n> \n>    I suspect this is what you are doing.  Instead of individual\n>    developers pulling directly from upstream, you would want to\n>    fetch and update the bare cloned repository and have your\n>    developers fetch from it.\n\nCorrect.\n \n> Let's outline how.\n> \n> What I would suggest is to arrange things like this:\n> \n>    +-------------------------------------------+\n>    | Your upstream repository                  |\n>    | git://git.kernel.org/pub/scm/git/git.git/ |\n>    +-------------------------------------------+ \n>       |                                      ^\n>       | (1)                                  | (5)\n>       |                                      |\n>       v                                      |\n>    +-----------------+                     +----------------+\n>    | Your central    |        (4)          | My development |\n>    | bare repository |-------------------->| tree           |\n>    +-----------------+                     +----------------+\n>       |      ^\n>       | (2)  | (3)\n>       |      |\n>       v      |\n>    +------------------+\n>    | Your developers' |+\n>    | trees            ||+\n>    +------------------+||\n>      +-----------------+|\n>       +-----------------+\n> [...]\n> Does this make sense now?\n\nIt totally does. I guess this email could end up in the Documentation\nfolder in some way!?\n\n-- \nMathieu Chouquet-Stringer\n    \"Le disparu, si l'on vénère sa mémoire, est plus présent et\n                 plus puissant que le vivant\".\n           -- Antoine de Saint-Exupéry, Citadelle --\n"},{"id":"15168","messageId":"7v3bj9344w.fsf@assigned-by-dhcp.cox.net","threadId":"3148","inReplyTo":"m34q3p7q1n.fsf@localhost.localdomain","subject":"Re: How to create and keep up to date a naked/bare repository?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-27T18:41:19Z","receivedAt":"2006-01-27T18:41:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mathieu Chouquet-Stringer <ml2news@free.fr> writes:\n\n> Thanks and sorry for making you write this long message...\n\nHey, I do not mind \"I appreciate\", but don't be sorry.  I\nactually enjoyed drawing the ASCII art.\n\n>...\n> It totally does. I guess this email could end up in the Documentation\n> folder in some way!?\n\nMaybe somebody so inclined could copyedit it, find an\nappropriate place for it somewhere in the tutorial.txt or\ncore-tutorial.txt and feed that back to me in a patch form.\nHint, hint,... ;-).\n"},{"id":"15169","messageId":"20060127190157.GF23949@fieldses.org","threadId":"3148","inReplyTo":"7v3bj9344w.fsf@assigned-by-dhcp.cox.net","subject":"Re: How to create and keep up to date a naked/bare repository?","fromName":"J. Bruce Fields","fromEmail":"bfields@fieldses.org","sentAt":"2006-01-27T19:01:57Z","receivedAt":"2006-01-27T19:01:57Z","isPatch":false,"sender":{"key":"bfields@citi.umich.edu","avatar":null},"body":"On Fri, Jan 27, 2006 at 10:41:19AM -0800, Junio C Hamano wrote:\n> Mathieu Chouquet-Stringer <ml2news@free.fr> writes:\n> \n> > Thanks and sorry for making you write this long message...\n> \n> Hey, I do not mind \"I appreciate\", but don't be sorry.  I\n> actually enjoyed drawing the ASCII art.\n> \n> >...\n> > It totally does. I guess this email could end up in the Documentation\n> > folder in some way!?\n> \n> Maybe somebody so inclined could copyedit it, find an\n> appropriate place for it somewhere in the tutorial.txt or\n> core-tutorial.txt and feed that back to me in a patch form.\n> Hint, hint,... ;-).\n\nIt might make sense just to dump it in Documentation/howto/ for now.\n\n--b.\n"},{"id":"15172","messageId":"7vek2t1j50.fsf@assigned-by-dhcp.cox.net","threadId":"3148","inReplyTo":"20060127190157.GF23949@fieldses.org","subject":"Re: How to create and keep up to date a naked/bare repository?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-27T21:00:11Z","receivedAt":"2006-01-27T21:00:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"J. Bruce Fields\" <bfields@fieldses.org> writes:\n\n>> Maybe somebody so inclined could copyedit it, find an\n>> appropriate place for it somewhere in the tutorial.txt or\n>> core-tutorial.txt and feed that back to me in a patch form.\n>> Hint, hint,... ;-).\n>\n> It might make sense just to dump it in Documentation/howto/ for now.\n\nPerhaps, but I forgot to say \"after some discussion\".\n\nI think people on the list have better suggestion than what I\noutlined, and I suspect I probably have some details wrong in\nthat message.\n"},{"id":"15189","messageId":"7v4q3no0v7.fsf@assigned-by-dhcp.cox.net","threadId":"3148","inReplyTo":"7v4q3ssbr6.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH/RFC] git-rerere: reuse recorded resolve.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-29T09:10:52Z","receivedAt":"2006-01-29T09:10:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"In a workflow that employs relatively long lived topic branches,\nthe developer sometimes needs to resolve the same conflict over\nand over again until the topic branches are done (either merged\nto the \"release\" branch, or sent out and accepted upstream).\n\nThis commit introduces a new command, \"git rerere\", to help this\nprocess by recording the conflicted automerge results and\ncorresponding hand-resolve results on the initial manual merge,\nand later by noticing the same conflicted automerge and applying\nthe previously recorded hand resolution using three-way merge.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n * With my admittedly limited tests, this seems to work rather\n   well.  I do a lot of \"same\" merges, because I rebuild \"pu\"\n   every time I have something new in the \"master\" branch, and\n   often what conflict are the things in my own topic branches,\n   none of which has been advanced meanwhile.\n\n   The feature is not enabled until you manually create\n   $GIT_DIR/rr-cache directory, at least for now.\n\n Documentation/git-rerere.txt |  177 +++++++++++++++++++++++++++++++++\n Documentation/git.txt        |    3 +\n Makefile                     |    2 \n git-am.sh                    |    1 \n git-commit.sh                |    1 \n git-merge.sh                 |    1 \n git-rerere.perl              |  223 ++++++++++++++++++++++++++++++++++++++++++\n git-reset.sh                 |    2 \n 8 files changed, 408 insertions(+), 2 deletions(-)\n create mode 100644 Documentation/git-rerere.txt\n create mode 100755 git-rerere.perl\n\n9843f047463a7b0b993c4bd80d34934618d5d622\ndiff --git a/Documentation/git-rerere.txt b/Documentation/git-rerere.txt\nnew file mode 100644\nindex 0000000..8b6b651\n--- /dev/null\n+++ b/Documentation/git-rerere.txt\n@@ -0,0 +1,177 @@\n+git-rerere(1)\n+=============\n+\n+NAME\n+----\n+git-rerere - Reuse recorded resolve\n+\n+SYNOPSIS\n+--------\n+'git-rerere'\n+\n+\n+DESCRIPTION\n+-----------\n+\n+In a workflow that employs relatively long lived topic branches,\n+the developer sometimes needs to resolve the same conflict over\n+and over again until the topic branches are done (either merged\n+to the \"release\" branch, or sent out and accepted upstream).\n+\n+This command helps this process by recording conflicted\n+automerge results and corresponding hand-resolve results on the\n+initial manual merge, and later by noticing the same automerge\n+results and applying the previously recorded hand resolution.\n+\n+[NOTE]\n+You need to create `$GIT_DIR/rr-cache` directory to enable this\n+command.\n+\n+DISCUSSION\n+----------\n+\n+When your topic branch modifies overlapping area that your\n+master branch (or upstream) touched since your topic branch\n+forked from it, you may want to test it with the latest master,\n+even before your topic branch is ready to be pushed upstream:\n+\n+------------\n+              o---*---o topic\n+             /\n+    o---o---o---*---o---o master\n+------------\n+\n+For such a test, you need to merge master and topic somehow.\n+One way to do it is to pull master into the topic branch:\n+\n+------------\n+\t$ git checkout topic\n+\t$ git pull . master\n+\n+              o---*---o---+ topic\n+             /           /\n+    o---o---o---*---o---o master\n+------------\n+\n+The commits marked with `*` touch the same area in the same\n+file; you need to resolve the conflicts when creating the commit\n+marked with `+`.  Then you can test the result to make sure your\n+work-in-progress still works with what is in the latest master.\n+\n+After this test merge, there are two ways to continue your work\n+on the topic.  The easiest is to build on top of the test merge\n+commit `+`, and when your work in the topic branch is finally\n+ready, pull the topic branch into master, and/or ask the\n+upstream to pull from you.  By that time, however, the master or\n+the upstream might have been advanced since the test merge `+`,\n+in which case the final commit graph would look like this:\n+\n+------------\n+\t$ git checkout topic\n+\t$ git pull . master\n+\t$ ... work on both topic and master branches\n+\t$ git checkout master\n+\t$ git pull . topic\n+\n+              o---*---o---+---o---o topic\n+             /           /         \\\n+    o---o---o---*---o---o---o---o---+ master\n+------------\n+\n+When your topic branch is long-lived, however, your topic branch\n+would end up having many such \"Merge from master\" commits on it,\n+which would unnecessarily clutter the development history.\n+Readers of the Linux kernel mailing list may remember that Linus\n+complained about such too frequent test merges when a subsystem\n+maintainer asked to pull from a branch full of \"useless merges\".\n+\n+As an alternative, to keep the topic branch clean of test\n+merges, you could blow away the test merge, and keep building on\n+top of the tip before the test merge:\n+\n+------------\n+\t$ git checkout topic\n+\t$ git pull . master\n+\t$ git reset --hard HEAD^ ;# rewind the test merge\n+\t$ ... work on both topic and master branches\n+\t$ git checkout master\n+\t$ git pull . topic\n+\n+              o---*---o-------o---o topic\n+             /                     \\\n+    o---o---o---*---o---o---o---o---+ master\n+------------\n+\n+This would leave only one merge commit when your topic branch is\n+finally ready and merged into the master branch.  This merge\n+would require you to resolve the conflict, introduced by the\n+commits marked with `*`.  However, often this conflict is the\n+same conflict you resolved when you created the test merge you\n+blew away.  `git-rerere` command helps you to resolve this final\n+conflicted merge using the information from your earlier hand\n+resolve.\n+\n+Running `git-rerere` command immediately after a conflicted\n+automerge records the conflicted working tree files, with the\n+usual conflict markers `<<<<<<<`, `=======`, and `>>>>>>>` in\n+them.  Later, after you are done resolving the conflicts,\n+running `git-rerere` again records the resolved state of these\n+files.  Suppose you did this when you created the test merge of\n+master into the topic branch.\n+\n+Next time, running `git-rerere` after seeing a conflicted\n+automerge, if the conflict is the same as the earlier one\n+recorded, it is noticed and a three-way merge between the\n+earlier conflicted automerge, the earlier manual resolution, and\n+the current conflicted automerge is performed by the command.\n+If this three-way merge resolves cleanly, the result is written\n+out to your working tree file, so you would not have to manually\n+resolve it.  Note that `git-rerere` leaves the index file alone,\n+so you still need to do the final sanity checks with `git diff`\n+(or `git diff -c`) and `git update-index` when you are\n+satisfied.\n+\n+As a convenience measure, `git-merge` automatically invokes\n+`git-rerere` when it exits with a failed automerge, which\n+records it if it is a new conflict, or reuses the earlier hand\n+resolve when it is not.  `git-commit` also invokes `git-rerere`\n+when recording a merge result.  What this means is that you do\n+not have to do anything special yourself (Note: you still have\n+to create `$GIT_DIR/rr-cache` directory to enable this command).\n+\n+In our example, when you did the test merge, the manual\n+resolution is recorded, and it will be reused when you do the\n+actual merge later with updated master and topic branch, as long\n+as the earlier resolution is still applicable.\n+\n+The information `git-rerere` records is also used when running\n+`git-rebase`.  After blowing away the test merge and continuing\n+development on the topic branch:\n+\n+------------\n+              o---*---o-------o---o topic\n+             /\n+    o---o---o---*---o---o---o---o   master\n+\n+\t$ git rebase master topic\n+\n+\t\t\t\t  o---*---o-------o---o topic\n+\t\t\t\t /\n+    o---o---o---*---o---o---o---o   master\n+------------\n+\n+you could run `git rebase master topic`, to keep yourself\n+up-to-date even before your topic is ready to be sent upstream.\n+This would result in falling back to three-way merge, and it\n+would conflict the same way the test merge you resolved earlier.\n+`git-rerere` is run by `git rebase` to help you resolve this\n+conflict.\n+\n+\n+Author\n+------\n+Written by Junio C Hamano <junkio@cox.net>\n+\n+GIT\n+---\n+Part of the gitlink:git[7] suite\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex e8ef3ef..2d0ca9d 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -313,6 +313,9 @@ gitlink:git-rebase[1]::\n gitlink:git-repack[1]::\n \tPack unpacked objects in a repository.\n \n+gitlink:git-rerere[1]::\n+\tReuse recorded resolution of conflicted merges.\n+\n gitlink:git-reset[1]::\n \tReset current HEAD to the specified state.\n \ndiff --git a/Makefile b/Makefile\nindex 2aa2385..a566951 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -116,7 +116,7 @@ SCRIPT_SH = \\\n \n SCRIPT_PERL = \\\n \tgit-archimport.perl git-cvsimport.perl git-relink.perl \\\n-\tgit-shortlog.perl git-fmt-merge-msg.perl \\\n+\tgit-shortlog.perl git-fmt-merge-msg.perl git-rerere.perl \\\n \tgit-svnimport.perl git-mv.perl git-cvsexportcommit.perl\n \n SCRIPT_PYTHON = \\\ndiff --git a/git-am.sh b/git-am.sh\nindex 731ab1f..ee6886f 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -88,6 +88,7 @@ fall_back_3way () {\n     # saying that we reverted all those changes.\n \n     git-merge-resolve $orig_tree -- HEAD $his_tree || {\n+\t    git-rerere\n \t    echo Failed to merge in the changes.\n \t    exit 1\n     }\ndiff --git a/git-commit.sh b/git-commit.sh\nindex 193feeb..bfcb0f2 100755\n--- a/git-commit.sh\n+++ b/git-commit.sh\n@@ -237,6 +237,7 @@ else\n fi\n ret=\"$?\"\n rm -f \"$GIT_DIR/COMMIT_MSG\" \"$GIT_DIR/COMMIT_EDITMSG\"\n+git-rerere\n \n if test -x \"$GIT_DIR\"/hooks/post-commit && test \"$ret\" = 0\n then\ndiff --git a/git-merge.sh b/git-merge.sh\nindex 92e5a65..586ac08 100755\n--- a/git-merge.sh\n+++ b/git-merge.sh\n@@ -309,5 +309,6 @@ Conflicts:\n \t\tsed -e 's/^[^\t]*\t/\t/' |\n \t\tuniq\n \t} >>\"$GIT_DIR/MERGE_MSG\"\n+\tgit rerere\n \tdie \"Automatic merge failed; fix up by hand\"\n fi\ndiff --git a/git-rerere.perl b/git-rerere.perl\nnew file mode 100755\nindex 0000000..df11951\n--- /dev/null\n+++ b/git-rerere.perl\n@@ -0,0 +1,223 @@\n+#!/usr/bin/perl\n+#\n+# REuse REcorded REsolve.  This tool records a conflicted automerge\n+# result and its hand resolution, and helps to resolve future\n+# automerge that results in the same conflict.\n+#\n+# To enable this feature, create a directory 'rr-cache' under your\n+# .git/ directory.\n+\n+use Digest;\n+use File::Path;\n+use File::Copy;\n+\n+my $git_dir = $::ENV{GIT_DIR} || \".git\";\n+my $rr_dir = \"$git_dir/rr-cache\";\n+my $merge_rr = \"$git_dir/rr-cache/MERGE_RR\";\n+\n+my %merge_rr = ();\n+\n+sub read_rr {\n+\tif (!-f $merge_rr) {\n+\t\t%merge_rr = ();\n+\t\treturn;\n+\t}\n+\tmy $in;\n+\tlocal $/ = \"\\0\";\n+\topen $in, \"<$merge_rr\" or die \"$!: $merge_rr\";\n+\twhile (<$in>) {\n+\t\tchomp;\n+\t\tmy ($name, $path) = /^([0-9a-f]{40})\\t(.*)$/s;\n+\t\t$merge_rr{$path} = $name;\n+\t}\n+\tclose $in;\n+}\n+\n+sub write_rr {\n+\tmy $out;\n+\topen $out, \">$merge_rr\" or die \"$!: $merge_rr\";\n+\tfor my $path (sort keys %merge_rr) {\n+\t\tmy $name = $merge_rr{$path};\n+\t\tprint $out \"$name\\t$path\\0\";\n+\t}\n+\tclose $out;\n+}\n+\n+sub compute_conflict_name {\n+\tmy ($path) = @_;\n+\tmy @side = ();\n+\tmy $in;\n+\topen $in, \"<$path\"  or die \"$!: $path\";\n+\n+\tmy $sha1 = Digest->new(\"SHA-1\");\n+\tmy $hunk = 0;\n+\twhile (<$in>) {\n+\t\tif (/^<<<<<<< .*/) {\n+\t\t\t$hunk++;\n+\t\t\t@side = ([], undef);\n+\t\t}\n+\t\telsif (/^=======$/) {\n+\t\t\t$side[1] = [];\n+\t\t}\n+\t\telsif (/^>>>>>>> .*/) {\n+\t\t\tmy ($one, $two);\n+\t\t\t$one = join('', @{$side[0]});\n+\t\t\t$two = join('', @{$side[1]});\n+\t\t\tif ($two le $one) {\n+\t\t\t\t($one, $two) = ($two, $one);\n+\t\t\t}\n+\t\t\t$sha1->add($one);\n+\t\t\t$sha1->add(\"\\0\");\n+\t\t\t$sha1->add($two);\n+\t\t\t$sha1->add(\"\\0\");\n+\t\t\t@side = ();\n+\t\t}\n+\t\telsif (@side == 0) {\n+\t\t\tnext;\n+\t\t}\n+\t\telsif (defined $side[1]) {\n+\t\t\tpush @{$side[1]}, $_;\n+\t\t}\n+\t\telse {\n+\t\t\tpush @{$side[0]}, $_;\n+\t\t}\n+\t}\n+\tclose $in;\n+\treturn ($sha1->hexdigest, $hunk);\n+}\n+\n+sub record_preimage {\n+\tmy ($path, $name) = @_;\n+\tmy @side = ();\n+\tmy ($in, $out);\n+\topen $in, \"<$path\"  or die \"$!: $path\";\n+\topen $out, \">$name\" or die \"$!: $name\";\n+\n+\twhile (<$in>) {\n+\t\tif (/^<<<<<<< .*/) {\n+\t\t\t@side = ([], undef);\n+\t\t}\n+\t\telsif (/^=======$/) {\n+\t\t\t$side[1] = [];\n+\t\t}\n+\t\telsif (/^>>>>>>> .*/) {\n+\t\t\tmy ($one, $two);\n+\t\t\t$one = join('', @{$side[0]});\n+\t\t\t$two = join('', @{$side[1]});\n+\t\t\tif ($two le $one) {\n+\t\t\t\t($one, $two) = ($two, $one);\n+\t\t\t}\n+\t\t\tprint $out \"<<<<<<<\\n\";\n+\t\t\tprint $out $one;\n+\t\t\tprint $out \"=======\\n\";\n+\t\t\tprint $out $two;\n+\t\t\tprint $out \">>>>>>>\\n\";\n+\t\t\t@side = ();\n+\t\t}\n+\t\telsif (@side == 0) {\n+\t\t\tprint $out $_;\n+\t\t}\n+\t\telsif (defined $side[1]) {\n+\t\t\tpush @{$side[1]}, $_;\n+\t\t}\n+\t\telse {\n+\t\t\tpush @{$side[0]}, $_;\n+\t\t}\n+\t}\n+\tclose $out;\n+\tclose $in;\n+}\n+\n+sub find_conflict {\n+\tmy $in;\n+\tlocal $/ = \"\\0\";\n+\topen $in, '-|', qw(git ls-files -z -u) or die \"$!: ls-files\";\n+\tmy %path = ();\n+\tmy @path = ();\n+\twhile (<$in>) {\n+\t\tchomp;\n+\t\tmy ($mode, $sha1, $stage, $path) =\n+\t\t    /^([0-7]+) ([0-9a-f]{40}) ([123])\\t(.*)$/s;\n+\t\t$path{$path} |= (1 << $stage);\n+\t}\n+\tclose $in;\n+\twhile (my ($path, $status) = each %path) {\n+\t\tif ($status == 14) { push @path, $path; }\n+\t}\n+\treturn @path;\n+}\n+\n+sub merge {\n+\tmy ($name, $path) = @_;\n+\trecord_preimage($path, \"$rr_dir/$name/thisimage\");\n+\tunless (system('merge', map { \"$rr_dir/$name/${_}image\" }\n+\t\t       qw(this pre post))) {\n+\t\tmy $in;\n+\t\topen $in, \"<$rr_dir/$name/thisimage\" or\n+\t\t    die \"$!: $name/thisimage\";\n+\t\tmy $out;\n+\t\topen $out, \">$path\" or die \"$!: $path\";\n+\t\twhile (<$in>) { print $out $_; }\n+\t\tclose $in;\n+\t\tclose $out;\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+-d \"$rr_dir\" || exit(0);\n+\n+read_rr();\n+my %conflict = map { $_ => 1 } find_conflict();\n+\n+# MERGE_RR records paths with conflicts immediately after merge\n+# failed.  Some of the conflicted paths might have been hand resolved\n+# in the working tree since then, but the initial run would catch all\n+# and register their preimages.\n+\n+for my $path (keys %conflict) {\n+\t# This path has conflict.  If it is not recorded yet,\n+\t# record the pre-image.\n+\tif (!exists $merge_rr{$path}) {\n+\t\tmy ($name, $hunk) = compute_conflict_name($path);\n+\t\tnext unless ($hunk);\n+\t\t$merge_rr{$path} = $name;\n+\t\tif (! -d \"$rr_dir/$name\") {\n+\t\t\tmkpath(\"$rr_dir/$name\", 0, 0777);\n+\t\t\tprint STDERR \"Recorded preimage for '$path'\\n\";\n+\t\t\trecord_preimage($path, \"$rr_dir/$name/preimage\");\n+\t\t}\n+\t}\n+}\n+\n+# Now some of the paths that had conflicts earlier might have been\n+# hand resolved.  Others may be similar to a conflict already that\n+# was resolved before.\n+\n+for my $path (keys %merge_rr) {\n+\tmy $name = $merge_rr{$path};\n+\n+\t# We could resolve this automatically if we have images.\n+\tif (-f \"$rr_dir/$name/preimage\" &&\n+\t    -f \"$rr_dir/$name/postimage\") {\n+\t\tif (merge($name, $path)) {\n+\t\t\tprint STDERR \"Resolved '$path' using previous resolution.\\n\";\n+\t\t\t# Then we do not have to worry about this path\n+\t\t\t# anymore.\n+\t\t\tdelete $merge_rr{$path};\n+\t\t\tnext;\n+\t\t}\n+\t}\n+\n+\t# Let's see if we have resolved it.\n+\t(undef, my $hunk) = compute_conflict_name($path);\n+\tnext if ($hunk);\n+\n+\tprint STDERR \"Recorded resolution for '$path'.\\n\";\n+\tcopy($path, \"$rr_dir/$name/postimage\");\n+\t# And we do not have to worry about this path anymore.\n+\tdelete $merge_rr{$path};\n+}\n+\n+# Write out the rest.\n+write_rr();\ndiff --git a/git-reset.sh b/git-reset.sh\nindex 6c9e58a..fe53fc8 100755\n--- a/git-reset.sh\n+++ b/git-reset.sh\n@@ -100,4 +100,4 @@ case \"$reset_type\" in\n \t;;\n esac\n \n-rm -f \"$GIT_DIR/MERGE_HEAD\"\n+rm -f \"$GIT_DIR/MERGE_HEAD\" \"$GIT_DIR/rr-cache/MERGE_RR\"\n-- \n1.1.5.g3480-dirty\n"}]}