Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add patch to fix date in git adapter -- should really be submitted up…

…stream, but fix it here first
  • Loading branch information...
commit fa16cd4a5b109fc4af8f9ede5d8a9a923c967df8 1 parent 1756f7f
@ericpaulbishop ericpaulbishop authored
Showing with 133 additions and 0 deletions.
  1. +1 −0  init.rb
  2. +132 −0 lib/gitosis/patches/git_adapter_patch.rb
View
1  init.rb
@@ -4,6 +4,7 @@
require_dependency 'gitosis'
require_dependency 'gitosis/patches/repositories_controller_patch'
require_dependency 'gitosis/patches/repositories_helper_patch'
+require_dependency 'gitosis/patches/git_adapter_patch'
Redmine::Plugin.register :redmine_gitosis do
name 'Redmine Gitosis plugin'
View
132 lib/gitosis/patches/git_adapter_patch.rb
@@ -0,0 +1,132 @@
+require_dependency 'git_adapter'
+module Gitosis
+ module Patches
+ module GitAdapterPatch
+
+
+ def lastrev(path,rev)
+ return nil if path.nil?
+ cmd = "#{GIT_BIN} --git-dir #{target('')} log --pretty=fuller --date=rfc --no-merges -n 1 "
+ cmd << " #{shell_quote rev} " if rev
+ cmd << "-- #{path} " unless path.empty?
+ shellout(cmd) do |io|
+ begin
+ id = io.gets.split[1]
+ author = io.gets.match('Author:\s+(.*)$')[1]
+ 2.times { io.gets }
+ time = io.gets.match('CommitDate:\s+(.*)$')[1]
+
+ Revision.new({
+ :identifier => id,
+ :scmid => id,
+ :author => author,
+ :time => Time.rfc2822(time),
+ :message => nil,
+ :paths => nil
+ })
+ rescue NoMethodError => e
+ logger.error("The revision '#{path}' has a wrong format")
+ return nil
+ end
+ end
+ end
+
+
+ def revisions(path, identifier_from, identifier_to, options={})
+ revisions = Revisions.new
+
+ cmd = "#{GIT_BIN} --git-dir #{target('')} log --raw --date=rfc --pretty=fuller"
+ cmd << " --reverse" if options[:reverse]
+ cmd << " --all" if options[:all]
+ cmd << " -n #{options[:limit]} " if options[:limit]
+ cmd << " #{shell_quote(identifier_from + '..')} " if identifier_from
+ cmd << " #{shell_quote identifier_to} " if identifier_to
+ cmd << " --since=#{shell_quote(options[:since].strftime("%Y-%m-%d %H:%M:%S"))}" if options[:since]
+ cmd << " -- #{path}" if path && !path.empty?
+
+ shellout(cmd) do |io|
+ files=[]
+ changeset = {}
+ parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files
+ revno = 1
+
+ io.each_line do |line|
+ if line =~ /^commit ([0-9a-f]{40})$/
+ key = "commit"
+ value = $1
+ if (parsing_descr == 1 || parsing_descr == 2)
+ parsing_descr = 0
+ revision = Revision.new({
+ :identifier => changeset[:commit],
+ :scmid => changeset[:commit],
+ :author => changeset[:author],
+ #:time => Time.parse(changeset[:date]),
+ :time => Time.rfc2822(changeset[:date]),
+ :message => changeset[:description],
+ :paths => files
+ })
+ if block_given?
+ yield revision
+ else
+ revisions << revision
+ end
+ changeset = {}
+ files = []
+ revno = revno + 1
+ end
+ changeset[:commit] = $1
+ elsif (parsing_descr == 0) && line =~ /^(\w+):\s*(.*)$/
+ key = $1
+ value = $2
+ if key == "Author"
+ changeset[:author] = value
+ elsif key == "CommitDate"
+ changeset[:date] = value
+ end
+ elsif (parsing_descr == 0) && line.chomp.to_s == ""
+ parsing_descr = 1
+ changeset[:description] = ""
+ elsif (parsing_descr == 1 || parsing_descr == 2) \
+ && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\s+(.+)$/
+ parsing_descr = 2
+ fileaction = $1
+ filepath = $2
+ files << {:action => fileaction, :path => filepath}
+ elsif (parsing_descr == 1 || parsing_descr == 2) \
+ && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\s+(.+)$/
+ parsing_descr = 2
+ fileaction = $1
+ filepath = $3
+ files << {:action => fileaction, :path => filepath}
+ elsif (parsing_descr == 1) && line.chomp.to_s == ""
+ parsing_descr = 2
+ elsif (parsing_descr == 1)
+ changeset[:description] << line[4..-1]
+ end
+ end
+
+ if changeset[:commit]
+ revision = Revision.new({
+ :identifier => changeset[:commit],
+ :scmid => changeset[:commit],
+ :author => changeset[:author],
+ :time => Time.parse(changeset[:date]),
+ :message => changeset[:description],
+ :paths => files
+ })
+
+ if block_given?
+ yield revision
+ else
+ revisions << revision
+ end
+ end
+ end
+
+ return nil if $? && $?.exitstatus != 0
+ revisions
+ end
+ end
+ end
+end
+GitAdapter.send(:include, Gitosis::Patches::GitAdapterPatch) unless GitAdapter.include?(Gitosis::Patches::GitAdapterPatch)
Please sign in to comment.
Something went wrong with that request. Please try again.