Mercurial > hg > soundsoftware-site
comparison lib/redmine/scm/adapters/git_adapter.rb @ 37:94944d00e43c
* Update to SVN trunk rev 4411
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 19 Nov 2010 13:24:41 +0000 |
parents | 1d32c0a0efbf |
children | af80e5618e9b |
comparison
equal
deleted
inserted
replaced
22:40f7cfd4df19 | 37:94944d00e43c |
---|---|
33 end | 33 end |
34 | 34 |
35 def branches | 35 def branches |
36 return @branches if @branches | 36 return @branches if @branches |
37 @branches = [] | 37 @branches = [] |
38 cmd = "#{GIT_BIN} --git-dir #{target('')} branch" | 38 cmd = "#{GIT_BIN} --git-dir #{target('')} branch --no-color" |
39 shellout(cmd) do |io| | 39 shellout(cmd) do |io| |
40 io.each_line do |line| | 40 io.each_line do |line| |
41 @branches << line.match('\s*\*?\s*(.*)$')[1] | 41 @branches << line.match('\s*\*?\s*(.*)$')[1] |
42 end | 42 end |
43 end | 43 end |
63 cmd << shell_quote("HEAD:" + path) if identifier.nil? | 63 cmd << shell_quote("HEAD:" + path) if identifier.nil? |
64 cmd << shell_quote(identifier + ":" + path) if identifier | 64 cmd << shell_quote(identifier + ":" + path) if identifier |
65 shellout(cmd) do |io| | 65 shellout(cmd) do |io| |
66 io.each_line do |line| | 66 io.each_line do |line| |
67 e = line.chomp.to_s | 67 e = line.chomp.to_s |
68 if e =~ /^\d+\s+(\w+)\s+([0-9a-f]{40})\s+([0-9-]+)\s+(.+)$/ | 68 if e =~ /^\d+\s+(\w+)\s+([0-9a-f]{40})\s+([0-9-]+)\t(.+)$/ |
69 type = $1 | 69 type = $1 |
70 sha = $2 | 70 sha = $2 |
71 size = $3 | 71 size = $3 |
72 name = $4 | 72 name = $4 |
73 full_path = path.empty? ? name : "#{path}/#{name}" | 73 full_path = path.empty? ? name : "#{path}/#{name}" |
84 entries.sort_by_name | 84 entries.sort_by_name |
85 end | 85 end |
86 | 86 |
87 def lastrev(path,rev) | 87 def lastrev(path,rev) |
88 return nil if path.nil? | 88 return nil if path.nil? |
89 cmd = "#{GIT_BIN} --git-dir #{target('')} log --pretty=fuller --no-merges -n 1 " | 89 cmd = "#{GIT_BIN} --git-dir #{target('')} log --no-color --date=iso --pretty=fuller --no-merges -n 1 " |
90 cmd << " #{shell_quote rev} " if rev | 90 cmd << " #{shell_quote rev} " if rev |
91 cmd << "-- #{path} " unless path.empty? | 91 cmd << "-- #{shell_quote path} " unless path.empty? |
92 shellout(cmd) do |io| | 92 shellout(cmd) do |io| |
93 begin | 93 begin |
94 id = io.gets.split[1] | 94 id = io.gets.split[1] |
95 author = io.gets.match('Author:\s+(.*)$')[1] | 95 author = io.gets.match('Author:\s+(.*)$')[1] |
96 2.times { io.gets } | 96 2.times { io.gets } |
97 time = io.gets.match('CommitDate:\s+(.*)$')[1] | 97 time = Time.parse(io.gets.match('CommitDate:\s+(.*)$')[1]).localtime |
98 | 98 |
99 Revision.new({ | 99 Revision.new({ |
100 :identifier => id, | 100 :identifier => id, |
101 :scmid => id, | 101 :scmid => id, |
102 :author => author, | 102 :author => author, |
112 end | 112 end |
113 | 113 |
114 def revisions(path, identifier_from, identifier_to, options={}) | 114 def revisions(path, identifier_from, identifier_to, options={}) |
115 revisions = Revisions.new | 115 revisions = Revisions.new |
116 | 116 |
117 cmd = "#{GIT_BIN} --git-dir #{target('')} log --raw --date=iso --pretty=fuller " | 117 cmd = "#{GIT_BIN} --git-dir #{target('')} log --no-color --raw --date=iso --pretty=fuller " |
118 cmd << " --reverse " if options[:reverse] | 118 cmd << " --reverse " if options[:reverse] |
119 cmd << " --all " if options[:all] | 119 cmd << " --all " if options[:all] |
120 cmd << " -n #{options[:limit]} " if options[:limit] | 120 cmd << " -n #{options[:limit]} " if options[:limit] |
121 cmd << "#{shell_quote(identifier_from + '..')}" if identifier_from | 121 cmd << "#{shell_quote(identifier_from + '..')}" if identifier_from |
122 cmd << "#{shell_quote identifier_to}" if identifier_to | 122 cmd << "#{shell_quote identifier_to}" if identifier_to |
123 cmd << " --since=#{shell_quote(options[:since].strftime("%Y-%m-%d %H:%M:%S"))}" if options[:since] | 123 cmd << " --since=#{shell_quote(options[:since].strftime("%Y-%m-%d %H:%M:%S"))}" if options[:since] |
124 cmd << " -- #{path}" if path && !path.empty? | 124 cmd << " -- #{shell_quote path}" if path && !path.empty? |
125 | 125 |
126 shellout(cmd) do |io| | 126 shellout(cmd) do |io| |
127 files=[] | 127 files=[] |
128 changeset = {} | 128 changeset = {} |
129 parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files | 129 parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files |
163 end | 163 end |
164 elsif (parsing_descr == 0) && line.chomp.to_s == "" | 164 elsif (parsing_descr == 0) && line.chomp.to_s == "" |
165 parsing_descr = 1 | 165 parsing_descr = 1 |
166 changeset[:description] = "" | 166 changeset[:description] = "" |
167 elsif (parsing_descr == 1 || parsing_descr == 2) \ | 167 elsif (parsing_descr == 1 || parsing_descr == 2) \ |
168 && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\s+(.+)$/ | 168 && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\t(.+)$/ |
169 parsing_descr = 2 | 169 parsing_descr = 2 |
170 fileaction = $1 | 170 fileaction = $1 |
171 filepath = $2 | 171 filepath = $2 |
172 files << {:action => fileaction, :path => filepath} | 172 files << {:action => fileaction, :path => filepath} |
173 elsif (parsing_descr == 1 || parsing_descr == 2) \ | 173 elsif (parsing_descr == 1 || parsing_descr == 2) \ |
174 && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\s+(.+)$/ | 174 && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\t(.+)$/ |
175 parsing_descr = 2 | 175 parsing_descr = 2 |
176 fileaction = $1 | 176 fileaction = $1 |
177 filepath = $3 | 177 filepath = $3 |
178 files << {:action => fileaction, :path => filepath} | 178 files << {:action => fileaction, :path => filepath} |
179 elsif (parsing_descr == 1) && line.chomp.to_s == "" | 179 elsif (parsing_descr == 1) && line.chomp.to_s == "" |
207 | 207 |
208 def diff(path, identifier_from, identifier_to=nil) | 208 def diff(path, identifier_from, identifier_to=nil) |
209 path ||= '' | 209 path ||= '' |
210 | 210 |
211 if identifier_to | 211 if identifier_to |
212 cmd = "#{GIT_BIN} --git-dir #{target('')} diff #{shell_quote identifier_to} #{shell_quote identifier_from}" | 212 cmd = "#{GIT_BIN} --git-dir #{target('')} diff --no-color #{shell_quote identifier_to} #{shell_quote identifier_from}" |
213 else | 213 else |
214 cmd = "#{GIT_BIN} --git-dir #{target('')} show #{shell_quote identifier_from}" | 214 cmd = "#{GIT_BIN} --git-dir #{target('')} show --no-color #{shell_quote identifier_from}" |
215 end | 215 end |
216 | 216 |
217 cmd << " -- #{shell_quote path}" unless path.empty? | 217 cmd << " -- #{shell_quote path}" unless path.empty? |
218 diff = [] | 218 diff = [] |
219 shellout(cmd) do |io| | 219 shellout(cmd) do |io| |
253 | 253 |
254 def cat(path, identifier=nil) | 254 def cat(path, identifier=nil) |
255 if identifier.nil? | 255 if identifier.nil? |
256 identifier = 'HEAD' | 256 identifier = 'HEAD' |
257 end | 257 end |
258 cmd = "#{GIT_BIN} --git-dir #{target('')} show #{shell_quote(identifier + ':' + path)}" | 258 cmd = "#{GIT_BIN} --git-dir #{target('')} show --no-color #{shell_quote(identifier + ':' + path)}" |
259 cat = nil | 259 cat = nil |
260 shellout(cmd) do |io| | 260 shellout(cmd) do |io| |
261 io.binmode | 261 io.binmode |
262 cat = io.read | 262 cat = io.read |
263 end | 263 end |