git-bro 0.1.0 → 0.2.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.
Files changed (66) hide show
  1. data/LICENSE +7 -0
  2. data/README.rdoc +37 -0
  3. data/bin/git-bro +85 -85
  4. data/docs/created.rid +1 -0
  5. data/docs/files/LICENSE.html +129 -0
  6. data/docs/files/README_rdoc.html +178 -0
  7. data/docs/fr_class_index.html +26 -0
  8. data/docs/fr_file_index.html +28 -0
  9. data/docs/fr_method_index.html +26 -0
  10. data/docs/index.html +24 -0
  11. data/docs/rdoc-style.css +208 -0
  12. data/lib/git-bro.rb +2 -1
  13. data/lib/git-bro/commands/serve.rb +2 -2
  14. data/lib/git-bro/core_extensions.rb +22 -0
  15. data/lib/git-bro/repository.rb +74 -40
  16. data/lib/git-bro/sinatra/helpers.rb +11 -0
  17. data/sinatra/app.rb +113 -0
  18. data/{bin → sinatra}/public/images/file.png +0 -0
  19. data/{bin → sinatra}/public/images/folder.png +0 -0
  20. data/sinatra/public/js/application.js +10 -0
  21. data/sinatra/public/js/jquery-1.4.2.js +6240 -0
  22. data/sinatra/views/application.sass +180 -0
  23. data/sinatra/views/coderay.sass +42 -0
  24. data/sinatra/views/commit.haml +5 -0
  25. data/sinatra/views/commit_details.haml +13 -0
  26. data/sinatra/views/commits.haml +31 -0
  27. data/sinatra/views/dir.haml +40 -0
  28. data/sinatra/views/file_content.haml +5 -0
  29. data/{bin → sinatra}/views/index.haml +0 -0
  30. data/{bin → sinatra}/views/layout.haml +5 -1
  31. data/sinatra/views/menu.haml +23 -0
  32. data/sinatra/views/tree.haml +5 -0
  33. data/test/git-bro.git/HEAD +1 -0
  34. data/test/git-bro.git/config +4 -0
  35. data/test/git-bro.git/description +1 -0
  36. data/test/git-bro.git/hooks/applypatch-msg.sample +15 -0
  37. data/test/git-bro.git/hooks/commit-msg.sample +24 -0
  38. data/test/git-bro.git/hooks/post-commit.sample +8 -0
  39. data/test/git-bro.git/hooks/post-receive.sample +15 -0
  40. data/test/git-bro.git/hooks/post-update.sample +8 -0
  41. data/test/git-bro.git/hooks/pre-applypatch.sample +14 -0
  42. data/test/git-bro.git/hooks/pre-commit.sample +18 -0
  43. data/test/git-bro.git/hooks/pre-rebase.sample +169 -0
  44. data/test/git-bro.git/hooks/prepare-commit-msg.sample +36 -0
  45. data/test/git-bro.git/hooks/update.sample +118 -0
  46. data/test/git-bro.git/info/exclude +6 -0
  47. data/test/git-bro.git/objects/pack/pack-668e7a3976d53d070420e5877925f8472aaf569d.idx +0 -0
  48. data/test/git-bro.git/objects/pack/pack-668e7a3976d53d070420e5877925f8472aaf569d.pack +0 -0
  49. data/test/git-bro.git/objects/pack/pack-6f8375d1e612aff7cf5777d6fb1d0ca463f8e49d.idx +0 -0
  50. data/test/git-bro.git/objects/pack/pack-6f8375d1e612aff7cf5777d6fb1d0ca463f8e49d.pack +0 -0
  51. data/test/git-bro.git/refs/heads/develop +1 -0
  52. data/test/git-bro.git/refs/heads/master +1 -0
  53. data/test/git-bro/test_repository.rb +46 -0
  54. data/test/helper.rb +6 -0
  55. metadata +113 -30
  56. data/README +0 -18
  57. data/bin/server.rb +0 -52
  58. data/bin/short_help.txt +0 -4
  59. data/bin/views/application.sass +0 -69
  60. data/bin/views/dir.haml +0 -23
  61. data/bin/views/dir_listing.haml +0 -3
  62. data/bin/views/file_content.haml +0 -3
  63. data/git-bro-0.0.1.gem +0 -0
  64. data/git-bro.gemspec +0 -65
  65. data/lib/git-bro/process.rb +0 -28
  66. data/rakefile.rb +0 -29
