{"id":471,"date":"2008-05-24T16:00:42","date_gmt":"2008-05-24T23:00:42","guid":{"rendered":"https:\/\/www.reenigne.org\/blog\/?p=471"},"modified":"2008-05-23T16:19:36","modified_gmt":"2008-05-23T23:19:36","slug":"scripted-merge","status":"publish","type":"post","link":"https:\/\/www.reenigne.org\/blog\/scripted-merge\/","title":{"rendered":"Scripted merge"},"content":{"rendered":"<p>I&#8217;ve been thinking a bit about version control systems. It occurs to me that almost every element of a version control system is actually fairly easy technically except for two &#8211; diff and merge.<\/p>\n<p>Diff is the process of finding the difference between two files &#8211; I&#8217;ve written about some ways to deal with this in the past.<\/p>\n<p>Merge is process of taking two changes X and Y and finding the change Z consisting of both X and Y. This sounds easy but it&#8217;s really solving the &#8220;A is to B as C is to what&#8221; problem (the original being A, X being B, Y being C and Z being the answer). Suppose X is adding a method to a class and Y is renaming the same class. Most merge systems would add the new method with the original name (since Y didn&#8217;t include renaming of the new method).<\/p>\n<p>I think the answer is to treat every change as a little program in its own right. X isn&#8217;t just &#8220;inserting the lines corresponding to the new method&#8221;, it&#8217;s &#8220;insert the lines corresponding to the new method, substituting the current name of the class where appropriate&#8221; and Y isn&#8217;t just &#8220;change this list of instances of Foo to Bar&#8221; it&#8217;s &#8220;change Foo to Bar everywhere it appears in the context of a class name in namespace Baz&#8221;. In other words, have the changes themselves actually have some intelligence about what they are supposed to be doing. Then these programs could just be &#8220;run&#8221; (in any other) and produce the correct result.<\/p>\n<p>Such changes would be more than just lists of &#8220;insert this text in this position in this file&#8221; and &#8220;delete this text from this position in file&#8221;, and could therefore not easily be generated from diffing two files.<\/p>\n<p>However, such changes could be generated by a text editor which has some understanding of the format of the files it is used to edit. For example, if such an editor had a &#8220;rename class&#8221; command, it could generate a change saying exactly that.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been thinking a bit about version control systems. It occurs to me that almost every element of a version control system is actually fairly easy technically except for two &#8211; diff and merge. Diff is the process of finding the difference between two files &#8211; I&#8217;ve written about some ways to deal with this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[],"class_list":["post-471","post","type-post","status-publish","format-standard","hentry","category-algorithms"],"_links":{"self":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/comments?post=471"}],"version-history":[{"count":0,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}