git-ds 0.9.8.1 → 0.9.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ 2011-08-03 : mkfs <mkfs@thoughtgang.org>
2
+ * Repo#path_to_object now searches Index if appropriate
3
+ * Index now has include? and path_to_object methods
4
+
5
+ 2011-08-01 : mkfs <mkfs@thoughtgang.org>
6
+ * Added Index#force_sync method
7
+ * StageMemIndex#sync is now a no-op
8
+
1
9
  2011-07-30 : mkfs <mkfs@thoughtgang.org>
2
10
  * Model#batch is now a wrapper for Database#batch
3
11
  * Transaction#perform now executes in batch mode
@@ -374,7 +374,7 @@ NOTE: branch-and-merge will fail if in batch mode (TODO: FIX).
374
374
  end
375
375
 
376
376
  # write in-mem staging index to git-staging-index
377
- self.staging.sync
377
+ self.staging.force_sync
378
378
 
379
379
  # read git-staging-index if appropriate
380
380
  unstage
@@ -91,6 +91,30 @@ filesystem.
91
91
  }
92
92
  end
93
93
 
94
+ =begin rdoc
95
+ Return true if index includes path.
96
+ =end
97
+ def include?(path)
98
+ path_to_object(path) ? true : false
99
+ end
100
+
101
+ =begin rdoc
102
+ Return the data for the object at 'path'. This is required in order for
103
+ in-memory indexes to work properly.
104
+ =end
105
+ def path_to_object(path)
106
+ # Note: this algorithm is re-implemented from Grit::Index#add
107
+ arr = path.split('/')
108
+ fname = arr.pop
109
+ curr = self.tree
110
+ arr.each do |dir|
111
+ curr = curr[dir] if curr
112
+ end
113
+
114
+ #TODO: it would be nice to return a Grit::Blob or Grit::Tree here.
115
+ (curr && fname && curr[fname]) ? curr[fname] : nil
116
+ end
117
+
94
118
  private
95
119
 
96
120
  =begin rdoc
@@ -191,6 +215,8 @@ the index contents.
191
215
  @repo.exec_in_git_dir { `git read-tree #{@sha}` }
192
216
  end
193
217
 
218
+ alias :force_sync :sync
219
+
194
220
  =begin rdoc
195
221
  Read staging index from disk and create a StagingIndex object for it.
196
222
 
@@ -224,9 +250,15 @@ in-memory index with the on-disk index.
224
250
  end
225
251
 
226
252
  =begin rdoc
227
- Override StageIndex#sync to not rely on StageIndex#build.
253
+ Replace standard sync with a no-op.
228
254
  =end
229
255
  def sync
256
+ end
257
+
258
+ =begin rdoc
259
+ Force a sync-to-disk. This is used by batch mode to ensure a sync.
260
+ =end
261
+ def force_sync
230
262
  self.read_tree(self.write)
231
263
  @repo.exec_in_git_dir { `git read-tree #{@sha}` }
232
264
  end
@@ -339,10 +339,12 @@ Remove an object from the database. This can be a path to a Tree or a Blob.
339
339
  =begin rdoc
340
340
  Fetch the contents of a DB or FS object from the object database. This uses
341
341
  the staging index.
342
+ Note: This returns nil if path is a Tree instead of a blob
342
343
  =end
343
344
  def object_data(path)
344
345
  blob = path_to_object(path)
345
- (blob && blob.kind_of?(Grit::Blob)) ? blob.data : nil
346
+ return nil if (not blob) || (blob.kind_of? Grit::Tree)
347
+ blob.kind_of?(Grit::Blob) ? blob.data : blob
346
348
  end
347
349
 
348
350
  # ----------------------------------------------------------------------
@@ -455,14 +457,17 @@ Fetch an object from the repo based on its path.
455
457
  If a staging index exists, its tree will be used; otherwise, the tree
456
458
  Repo#current_branch will be used.
457
459
 
458
- The object returned will be a Grit::Blob, a Grit::Tree, or nil.
460
+ The object returned will be a Grit::Blob, a Grit::Tree, or the raw data from
461
+ the staging index.
459
462
  =end
460
463
  def path_to_object(path)
461
464
  treeish = (@staging_index ? staging.sha : @current_branch)
462
465
  tree = self.tree(treeish, [path])
463
466
  return tree.blobs.first if tree && (not tree.blobs.empty?)
464
467
  return tree.trees.first if tree && (not tree.trees.empty?)
465
- nil
468
+
469
+ # check staging index in case object has not been written to object DB
470
+ staging? ? staging.path_to_object(path) : nil
466
471
  end
467
472
 
468
473
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-ds
3
3
  version: !ruby/object:Gem::Version
4
- hash: 37
4
+ hash: 33
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 8
10
- - 1
11
- version: 0.9.8.1
10
+ - 3
11
+ version: 0.9.8.3
12
12
  platform: ruby
13
13
  authors:
14
14
  - TG Community
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-07-31 00:00:00 -04:00
19
+ date: 2011-08-03 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -72,7 +72,6 @@ extra_rdoc_files:
72
72
  - README.rdoc
73
73
  files:
74
74
  - lib/git-ds.rb
75
- - lib/git-ds/t.rb
76
75
  - lib/git-ds/repo.rb
77
76
  - lib/git-ds/config.rb
78
77
  - lib/git-ds/transaction.rb
@@ -1,44 +0,0 @@
1
- =begin rdoc
2
- Subcribers that are notified when the model is changed. This is a Hash of
3
- an ident (e.g. a classname, UUID, or symbol) to a 2-element array:
4
- a callback method and an (optional) object to pass with that method.
5
- =end
6
- attr_reader :subscribers
7
-
8
- @subscribers = {}
9
- =begin rdoc
10
- Subscribe to change notifications from the model. The provided callback will
11
- be invoked whenever the model is modified (specifically, when an outer
12
- Transaction or ExecCmd is completed).
13
-
14
- A subscriber can use either block or argument syntax:
15
-
16
- def func_cb(arg)
17
- ...
18
- end
19
- model.subscribe( self.ident, arg, func_cb )
20
-
21
- # block callback
22
- model.subscribe( self.ident ) { ... }
23
-
24
- # block callback where arg is specified in advance
25
- model.subscribe( self.ident, arg ) { |arg| ... }
26
- =end
27
- def subscribe(ident, obj=nil, func=nil, &block)
28
- cb = (block_given?) ? block : func
29
- @subscribers[ident] = [cb, obj]
30
- end
31
-
32
- =begin rdoc
33
- Notify all subscribers that a change has occurred.
34
- =end
35
- def notify
36
- @subscribers.each { |ident, (block,obj)} block.call(obj) }
37
- end
38
-
39
- =begin rdoc
40
- Unsubscribe from change notification.
41
- =end
42
- def unsubscribe(ident)
43
- @subscribers.delete(ident)
44
- end