@@ -0,0 +1,26 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Classes
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Classes</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Classes</h1>
22
+ <div id="index-entries">
23
+ </div>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,28 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Files
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Files</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Files</h1>
22
+ <div id="index-entries">
23
+ <a href="files/LICENSE.html">LICENSE</a><br />
24
+ <a href="files/README_rdoc.html">README.rdoc</a><br />
25
+ </div>
26
+ </div>
27
+ </body>
28
+ </html>
@@ -0,0 +1,26 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Methods
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Methods</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Methods</h1>
22
+ <div id="index-entries">
23
+ </div>
24
+ </div>
25
+ </body>
26
+ </html>
data/docs/index.html ADDED
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ RDoc Documentation
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>RDoc Documentation</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="files/README_rdoc.html" name="docwin" />
23
+ </frameset>
24
+ </html>
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
data/lib/git-bro.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'git-bro/repository'
2
+ require 'git-bro/core_extensions'
2
3
 
3
4
  module GitBro
4
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
5
6
  end
@@ -12,9 +12,9 @@ module GitBro
12
12
  def do_serve
13
13
  case GitBro::TARGET_OS
14
14
  when 'mswin32'
15
- Process::create("ruby #{@options.gem_path}/bin/server.rb #{@options.repo_path}")
15
+ system "ruby #{@options.gem_path}/sinatra/app.rb #{@options.repo_path}"
16
16
  when 'linux'
17
- system "/usr/bin/env ruby #{@options.gem_path}/bin/server.rb #{@options.repo_path}"
17
+ system "/usr/bin/env ruby #{@options.gem_path}/sinatra/app.rb #{@options.repo_path}"
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,22 @@
1
+ class Time
2
+ def relative_to(time)
3
+ diff = time - self
4
+
5
+ return "#{diff.to_i} seconds ago" if diff < 60
6
+ return "#{(diff/60).to_i} minutes ago" if diff < 3600
7
+ return "#{(diff/3600).to_i} hours ago" if diff < 86400
8
+ return "#{(diff/86400).to_i} days ago" if diff < 604800
9
+
10
+ self.strftime("%B %d, %Y")
11
+ end
12
+ end
13
+
14
+ class String
15
+ def shortify(len = 40)
16
+ if self.length > len
17
+ return self[0..len-1] + "..."
18
+ end
19
+
20
+ self
21
+ end
22
+ end
@@ -4,9 +4,15 @@ module GitBro
4
4
  class Repository
5
5
  attr_reader :name
6
6
 
7
- def initialize(repo_path)
8
- @repo = Grit::Repo.new(repo_path)
9
- @name = @repo.path.split('/')[-2]
7
+ def initialize(repo_path, opts = nil)
8
+ @repo = Grit::Repo.new(repo_path, opts)
9
+ @name = begin
10
+ dirs = @repo.path.split('/')
11
+ dirs.delete_at(dirs.size - 1) if dirs[-1] == '.git'
12
+ dirs[-1]
13
+ end
14
+
15
+ @cache = {}
10
16
  end
11
17
 
12
18
  def path
@@ -22,60 +28,88 @@ module GitBro
22
28
  blobs.first.data
23
29
  end
24
30
 
