Sha256: ecc483fe2e3ad06f1b04cb28cc6440c016d4fec70e44b622d07678a992fb6de7

Contents?: true

Size: 1.6 KB

Versions: 37

Compression:

Stored size: 1.6 KB

Contents

module OhlohScm::Adapters
	class GitAdapter < AbstractAdapter

		#---------------------------------------------------------------------------
		# TOKEN-RELATED CODE
		#
		# As CVS and Subversion are converted to Git, the unique ID of each commit
		# from the original source control system is stored in a special token file.
		#
		# Whenever Ohloh needs to incrementally update our local copy of the code with
		# the latest commits, we just check the token file to see at which point we need
		# to restart the process.
		#---------------------------------------------------------------------------

		def token_filename
			'ohloh_token'
		end

		def token_path
			File.join(self.url, token_filename)
		end

		# Determine the most recent revision that was safely stored in the GIT archive.
		# Resets the token file on disk to the most recent version stored in the repository.
		def read_token
			token = nil
			if self.exist?
				begin
					token = run("cd '#{url}' && git cat-file -p `git ls-tree HEAD #{token_filename} | cut -c 13-51`").strip
				rescue RuntimeError => e
					# If the git repository doesn't have a token file yet, it will error out.
					# We want to just quietly return nil.
					if e.message =~ /pathspec '#{token_filename}' did not match any file\(s\) known to git/
						return nil
					else
						raise
					end
				end
			end
			token
		end

		# Saves the new token in a well-known file.
		# If the passed token is empty, this method silently does nothing.
		def write_token(token)
			if token and token.to_s.length > 0
				File.open(token_path, 'w') do |f|
					f.write token.to_s
				end
			end
		end
	end
end

Version data entries

37 entries across 37 versions & 1 rubygems

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