public
Description: Piston is a utility that eases vendor branch management. This repository is a complete reimplementation of Piston to provide different backends, depending on the repositories and working copies you pistonize from.
Homepage: http://piston.rubyforge.org/
Clone URL: git://github.com/francois/piston.git
francois (author)
Tue May 13 15:55:22 -0700 2008
commit  6e1cadf946995cf390038318006423b6363d6e1c
tree    b7c2b8268e5ceb5c1a07d2ace2cee960f600830b
parent  e3ecdb9457fe4604d79a9b159bf88140041150a0
piston / lib / piston / commands / import.rb
100644 70 lines (55 sloc) 2.378 kb
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require "piston/commands/base"
 
module Piston
  module Commands
    class Import < Piston::Commands::Base
      attr_reader :options
 
      def temp_dir_name(working_copy)
        working_copy.path.parent + ".#{working_copy.path.basename}.tmp"
      end
      
      def repository_type
        options[:repository_type]
      end
      
      def select_repository(repository_url)
        if repository_type then
          logger.info {"Forced repository type to #{repository_type}"}
          repository_class_name = "Piston::#{repository_type.downcase.capitalize}::Repository"
          repository_class = constantize(repository_class_name)
          repository_class.new(repository_url)
        else
          logger.info {"Guessing the repository type"}
          Piston::Repository.guess(repository_url)
        end
      end
 
      def run(repository_url, target_revision, wcdir)
        repository = select_repository(repository_url)
        revision = repository.at(target_revision)
 
        wcdir = wcdir.nil? ? repository.basename : wcdir
        logger.info {"Guessing the working copy type"}
        logger.debug {"repository_url: #{repository_url.inspect}, target_revision: #{target_revision.inspect}, wcdir: #{wcdir.inspect}"}
        working_copy = guess_wc(wcdir)
 
        tmpdir = temp_dir_name(working_copy)
 
        if working_copy.exist? && !force then
          logger.fatal "Path #{working_copy} already exists and --force not given. Aborting..."
          abort
        end
 
        begin
          logger.info {"Checking out the repository"}
          revision.checkout_to(tmpdir)
 
          logger.debug {"Creating the local working copy"}
          working_copy.create
 
          logger.info {"Copying from #{revision}"}
          working_copy.copy_from(revision)
 
          logger.debug {"Remembering values"}
          working_copy.remember({:repository_url => repository.url, :lock => options[:lock], :repository_class => repository.class.name},
                                revision.remember_values)
 
          logger.debug {"Finalizing working copy"}
          working_copy.finalize
 
          logger.info {"Checked out #{repository_url.inspect} #{revision.name} to #{wcdir.inspect}"}
        ensure
          logger.debug {"Removing temporary directory: #{tmpdir}"}
          tmpdir.rmtree rescue nil
        end
      end
    end
  end
end