Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Is there a faster way? using Find to update repositories

Reply
Thread Tools

Is there a faster way? using Find to update repositories

 
 
Dominic Sisneros
Guest
Posts: n/a
 
      02-13-2008
[Note: parts of this message were removed to make it a legal post.]

require 'fileutils'
require 'find'

include FileUtils::Verbose

GIT_DIR = File.expand_path("~/programming/repos")

def find_git(dir)
git_repo = lambda{|d| Dir.entries(d).include?('.git') }
dirs = []
Find.find(dir) do |f |
Find.prune if f == "."
next if dirs.include? File.basename(f)
if FileTest.directory? f
dirs << f if git_repo[f]
end
end
dirs
end

git_dirs = find_git(GIT_DIR)

puts git_dirs.inspect
git_dirs.each do |repo|
cd repo do
system('git pull')
end
end

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      02-14-2008
2008/2/13, Dominic Sisneros <(E-Mail Removed)>:
> require 'fileutils'
> require 'find'
>
> include FileUtils::Verbose
>
> GIT_DIR = File.expand_path("~/programming/repos")
>
> def find_git(dir)
> git_repo = lambda{|d| Dir.entries(d).include?('.git') }
> dirs = []
> Find.find(dir) do |f |
> Find.prune if f == "."
> next if dirs.include? File.basename(f)
> if FileTest.directory? f
> dirs << f if git_repo[f]
> end
> end
> dirs
> end
>
> git_dirs = find_git(GIT_DIR)
>
> puts git_dirs.inspect
> git_dirs.each do |repo|
> cd repo do
> system('git pull')
> end
> end


Not sure whether this is faster but it's shorter:

dirs = Hash.new do |h,dir|
Dir.chdir dir { system 'git pull' }
h[dir] = true
end

Dir[File.join(File.expand_path("~/programming/repos"), "**",
"*.git")].each do |gf|
dirs[File.basename(gf)]
end

Alternative

require 'set'

dirs = Set.new

Find.find File.expand_path("~/programming/repos") do |f|
dir = File.dirname f

if File.file? f and /\.git$/ =~ f and dirs.add? dir
Dir.chdir dir { system 'git pull' }
end
end

Cheers

robert

--
use.inject do |as, often| as.you_can - without end

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CVS Repositories Shinya Koizumi Java 0 03-22-2006 10:02 PM
[ANN] repocaster.com : RSS feeds of Subversion/CVS repositories Admin Python 0 03-06-2006 07:09 PM
VHDL Code Repositories chris.michael@lmco.com VHDL 3 02-13-2005 05:51 PM
Source code as data structure in repositories. Steven T. Hatton C++ 5 04-10-2004 02:23 PM
XML Schemas Repositories babelix XML 1 11-13-2003 12:55 AM



Advertisments