git-ds 0.9.5.1 → 0.9.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,6 +1,10 @@
1
1
  2011-04-18 : mkfs <mkfs@thoughtgang.org>
2
+ * Bumped gem version to 0.9.5
2
3
  * Added ModelItem.exist? class member
3
4
  * Added convenience property method aliases to ModelItem
5
+ * Changed default branch from 'master' to Repo#current_branch
6
+ * Added a BinaryPropertyDefinition class
7
+ * Added a binary_property class method to ModelItem
4
8
 
5
9
  2011-04-15 : mkfs <mkfs@thoughtgang.org>
6
10
  * Removed newline from Repo.top_level
data/lib/git-ds/index.rb CHANGED
@@ -129,7 +129,7 @@ Index object for the Git staging index.
129
129
 
130
130
  =begin rdoc
131
131
  =end
132
- def initialize(repo,treeish=nil)
132
+ def initialize(repo, treeish=nil)
133
133
  super(repo)
134
134
  @parent_commit = repo.commits(repo.current_branch, 1).first
135
135
  treeish = (@parent_commit ? @parent_commit.tree.id : 'master') if \
@@ -249,6 +249,17 @@ This can be overridden to change how properties are stored.
249
249
  define_db_property(name, default, &block)
250
250
  end
251
251
 
252
+ =begin rdoc
253
+ Define a BinaryProperty for this ModelItem class. The property will be on-FS
254
+ unless on_fs is set to false.
255
+
256
+ Note: Properties that store raw binary data have no default value and no
257
+ validation function. They are assumed to be on-disk by default.
258
+ =end
259
+ def binary_property(name, on_fs=true)
260
+ add_property BinaryPropertyDefinition.new(name, nil, on_fs)
261
+ end
262
+
252
263
  =begin rdoc
253
264
  Define a property that is a link to a ModelItem object.
254
265
 
@@ -97,8 +97,8 @@ Property BLOB.
97
97
  val = value.inspect
98
98
  end
99
99
 
100
- on_fs ? model.add_fs_item(path(parent_path), val + "\n") \
101
- : model.add_item(path(parent_path), val + "\n")
100
+ write(model, path(parent_path), val + "\n")
101
+
102
102
  val
103
103
  end
104
104
 
@@ -113,6 +113,47 @@ valid. Otherwise, return true.
113
113
 
114
114
  alias :default :default_value
115
115
 
116
+ protected
117
+
118
+ =begin rdoc
119
+ Write
120
+ =end
121
+ def write(model, path, value)
122
+ on_fs ? model.add_fs_item(path, value) : model.add_item(path, value)
123
+ end
124
+
125
+ end
126
+
127
+ =begin rdoc
128
+ A definition of a ModelItem property that stores binary data.
129
+ =end
130
+ class BinaryPropertyDefinition < PropertyDefinition
131
+
132
+ =begin rdoc
133
+ Read value from ModelItem at path in Model.
134
+
135
+ This just returns the raw binary value of the property file contents.
136
+ =end
137
+ def get(model, parent_path)
138
+ model.get_item(path(parent_path))
139
+ end
140
+
141
+ =begin rdoc
142
+ Write a raw binary value to ModelItem at path in Model.
143
+
144
+ Note: this returns the raw binary data as written to the Property BLOB.
145
+ =end
146
+ def set(model, parent_path, value)
147
+ write(model, path(parent_path), value)
148
+ value
149
+ end
150
+
151
+ =begin rdoc
152
+ Raw binary property values are always valid if they are not nil
153
+ =end
154
+ def valid?(val)
155
+ val != nil
156
+ end
116
157
  end
117
158
 
118
159
  =begin rdoc
data/lib/git-ds/repo.rb CHANGED
@@ -261,8 +261,9 @@ Returns SHA of commit.
261
261
  =end
262
262
  def stage_and_commit(msg, actor=nil, &block)
263
263
  stage(&block)
264
- self.staging.commit(msg, actor)
264
+ sha = self.staging.commit(msg, actor)
265
265
  unstage
266
+ sha
266
267
  end
267
268
 
268
269
  # ----------------------------------------------------------------------
@@ -347,7 +348,7 @@ the staging index.
347
348
  # ----------------------------------------------------------------------
348
349
  =begin rdoc
349
350
  The Tree object for the given treeish reference
350
- +treeish+ is the reference (default 'master')
351
+ +treeish+ is the reference (default Repo#current_branch)
351
352
  +paths+ is an optional Array of directory paths to restrict the tree (default [])
352
353
 
353
354
  Uses staging index if present and provides wrapper for nil treeish.
@@ -363,7 +364,7 @@ Uses staging index if present and provides wrapper for nil treeish.
363
364
  @staging_index.sync
364
365
  super(@staging_index.current_tree.id, paths)
365
366
  else
366
- treeish = 'master' if not treeish
367
+ treeish = @current_branch if not treeish
367
368
  super
368
369
  end
369
370
  rescue Grit::GitRuby::Repository::NoSuchPath
@@ -419,7 +420,7 @@ tree_contents.
419
420
  def list(path=nil)
420
421
  sha = path_to_sha(path)
421
422
  # ensure correct operation even if path doesn't exist in repo
422
- t = sha ? tree(sha) : tree('master', (path ? [path] : []))
423
+ t = sha ? tree(sha) : tree(@current_branch, (path ? [path] : []))
423
424
  t ? tree_contents( t ) : {}
424
425
  end
425
426
 
@@ -452,12 +453,12 @@ Returns the raw (git cat-file) representation of a tree.
452
453
  Fetch an object from the repo based on its path.
453
454
 
454
455
  If a staging index exists, its tree will be used; otherwise, the tree
455
- 'master' will be used.
456
+ Repo#current_branch will be used.
456
457
 
457
458
  The object returned will be a Grit::Blob, a Grit::Tree, or nil.
458
459
  =end
459
460
  def path_to_object(path)
460
- treeish = (@staging_index ? staging.sha : 'master')
461
+ treeish = (@staging_index ? staging.sha : @current_branch)
461
462
  tree = self.tree(treeish, [path])
462
463
  return tree.blobs.first if tree && (not tree.blobs.empty?)
463
464
  return tree.trees.first if tree && (not tree.trees.empty?)
data/tests/ut_repo.rb CHANGED
@@ -173,6 +173,7 @@ class TC_GitRepoTest < Test::Unit::TestCase
173
173
 
174
174
  # switch to new branch and change data
175
175
  @repo.set_branch(new_branch)
176
+ assert_equal('v01', @repo.current_branch, 'V01 is not current branch')
176
177
  path, data = 'class c/instance a/prop b', '~~~~~~~~~~'
177
178
  @repo.stage_and_commit('test commit for merge') { |idx|
178
179
  idx.add( path, data )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-ds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5.1
4
+ version: 0.9.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: grit
17
- requirement: &19161300 !ruby/object:Gem::Requirement
17
+ requirement: &20831860 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 2.2.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *19161300
25
+ version_requirements: *20831860
26
26
  description: A hierarchical datastore based on Git.
27
27
  email: community@thoughtgang.org
28
28
  executables: []