Sha256: e11fa1e4047ecd8717d65e5eebe144bda76f9688191a06dde75a5391360aa928

Contents?: true

Size: 1.11 KB

Versions: 37

Compression:

Stored size: 1.11 KB

Contents

require 'digest/sha1'

NULL_SHA1 = '0000000000000000000000000000000000000000' unless defined?(NULL_SHA1)

module OhlohScm::Adapters
	class AbstractAdapter

		# This file provides SHA1 computation helpers for source control systems that
		# don't have them natively (that is, everyone except Git!).
		# So GitAdapter doesn't use this code, but others can us it to compute SHA1s
		# that match those generated natively by Git.

		def compute_sha1(blob)
			blob.to_s == '' ? NULL_SHA1 : Digest::SHA1.hexdigest("blob #{blob.length}\0#{blob}")
		end

		# Populates the SHA1 values for each diff in a commit.
		def populate_commit_sha1s!(commit)
			if commit.diffs
				commit.diffs.each do |diff|
					populate_diff_sha1s!(commit, diff)
				end
			end
			commit
		end

		# Populates the SHA1 values for a single diff.
		def populate_diff_sha1s!(commit, diff)
			diff.sha1 =
				case diff.action
				when 'D'
					NULL_SHA1
				else
					compute_sha1(cat_file(commit, diff))
				end

			diff.parent_sha1 =
				case diff.action
				when 'A'
					NULL_SHA1
				else
					compute_sha1(cat_file_parent(commit, diff))
				end

			diff
		end
	end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
ohloh_scm-2.5.1 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.14 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.13 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.12 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.11 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.10 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.9 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.8 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.7 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.6 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.5 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.4 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.3 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.1 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.4.0 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.3.5 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.3.4 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.3.2 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.3.1 lib/ohloh_scm/adapters/abstract/sha1.rb
ohloh_scm-2.3.0 lib/ohloh_scm/adapters/abstract/sha1.rb