Is there a faster way? using Find to update repositories

Discussion in 'Ruby' started by Dominic Sisneros, Feb 13, 2008.

  1. [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
    Dominic Sisneros, Feb 13, 2008
    #1
    1. Advertising

  2. 2008/2/13, Dominic Sisneros <>:
    > 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
    Robert Klemme, Feb 14, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steve
    Replies:
    17
    Views:
    681
    Mike Smith
    Sep 13, 2004
  2. Replies:
    9
    Views:
    711
    benben
    Mar 17, 2006
  3. Replies:
    7
    Views:
    312
    Boris Borcic
    Aug 6, 2008
  4. Steve555
    Replies:
    21
    Views:
    1,027
    James Kanze
    Dec 28, 2008
  5. Replies:
    21
    Views:
    1,023
    Juha Nieminen
    Aug 13, 2012
Loading...

Share This Page