Piston 2.0 Progress: native or ruby patching ?
piston update is coming. I have the high-level workflow completed. Conceptually, updating is pretty simple:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
module Piston module Commands class Update < Piston::Commands::Base # +wcdir+ is the working copy we're going to change. # +to+ is the new target revision we want to be at after update returns. def run(wcdir, to) working_copy = Piston::WorkingCopy.guess(wcdir) logger.debug {"Recalling previously saved values"} values = working_copy.recall repository_class = values["repository_class"] repository_url = values["repository_url"] repository = repository_class.constantize.new(repository_url) from_revision = repository.at(values["handler"]) to_revision = repository.at(to) logger.debug {"Validating that #{from_revision} exists and is capable of performing the update"} from_revision.validate! logger.info {"Updating from #{from_revision} to #{to_revision}"} working_copy.apply_differences(from_revision.differences_with(to_revision)) end end end end |
Obviously, the devil’s in the details… Notice the last line above:
1 |
working_copy.apply_differences(from_revision.differences_with(to_revision)) |
from_revision will calculate a set of differences between itself and to_revision. In Subversion speak, that would probably mean an svn log followed by an svn diff, to get all changes (copies + diffs).
What Piston 1.x does is copy the newer file over the original file, and then applies the changes between the last changed revision of the local files and the working copy. This ensures changes that were made are kept in the new revision.
I know I can do it under Subversion, as I have already done it, but what about git ? I can probably use a combination of git-format-patch and git-apply to get the job done. That would certainly work.
I also thought about finding / using a patch implementation in Ruby. I wonder if that would be another acceptable road ? Anybody out there has / knows about a patch implementation in Ruby ?
Leave a Reply