gitdb 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gitdb/Card.rb +19 -5
- data/lib/gitdb/Contacts.rb +47 -29
- data/lib/gitdb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 415b324df37bb5e094057579249db2c48bb0688c
|
4
|
+
data.tar.gz: 14b33e1f14ff4f2042c4c241d74789973ee9428f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dbb35666c3a91878196ef67f6a4be2e5d3c70ad20260c3b86e5e1f3713b184a8a0e7b499bb9334c83429efefaa4ac546cc3cad2b2d3b62e5cc8322961ba9cc0
|
7
|
+
data.tar.gz: 06b3e24be21830a88f773e2867e7170cb9a42b89881f59a5e1a11ead45a09c01e8423463e9319d4b8e7a4daaf1c6039109bddc575e59c47789cd754e068bb5a0
|
data/lib/gitdb/Card.rb
CHANGED
@@ -2,12 +2,16 @@
|
|
2
2
|
module Gitdb
|
3
3
|
class Card
|
4
4
|
|
5
|
+
# 线程锁
|
6
|
+
@@lock = false
|
7
|
+
|
5
8
|
def initialize repo
|
6
9
|
@repo = repo
|
7
10
|
end
|
8
11
|
|
9
12
|
def self::exist? repo, id
|
10
|
-
|
13
|
+
# 检查stage而不是tree
|
14
|
+
nil != repo.index.get(id)
|
11
15
|
end
|
12
16
|
|
13
17
|
def exist? id
|
@@ -35,6 +39,13 @@ module Gitdb
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def create uid
|
42
|
+
# 等待资源可用
|
43
|
+
loop do
|
44
|
+
break unless @@lock
|
45
|
+
end
|
46
|
+
# 锁定资源
|
47
|
+
@@lock = true
|
48
|
+
|
38
49
|
# 生成唯一的名片id
|
39
50
|
while exist?(@id = Gitil::generate_code(4))
|
40
51
|
end
|
@@ -42,6 +53,12 @@ module Gitdb
|
|
42
53
|
@uid = uid
|
43
54
|
# 用默认格式初始化名片可读内容
|
44
55
|
@content = format_card @id, @uid
|
56
|
+
# 添加到暂存区
|
57
|
+
add_to_stage @id, JSON.pretty_generate(@content)
|
58
|
+
|
59
|
+
# 释放资源
|
60
|
+
@@lock = false
|
61
|
+
|
45
62
|
# 返回Card实例
|
46
63
|
self
|
47
64
|
end
|
@@ -104,15 +121,12 @@ module Gitdb
|
|
104
121
|
@content[:meta] = hash
|
105
122
|
end
|
106
123
|
|
107
|
-
# Notice: 调用delete之后需要先commit, 然后才能继续调用add_to_stage
|
108
124
|
def delete
|
109
|
-
@repo.index.
|
110
|
-
@repo.index.find { |blob| @repo.index.remove blob[:path] if blob[:path] == @id }
|
125
|
+
@repo.index.remove @id
|
111
126
|
end
|
112
127
|
|
113
128
|
def add_to_stage id, content
|
114
129
|
oid = @repo.write content, :blob
|
115
|
-
@repo.index.read_tree @repo.head.target.tree unless @repo.branches.count == 0
|
116
130
|
@repo.index.add :path => id, :oid => oid, :mode => 0100644
|
117
131
|
end
|
118
132
|
end
|
data/lib/gitdb/Contacts.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
module Gitdb
|
3
3
|
class Contacts
|
4
4
|
|
5
|
+
# 线程锁
|
6
|
+
@@lock = false
|
7
|
+
|
5
8
|
attr_accessor 'repo'
|
6
9
|
|
7
10
|
def initialize uid
|
@@ -17,13 +20,24 @@ module Gitdb
|
|
17
20
|
end
|
18
21
|
|
19
22
|
def create name
|
23
|
+
# 等待资源可用
|
24
|
+
loop do
|
25
|
+
break unless @@lock
|
26
|
+
end
|
27
|
+
# 锁定资源
|
28
|
+
@@lock = true
|
29
|
+
|
20
30
|
# 生成联系人的唯一编码
|
21
31
|
while exist?(@gid = Gitil::generate_code(4))
|
22
32
|
end
|
23
33
|
# 创建并打开git仓库
|
24
34
|
@repo = Rugged::Repository.init_at "#{STORAGE_PATH}/#{@gid}"
|
35
|
+
# 释放资源
|
36
|
+
@@lock = false
|
25
37
|
# 设置元信息
|
26
|
-
setmeta :name => name, :gid => @gid, :
|
38
|
+
setmeta :name => name, :gid => @gid, :owner => @uid
|
39
|
+
# 读取最后一次提交指向的tree的数据到暂存区
|
40
|
+
@repo.index.read_tree @repo.last_commit.tree unless @repo.head_unborn?
|
27
41
|
# 返回Contacts实例
|
28
42
|
self
|
29
43
|
end
|
@@ -31,6 +45,8 @@ module Gitdb
|
|
31
45
|
def access gid
|
32
46
|
if exist?(@gid = gid)
|
33
47
|
@repo = Rugged::Repository.new "#{STORAGE_PATH}/#{gid}"
|
48
|
+
# 读取最后一次提交指向的tree的数据到暂存区
|
49
|
+
@repo.index.read_tree @repo.last_commit.tree unless @repo.head_unborn?
|
34
50
|
self
|
35
51
|
else
|
36
52
|
nil
|
@@ -39,7 +55,7 @@ module Gitdb
|
|
39
55
|
|
40
56
|
# 返回Card实例集合
|
41
57
|
def get_all_cards
|
42
|
-
if @repo.
|
58
|
+
if @repo.head_unborn?
|
43
59
|
[]
|
44
60
|
else
|
45
61
|
@repo.head.target.tree.collect.each { |o| Card.new(@repo).access o[:name] }
|
@@ -48,7 +64,7 @@ module Gitdb
|
|
48
64
|
|
49
65
|
# 返回Card实例
|
50
66
|
def get_card_by_id id
|
51
|
-
if @repo.
|
67
|
+
if @repo.head_unborn?
|
52
68
|
nil
|
53
69
|
else
|
54
70
|
Card.new(@repo).access id
|
@@ -58,7 +74,7 @@ module Gitdb
|
|
58
74
|
def getmeta
|
59
75
|
@meta = {
|
60
76
|
:name => @repo.config['repo.name'],
|
61
|
-
:
|
77
|
+
:owner => @repo.config['repo.owner'],
|
62
78
|
:gid => @repo.config['repo.gid']
|
63
79
|
}
|
64
80
|
end
|
@@ -69,46 +85,48 @@ module Gitdb
|
|
69
85
|
@repo.config['repo.gid'] = hash[:gid] if hash.member? :gid
|
70
86
|
end
|
71
87
|
|
72
|
-
# 返回commit
|
88
|
+
# 返回commit对象oid
|
73
89
|
def read_change_history
|
74
|
-
if @repo.
|
90
|
+
if @repo.head_unborn?
|
75
91
|
[]
|
76
92
|
else
|
77
93
|
walker = Rugged::Walker.new repo
|
78
94
|
walker.push repo.last_commit
|
79
|
-
walker.collect.each { |commit| commit.
|
95
|
+
walker.collect.each { |commit| commit.oid }
|
80
96
|
end
|
81
97
|
end
|
82
98
|
|
83
99
|
# 等同于git工具的 "Revert"操作
|
84
|
-
# @sha
|
85
|
-
#
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
# get committer info
|
98
|
-
# committer = get_card_by_id(@uid).getdata.sub_hash(:name, :email).merge :time => Time.now
|
100
|
+
# @sha = commit oid
|
101
|
+
# @options = {
|
102
|
+
# :message => '',
|
103
|
+
# :author => {:name=> '', :email=> '', :time=> Time},
|
104
|
+
# :committer => {:name=> '', :email=> '', :time=> Time}
|
105
|
+
# }
|
106
|
+
#
|
107
|
+
def revert_to sha, options
|
108
|
+
return nil if @repo.head_unborn?
|
109
|
+
commit = @repo.lookup sha
|
110
|
+
tree = commit.tree
|
111
|
+
# 构造tree
|
112
|
+
@repo.index.read_tree tree
|
99
113
|
# 提交暂存区的tree
|
100
|
-
make_a_commit
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
104
|
-
def write_to_stage card_id, content
|
105
|
-
oid = @repo.write content, :blob
|
106
|
-
@repo.index.add :path => card_id, :oid => oid, :mode => 0100644
|
114
|
+
make_a_commit options
|
107
115
|
end
|
108
116
|
|
109
117
|
# 生成一个commit对象
|
110
118
|
# 每次修改最终要调用
|
119
|
+
# @options = {
|
120
|
+
# :message => '',
|
121
|
+
# :author => {:name=> '', :email=> '', :time=> Time},
|
122
|
+
# :committer => {:name=> '', :email=> '', :time=> Time}
|
123
|
+
# }
|
124
|
+
#
|
111
125
|
def make_a_commit options
|
126
|
+
if @repo.index.count == 0 && @repo.head_unborn?
|
127
|
+
return nil
|
128
|
+
end
|
129
|
+
options[:message] = 'make a commit' unless options.include? :message
|
112
130
|
options[:tree] = @repo.index.write_tree @repo
|
113
131
|
options[:parents] = @repo.empty? ? [] : [@repo.head.target].compact
|
114
132
|
options[:update_ref] = 'HEAD'
|
data/lib/gitdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|