25
- def tree(branch, paths)
26
- objs = []
27
- cur_time = Time.now
28
- paths.empty? ? prefix = "" : prefix = paths.first
29
-
30
- @repo.tree(branch, paths).trees.each do |t|
31
- lc = last_commit(branch, prefix + t.basename)
32
- objs << {
33
- :type => 'dir',
34
- :name => t.basename + '/',
35
- :sha => t.id,
31
+ def get_commit_info(branch, object_id, object_name, current_time)
32
+ if @cache.has_key?(object_id)
33
+ commit_info = @cache[object_id]
34
+ else
35
+ lc = last_commit(branch, object_name)
36
+ commit_info = {
36
37
  :author => lc.author.name,
37
- :date => relative(cur_time - lc.date, lc.date),
38
- :message => shortify(lc.message)
38
+ :commit_time => lc.date,
39
+ :message => lc.message.shortify
39
40
  }
41
+ @cache[object_id] = commit_info
40
42
  end
41
- @repo.tree(branch, paths).blobs.each do |b|
42
- lc = last_commit(branch, prefix + b.basename)
43
- objs << {
44
- :type => 'file',
45
- :name => b.basename,
46
- :sha => b.id,
47
- :author => lc.author.name,
48
- :date => relative(cur_time - lc.date, lc.date),
49
- :message => shortify(lc.message)
50
- }
43
+
44
+ commit_info[:age] = commit_info[:commit_time].relative_to(current_time)
45
+
46
+ return commit_info
47
+ end
48
+
49
+ def commits_info(branch, path)
50
+ commits = {}
51
+
52
+ cur_time = Time.now
53
+ paths = path.empty? ? [] : [].push(path + '/')
54
+ tree = @repo.tree(branch, paths)
55
+
56
+ tree.trees.each do |t|
57
+ object_id = t.id.to_sym
58
+ commits[object_id] = get_commit_info(branch, object_id, t.name, cur_time)
59
+ end
60
+
61
+ tree.blobs.each do |b|
62
+ object_id = b.id.to_sym
63
+ commits[object_id] = get_commit_info(branch, object_id, b.name, cur_time)
64
+ end
65
+
66
+ return commits
67
+ end
68
+
69
+ def tree(branch, paths)
70
+ objects = []
71
+ tree = @repo.tree(branch, paths)
72
+
73
+ tree.trees.each do |t|
74
+ object_info = { :type => 'dir', :name => t.basename + '/', :sha => t.id, :commit_info => @cache[t.id.to_sym] }
75
+ objects.push(object_info)
76
+ end
77
+ tree.blobs.each do |b|
78
+ object_info = { :type => 'file', :name => b.basename, :sha => b.id, :commit_info => @cache[b.id.to_sym] }
79
+ objects.push(object_info)
51
80
  end
52
81
 
53
- objs
82
+ return objects
54
83
  end
55
84
 
56
85
  def branches
57
86
  @repo.heads
58
87
  end
59
88
 
60
- protected
61
- # TODO: Check what returns log function if there is dir and file with equal names
62
- def last_commit(branch, filename)
63
- lc = @repo.log(branch, filename, {:n => 1})
64
- lc.empty? ? nil : lc.first
89
+ def log(branch, page, per_page = 20)
90
+ @repo.log(branch, nil, {:skip => page * per_page, :n => per_page})
65
91
  end
66
92
 
67
- def shortify(s)
68
- s.length > 40 ? s[0..38] + '...' : s
93
+ def commit(sha)
94
+ @repo.commit(sha)
69
95
  end
70
96
 
71
- def relative(diff, orig)
72
- return "#{diff.to_i} seconds ago" if diff < 60
73
- return "#{(diff/60).to_i} minutes ago" if diff < 3600
74
- return "#{(diff/3600).to_i} hours ago" if diff < 86400
75
- return "#{(diff/86400).to_i} days ago" if diff < 604800
97
+ def default_branch
98
+ branches = @repo.heads.collect!{|h| h.name }
99
+ return "master" if branches.include?("master")
76
100
 
77
- orig.strftime("%B %d, %Y")
101
+ branches.first
78
102
  end
79
103
 
104
+ def top_commit(branch)
105
+ @repo.commits(branch, 1).first
106
+ end
107
+
108
+ protected
109
+ # TODO: Check what returns log function if there is dir and file with equal names
110
+ def last_commit(branch, filename)
111
+ lc = @repo.log(branch, filename, {:n => 1})
112
+ lc.empty? ? nil : lc.first
113
+ end
80
114
  end
81
115
  end