Use cross-platform ruby mktmpdir in comparelinks.rb

This commit is contained in:
Saivann 2014-06-04 11:52:42 -04:00
parent cdb7f24ef9
commit b5d2cbe5ce

View file

@ -3,12 +3,7 @@
## Example: ruby ./_contrib/comparelinks.rb master newbranch > ../diff ## Example: ruby ./_contrib/comparelinks.rb master newbranch > ../diff
WORKDIR = `mktemp -d` require 'tmpdir'
WORKDIR.gsub!("\n",'')
at_exit {
`rm -fr "#{WORKDIR}"`
}
def prompt(*args) def prompt(*args)
print(*args) print(*args)
@ -52,43 +47,49 @@ def fetchlinks()
end end
# Copy current repository to a temporary directory Dir.mktmpdir{|workdir|
`rsync -a ./ "#{WORKDIR}/"`
# Build both version of the website and fetch all links WORKDIR=workdir.gsub("\n",'')
oldlinks = {}
newlinks = {}
Dir.chdir(WORKDIR) do # Copy current repository to a temporary directory
`rsync -a ./ "#{WORKDIR}/"`
`git checkout #{srcbr}` # Build both version of the website and fetch all links
`jekyll` oldlinks = {}
oldlinks = fetchlinks() newlinks = {}
`git checkout #{dstbr}` Dir.chdir(WORKDIR) do
`jekyll`
newlinks = fetchlinks()
end `git checkout #{srcbr}`
`jekyll`
oldlinks = fetchlinks()
`git checkout #{dstbr}`
`jekyll`
newlinks = fetchlinks()
end
# Find added links, removed links
diffaddlinks = []
diffrmlinks = []
newlinks.each { |link, etag|
next if oldlinks.has_key?(link)
diffaddlinks.push(link)
}
oldlinks.each { |link, etag|
next if newlinks.has_key?(link)
diffrmlinks.push(link)
}
# Display resulting diff
diff = ''
if diffaddlinks.length > 0
diff = diff + "## links added\n\n" + diffaddlinks.join("\n") + "\n\n"
end
if diffrmlinks.length > 0
diff = diff + "## links removed\n\n" + diffrmlinks.join("\n") + "\n\n"
end
print diff
# Find added links, removed links
diffaddlinks = []
diffrmlinks = []
newlinks.each { |link, etag|
next if oldlinks.has_key?(link)
diffaddlinks.push(link)
} }
oldlinks.each { |link, etag|
next if newlinks.has_key?(link)
diffrmlinks.push(link)
}
# Display resulting diff
diff = ''
if diffaddlinks.length > 0
diff = diff + "## links added\n\n" + diffaddlinks.join("\n") + "\n\n"
end
if diffrmlinks.length > 0
diff = diff + "## links removed\n\n" + diffrmlinks.join("\n") + "\n\n"
end
print diff