Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

Capistrano : apply local patches when deploying from an external source code repository

I've submitted patches to a couple rails apps, and want to run off of their SCM's trunk code, but with my local patches applied. These Capistrano tasks will take any files matching
patches/*.diff
in your local directory, and apply them before restarting your app.

task :after_setup do
  patches_setup
end

task :after_update_code do
  send_and_apply_patches
end

task :patches_setup do
  run "mkdir -p #{deploy_to}/#{shared_dir}/patches" 
end

task :send_and_apply_patches do
  Dir[File.join(File.dirname(__FILE__), '../patches/*.diff')].sort.each do |patch|
    puts "sending #{File.basename(patch)}"
    put(File.read(patch),
       "#{deploy_to}/#{shared_dir}/patches/#{File.basename(patch)}",
       :mode => 0777)
    puts "applying #{File.basename(patch)}"
    run "cd #{release_path}; patch -p0 < #{deploy_to}/#{shared_dir}/patches/#{File.basename(patch)}"
  end
end

patching source

Making Patch -- to represent the addition of a new file, diff it against /dev/null.
diff -Naur test.old test.cpp > test.patch

Apply Patch
patch test.cpp test.patch

Undo Patch
patch -R test.cpp test.patch

rpatch XOR diff/patch script

REBOL []


do-by-type: func [
    value
    actions [block!]
    /default
        def-action [block!]
    /local action
][
    either action: select actions type?/word value [
        ;print mold action
        do bind/copy action 'value
    ][
        if default [do bind/copy def-action 'value]
    ]
]

to-binary-ex: func [value] [
    do-by-type value [
        binary! [value]
        string! [to-binary value]
        file!   [read/binary value]
    ]
]

xor-diff: func [
    a [binary! string! file!]
    b [binary! string! file!]
    /local bin-a bin-b
][
    bin-a: to-binary-ex a
    bin-b: to-binary-ex b
    bin-a xor bin-b
]

make-patch: func [
    a [binary! string! file!]
    b [binary! string! file!]
][
    compress xor-diff a b
]

apply-patch: func [
    data  [binary! string! file!]
    patch [binary! string!]
    /local result
][
    result: xor-diff data decompress patch
    ; If they gave us a string as the source, return a string.
    ;?? If they give us a file, should we write back out to it?
    either string? data [to-string result][result]
]


a: "Now is the time for all good men to come to the aid of their country..."
b: {Now is the time for all good men to come to the aid of their country...
whether 'tis nolber to suffer the slings and arrows...}
;d1: xor-diff a b
p1: make-patch a b
bp: apply-patch a p1



change-dir %./test-files

files: sort read %.
print mold files
print [files/1 files/2]
fp-1-2: make-patch files/1 files/2
fp-2-3: make-patch files/2 files/3
fp-3-4: make-patch files/3 files/4
fp-a-b: make-patch files/5 files/6

pp-a-b: apply-patch files/5 fp-a-b

change-dir %..


halt


Release description

// Release description

#                                 1.1.0 patchlevel 1
#                                 | | |            |
#          Code base version -----/ | |            |
#          Major version -----------/ |            |
#          Minor version -------------/            |
#          Patchlevel -----------------------------/
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS