summaryrefslogtreecommitdiffstats
path: root/lib/git/raw/internal/mmap.rb
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-20 13:24:44 -0800
committerscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-20 13:24:44 -0800
commit90dea6d415bfc5734bc87c2797b26cca311246bc (patch)
treeca17b784c0f417bb62fde17e9b11a1a8a444c07e /lib/git/raw/internal/mmap.rb
parentd07a2c04c1599fe707831afdd29397cc36e02fa6 (diff)
downloadthird_party-ruby-git-90dea6d415bfc5734bc87c2797b26cca311246bc.tar.gz
third_party-ruby-git-90dea6d415bfc5734bc87c2797b26cca311246bc.tar.xz
third_party-ruby-git-90dea6d415bfc5734bc87c2797b26cca311246bc.zip
have the pure ruby bindings working to some degree
Diffstat (limited to 'lib/git/raw/internal/mmap.rb')
-rw-r--r--lib/git/raw/internal/mmap.rb70
1 files changed, 37 insertions, 33 deletions
diff --git a/lib/git/raw/internal/mmap.rb b/lib/git/raw/internal/mmap.rb
index d7390b1..15b5628 100644
--- a/lib/git/raw/internal/mmap.rb
+++ b/lib/git/raw/internal/mmap.rb
@@ -2,43 +2,47 @@ begin
require 'mmap'
rescue LoadError
-module Git module Raw module Internal
- class Mmap
- def initialize(file)
- @file = file
- @offset = nil
- end
+module Git
+ module Raw
+ module Internal
+ class Mmap
+ def initialize(file)
+ @file = file
+ @offset = nil
+ end
- def unmap
- @file = nil
- end
+ def unmap
+ @file = nil
+ end
- def [](*idx)
- idx = idx[0] if idx.length == 1
- case idx
- when Range
- offset = idx.first
- len = idx.last - idx.first + idx.exclude_end? ? 0 : 1
- when Fixnum
- offset = idx
- len = nil
- when Array
- offset, len = idx
- else
- raise RuntimeError, "invalid index param: #{idx.class}"
- end
- if @offset != offset
- @file.seek(offset)
- end
- @offset = offset + len ? len : 1
- if not len
- @file.read(1)[0]
- else
- @file.read(len)
+ def [](*idx)
+ idx = idx[0] if idx.length == 1
+ case idx
+ when Range
+ offset = idx.first
+ len = idx.last - idx.first + idx.exclude_end? ? 0 : 1
+ when Fixnum
+ offset = idx
+ len = nil
+ when Array
+ offset, len = idx
+ else
+ raise RuntimeError, "invalid index param: #{idx.class}"
+ end
+ if @offset != offset
+ @file.seek(offset)
+ end
+ @offset = offset + len ? len : 1
+ if not len
+ @file.read(1)[0]
+ else
+ @file.read(len)
+ end
+ end
end
end
- end
-end end
+ end
+end
end # rescue LoadError