Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 65 lines (54 sloc) 1.348 kB
4407117 @schacon initial commit of code examples
schacon authored
1 #! /usr/bin/env ruby
2 require 'digest/sha1'
3
4 last_mark = nil
5 $author = 'Scott Chacon <schacon@example.com>'
6
7 $marks = []
8 def convert_dir_to_mark(dir)
9 if !$marks.include?(dir)
10 $marks << dir
11 end
12 ($marks.index(dir) + 1).to_s
13 end
14
15 def convert_dir_to_date(dir)
16 if dir == 'current'
17 return Time.now().to_i
18 else
19 dir = dir.gsub('back_', '')
20 (year, month, day) = dir.split('_')
21 return Time.local(year, month, day).to_i
22 end
23 end
24
25 def export_data(string)
26 print "data #{string.size}\n#{string}"
27 end
28
29 def inline_data(file, code = 'M', mode = '644')
30 content = File.read(file)
31 puts "#{code} #{mode} inline #{file}"
32 export_data(content)
33 end
34
35 def print_export(dir, last_mark)
36 mark = convert_dir_to_mark(dir)
37 date = convert_dir_to_date(dir)
38
39 # print the import information
40 puts 'commit refs/heads/master'
41 puts 'mark :' + mark
42 puts "committer #{$author} #{date} -0700"
43 export_data('imported from ' + dir)
44 puts 'from :' + last_mark if last_mark
45
46 puts 'deleteall'
47 Dir.glob("**/*").each do |file|
48 next if !File.file?(file)
49 inline_data(file)
50 end
51
52 return mark
53 end
54
55 # loop through the directories
56 Dir.chdir(ARGV[0]) do
57 Dir.glob("*").each do |dir|
58 next if File.file?(dir)
59
60 # move into the target directory
61 Dir.chdir(dir) do
62 last_mark = print_export(dir, last_mark)
63 end
64 end
65 end
Something went wrong with that request. Please try again.