lib/gitrb/repository.rb in gitrb-0.1.2 vs lib/gitrb/repository.rb in gitrb-0.1.3
- old
+ new
@@ -17,11 +17,10 @@
SHA_PATTERN = /^[A-Fa-f0-9]{5,40}$/
REVISION_PATTERN = /^[\w\-\.]+([\^~](\d+)?)*$/
DEFAULT_ENCODING = 'utf-8'
MIN_GIT_VERSION = '1.6.0'
- LOCK = 'Gitrb.Repository.lock'
if RUBY_VERSION > '1.9'
def set_encoding(s); s.force_encoding(@encoding); end
else
def set_encoding(s); s; end
@@ -31,10 +30,11 @@
def initialize(options = {})
@bare = options[:bare] || false
@branch = options[:branch] || 'master'
@logger = options[:logger] || Logger.new(nil)
@encoding = options[:encoding] || DEFAULT_ENCODING
+ @lock = {}
@path = options[:path]
@path.chomp!('/')
@path += '/.git' if !@bare
@@ -66,11 +66,11 @@
load if changed?
end
# Is there any transaction going on?
def in_transaction?
- Thread.current[LOCK]
+ @lock[Thread.current.object_id]
end
# Diff
def diff(from, to, path = nil)
if from && !(Commit === from)
@@ -327,11 +327,11 @@
# Tries to get lock on lock file, load the this repository if
# has changed in the repository.
def start_transaction
file = File.open("#{head_path}.lock", 'w')
file.flock(File::LOCK_EX)
- Thread.current[LOCK] = file
+ @lock[Thread.current.object_id] = file
refresh
end
# Rerepository the state of the repository.
#
@@ -344,11 +344,11 @@
# Finish the transaction.
#
# Release the lock file.
def finish_transaction
- Thread.current[LOCK].close rescue nil
- Thread.current[LOCK] = nil
+ @lock[Thread.current.object_id].close rescue nil
+ @lock.delete(Thread.current.object_id)
File.unlink("#{head_path}.lock") rescue nil
end
def get_type(id, expected)
object = get(id)