zitgit 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
- gem "grit", '~> 2.5.0', git: 'https://github.com/gitlabhq/grit.git', ref: '42297cdcee16284d2e4eff23d41377f52fc28b9d'
5
4
 
data/README.md CHANGED
@@ -6,17 +6,26 @@ Simple sinatra-based web-interface to view git repository history
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem "grit", '~> 2.5.0', git: 'https://github.com/gitlabhq/grit.git', ref: '42297cdcee16284d2e4eff23d41377f52fc28b9d'
10
9
  gem 'zitgit'
11
10
 
11
+ or install from GitHub:
12
+
13
+ gem 'zitgit', git: 'https://github.com/rsludge/zitgit.git'
14
+
12
15
  And then execute:
13
16
 
14
17
  $ bundle install
15
18
 
16
- You can not just run gem install zitgit because it has dependencies from GitHub
19
+ Or install with:
20
+
21
+ $ gem install zitgit
17
22
 
18
23
  ## Usage
19
24
 
20
25
  Just run `zitgit` from git repo folder and view your repository history on http://localhost:5555
21
26
 
22
27
  Or you can run it on different port with `zitgit -p <port_number>`
28
+
29
+ ## Develop
30
+
31
+ Clone repository from GitHub and run `bundle install`. Launch guard to manage assets.
@@ -0,0 +1,36 @@
1
+ module Grit
2
+ class Status
3
+ class StatusFile
4
+ def diff_string
5
+ old = @base.object(self.sha_repo)
6
+ new = @base.object(self.sha_index)
7
+ data_old = old.content.split(/\n/).map! { |e| e.chomp }
8
+ data_new = new.content.split(/\n/).map! { |e| e.chomp }
9
+ diffs = Difference::LCS.diff(data_old, data_new)
10
+ file_length_difference = 0
11
+ lines = 3
12
+ oldhunk = hunk = nil
13
+ output = "--- a/#{self.path}\n+++ b/#{self.path}"
14
+ format = :unified
15
+ diffs.each do |piece|
16
+ begin
17
+ hunk = Difference::LCS::Hunk.new(data_old, data_new, piece, lines, file_length_difference)
18
+ file_length_difference = hunk.file_length_difference
19
+ next unless oldhunk
20
+ if lines > 0 && hunk.overlaps?(oldhunk)
21
+ hunk.unshift(oldhunk)
22
+ else
23
+ output << oldhunk.diff(format)
24
+ end
25
+ ensure
26
+ oldhunk = hunk
27
+ output << "\n"
28
+ end
29
+ end
30
+ output << oldhunk.diff(format)
31
+ output << "\n"
32
+ output
33
+ end
34
+ end
35
+ end
36
+ end
data/lib/zitgit.rb CHANGED
@@ -1,54 +1,44 @@
1
- require_relative "zitgit/version"
2
- require 'bundler'
3
- Dir.chdir(File.dirname(__FILE__)) do
4
- Bundler.setup
5
- end
1
+ require_relative 'zitgit/version'
2
+ require_relative 'zitgit/helpers/views'
3
+ require_relative 'zitgit/helpers/git'
4
+ require_relative 'grit/status'
6
5
  require 'sinatra/base'
7
6
  require 'grit'
8
7
  require 'slim'
8
+ require 'base64'
9
9
 
10
10
  module Zitgit
11
11
  class Zitgit < Sinatra::Base
12
12
  configure do
13
13
  set :root, File.expand_path('..', File.dirname(__FILE__))
14
14
  end
15
-
16
- helpers do
17
- def heads(commit)
18
- repo = Grit::Repo.new('.')
19
- repo.heads.select{|head| head.commit.id == commit.id}
20
- end
21
-
22
- def remotes(commit)
23
- repo = Grit::Repo.new('.')
24
- repo.remotes.select{|head| head.commit.id == commit.id}
25
- end
26
-
27
- def tags(commit)
28
- repo = Grit::Repo.new('.')
29
- repo.tags.select{|head| head.commit.id == commit.id}
30
- end
31
- end
15
+ helpers ViewsHelpers
16
+ helpers GitHelpers
32
17
 
33
18
  get '/' do
34
- repo = Grit::Repo.new('.')
35
- @current_branch = Grit::Head.current(repo)
36
- @commits = repo.commits(@current_branch.name, 200)
19
+ @repo = Grit::Repo.new('.')
20
+ @current_branch = Grit::Head.current(@repo)
21
+ @commits = @repo.commits(@current_branch.name, 200)
37
22
  @last_commit = @commits[0]
38
- @repo_name = File.basename(repo.working_dir)
39
- @branches = repo.heads
40
- @remotes = repo.remotes
41
- @tags = repo.tags
42
- @index = repo.index
23
+ @repo_name = File.basename(@repo.working_dir)
24
+ @branches = @repo.heads
25
+ @remotes = @repo.remotes
26
+ @tags = @repo.tags
27
+ @index = @repo.index
43
28
  slim :index
44
29
  end
45
30
 
46
31
  get "/ref/:ref_name" do |ref_name|
47
- repo = Grit::Repo.new('')
48
- commits = repo.commits(ref_name, 200)
32
+ @repo = Grit::Repo.new('.')
33
+ commits = @repo.commits(ref_name, 200)
49
34
  slim :branch, :locals => { commits: commits }, :layout => false
50
35
  end
51
36
 
37
+ get "/status/" do
38
+ @repo = Grit::Repo.new('.')
39
+ slim :'status/list', :locals => {repo: @repo}, :layout => false
40
+ end
41
+
52
42
  run! if app_file == $0
53
43
  end
54
44
  end
@@ -0,0 +1,37 @@
1
+ module GitHelpers
2
+ def heads(commit)
3
+ repo = Grit::Repo.new('.')
4
+ repo.heads.select{|head| head.commit.id == commit.id}
5
+ end
6
+
7
+ def remotes(commit)
8
+ repo = Grit::Repo.new('.')
9
+ repo.remotes.select{|head| head.commit.id == commit.id}
10
+ end
11
+
12
+ def tags(commit)
13
+ repo = Grit::Repo.new('.')
14
+ repo.tags.select{|head| head.commit.id == commit.id}
15
+ end
16
+
17
+ def merge_commit?(commit)
18
+ commit.parents.count > 1
19
+ end
20
+
21
+ def large_commit?(commit)
22
+ commit.diffs.count > 20
23
+ end
24
+
25
+ def large_diff?(diff)
26
+ diff.diff.lines.count > 200
27
+ end
28
+
29
+ def is_head_ref(ref)
30
+ ref.name.split('/').index('HEAD')
31
+ end
32
+
33
+ def is_image(diff)
34
+ image_exts = ['.jpg', '.jpeg', '.png', '.gif']
35
+ image_exts.include?(File.extname(diff.a_path)) or image_exts.include?(File.extname(diff.b_path))
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ module ViewsHelpers
2
+ def strip_message(text, length)
3
+ text.length > length ? text[0, length] + '...' : text
4
+ end
5
+
6
+ def summ_line(line)
7
+ line.match(/@@\s+-([^\s]+)\s+\+([^\s]+)\s+@@/)
8
+ [Regexp.last_match(1), Regexp.last_match(2)].map{|item|
9
+ parts = item.split(',')
10
+ if parts.count == 2
11
+ parts[0] + '-' + (parts[0].to_i + parts[1].to_i).to_s
12
+ else
13
+ item
14
+ end
15
+ }.join(' -> ')
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Zitgit
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,43 +1,157 @@
1
1
  ChangeCommit = ($commit)->
2
- $target_commit = $commit.clone()
3
- $('.commits-table tr.selected').removeClass 'selected'
4
- $commit.parents('tr').addClass 'selected'
5
- $('.show_commit').html $target_commit
6
- UpdateDiffsWidth()
2
+ $target_commit = $commit.clone()
3
+ $('.commits-table tr.selected').removeClass 'selected'
4
+ $('.status').removeClass 'selected'
5
+ $commit.parents('tr').addClass 'selected'
6
+ $('.show_commit').html $target_commit
7
+ $('.show_commit .diffs li').niceScroll({
8
+ cursorcolor: '#ccc',
9
+ cursorwidth: 14,
10
+ })
11
+ UpdateDiffsWidth()
12
+
13
+ LoadStatus = ->
14
+ $('.commits-table tr.selected').removeClass 'selected'
15
+ $('.status').addClass 'selected'
16
+ $status_content = $('.status .status_content').clone()
17
+ $('.show_commit').html $status_content
18
+ $('.show_commit .diffs li').niceScroll({
19
+ cursorcolor: '#ccc',
20
+ cursorwidth: 14,
21
+ })
22
+ UpdateDiffsWidth()
7
23
 
8
24
  SetHeight = ->
9
25
  commit_offset = $('.show_commit').offset().top
10
26
  $('.show_commit').height(window.innerHeight - commit_offset)
11
27
  history_offset = $('.history').offset().top
12
28
  $('.history').height(window.innerHeight - history_offset)
13
-
14
29
 
15
30
  UpdateDiffsWidth = ->
16
- $('.show_commit .diffs li').each (index)->
17
- $(this).find('div').css('width', $(this)[0].scrollWidth)
31
+ $('.show_commit .diffs li').each (index)->
32
+ $(this).find('div').css('width', $(this)[0].scrollWidth)
18
33
 
19
- $ ->
34
+ SelectDiff = ($diff) ->
35
+ $('.show_commit .diff-names .selected').removeClass('selected')
36
+ $diff.addClass('selected')
37
+ if $diff.hasClass('all')
38
+ $('.show_commit .diffs li').removeClass('hidden')
39
+ else
40
+ index = $diff.index() - 1
41
+ $('.show_commit .diffs li').addClass('hidden')
42
+ $('.show_commit .diffs li:eq('+index+')').removeClass('hidden')
43
+
44
+ ChangeBranch = ($link)->
45
+ timeout = setTimeout ->
46
+ $('.loader').show()
47
+ $('.main').hide()
48
+ , 1500
49
+ $.get $link.attr('href'), (data)->
50
+ clearTimeout(timeout)
51
+ $('.loader').hide()
52
+ $('.current_branch').text ''
53
+ if $link.parents('.ref_label').length
54
+ list_class = $link.parents('.ref_label').attr('data-dropdown-name')
55
+ $('.dropdown.'+list_class+'').parent('.has-dropdown').find('.current_branch').text $link.text()
56
+ else
57
+ $link.parents('.has-dropdown').find('.current_branch').text $link.text()
58
+ $('.commits-table').replaceWith data
59
+ $('.main').show()
60
+ ChangeCommit $('.commits-table tbody tr:first .commit')
61
+
62
+ SwitchBranch = ->
20
63
  $('.top-bar .dropdown li a').on 'click', (e) ->
21
64
  e.preventDefault()
22
- $link = $(this)
23
- timeout = setTimeout ->
24
- $('.loader').show()
25
- $('.main').hide()
26
- , 1500
27
- $.get $link.attr('href'), (data)->
28
- clearTimeout(timeout)
29
- $('.loader').hide()
30
- $('.current_branch').text ''
31
- $link.parents('.has-dropdown').find('.current_branch').text $link.text()
32
- $('.commits-table').replaceWith data
33
- $('.main').show()
34
- ChangeCommit $('.commits-table tbody tr:first .commit')
65
+ ChangeBranch($(this))
66
+ $('body').on 'click', '.ref_label a', (e) ->
67
+ e.preventDefault()
68
+ ChangeBranch($(this))
69
+
70
+ RefreshStatus = ->
71
+ $.get '/status/', (data)->
72
+ $('.status').replaceWith data
73
+
74
+ RefreshContent = ->
75
+ RefreshStatus()
76
+ $('.current_branch').each (index)->
77
+ if $(this).text() != ''
78
+ branch_name = $(this).text()
79
+ $(this).parent('.has-dropdown').find('.dropdown li a').each (index)->
80
+ if $(this).text() == branch_name
81
+ ChangeBranch($(this))
82
+ return false
83
+ return false
84
+
85
+ SelectRow = ($row) ->
86
+ if $row.offset().top < $('.history').offset().top
87
+ current_scroll = $('.history').scrollTop()
88
+ $('.history').scrollTop(current_scroll + $row.offset().top - $('.history').offset().top)
89
+ offset = $row.offset().top - $('.history').offset().top
90
+ if offset + $row.outerHeight() > $('.history').outerHeight()
91
+ current_scroll = $('.history').scrollTop()
92
+ $('.history').scrollTop(current_scroll + offset + $row.outerHeight() - $('.history').outerHeight())
93
+ ChangeCommit $row.find('.commit')
94
+
95
+ TableArrows = ->
96
+ motions = [38, 40, 33, 34, 35, 36]
97
+ $('.history').on 'keydown', (e)->
98
+ if motions.indexOf(e.keyCode) == -1
99
+ return
100
+ e.preventDefault()
101
+ e.stopPropagation()
102
+ if e.keyCode == 38 #up
103
+ $next = $('.commits-table tr.selected').prev()
104
+ else if e.keyCode == 40 #down
105
+ $next = $('.commits-table tr.selected').next()
106
+ else if e.keyCode == 33 #page up
107
+ $next_rows = $('.commits-table tr.selected').prevAll()
108
+ if $next_rows.length >= 10
109
+ $next = $next_rows.eq(9)
110
+ else
111
+ $next = $next_rows.last()
112
+ else if e.keyCode == 34 #page down
113
+ $next_rows = $('.commits-table tr.selected').nextAll()
114
+ if $next_rows.length >= 10
115
+ $next = $next_rows.eq(9)
116
+ else
117
+ $next = $next_rows.last()
118
+ else if e.keyCode == 36 #home
119
+ $next = $('.commits-table tbody tr:first')
120
+ else if e.keyCode == 35 #end
121
+ $next = $('.commits-table tr:last')
122
+ if $next and $next.length > 0
123
+ SelectRow($next)
35
124
 
125
+ CommitArrows = ->
126
+ motions = [38, 40]
127
+ $('.show_commit').on 'keydown', (e)->
128
+ if motions.indexOf(e.keyCode) == -1
129
+ return
130
+ e.preventDefault()
131
+ e.stopPropagation()
132
+ if e.keyCode == 38 #up
133
+ $next = $('.show_commit .diff-names li.selected').prev()
134
+ else if e.keyCode == 40 #down
135
+ $next = $('.show_commit .diff-names li.selected').next()
136
+ if $next and $next.length > 0
137
+ SelectDiff($next)
138
+
139
+ $ ->
36
140
  $('.history').on 'click', '.commits-table tr', (e)->
37
141
  ChangeCommit $(this).find('.commit')
142
+ $('.history').on 'click', '.status-link', (e)->
143
+ e.preventDefault()
144
+ LoadStatus()
145
+ $('.refresh').on 'click', (e)->
146
+ e.preventDefault()
147
+ RefreshContent()
148
+ $('.show_commit').on 'click', '.diff-names li', (e)->
149
+ SelectDiff $(this)
38
150
 
39
- UpdateDiffsWidth()
151
+ SwitchBranch()
40
152
  SetHeight()
153
+ TableArrows()
154
+ CommitArrows()
41
155
 
42
156
  $(window).resize ->
43
157
  SetHeight()
@@ -52,7 +166,8 @@ $ ->
52
166
  railalign: 'left',
53
167
  horizrailenabled: false
54
168
  })
55
- $('.diffs li').niceScroll({
169
+ $('.show_commit .diffs li').niceScroll({
56
170
  cursorcolor: '#ccc',
57
171
  cursorwidth: 14,
58
172
  })
173
+ UpdateDiffsWidth()
data/public/css/app.css CHANGED
@@ -3952,8 +3952,11 @@ a.th {
3952
3952
 
3953
3953
  .top-bar {
3954
3954
  z-index: 6; }
3955
+ .top-bar .refresh img {
3956
+ position: relative;
3957
+ top: 8px; }
3955
3958
 
3956
- .row .history.columns {
3959
+ .main .history.columns {
3957
3960
  padding: 0 0 0 15px; }
3958
3961
 
3959
3962
  .ref_label {
@@ -3962,15 +3965,26 @@ a.th {
3962
3965
  border-radius: 12px;
3963
3966
  padding: 2px 4px;
3964
3967
  float: left; }
3968
+ .ref_label a {
3969
+ color: #000; }
3965
3970
 
3966
3971
  .branch_label {
3967
- background: yellow; }
3972
+ background: #ffeeee;
3973
+ border-color: #581313; }
3974
+ .branch_label a {
3975
+ color: #581313; }
3968
3976
 
3969
3977
  .remote_label {
3970
- background: red; }
3978
+ background: #ffe3e3;
3979
+ border-color: #b32222; }
3980
+ .remote_label a {
3981
+ color: #b32222; }
3971
3982
 
3972
3983
  .tag_label {
3973
- background: #e77a1c; }
3984
+ background: #ffe6bc;
3985
+ border-color: #ff9800; }
3986
+ .tag_label a {
3987
+ color: #ff9800; }
3974
3988
 
3975
3989
  .commits-table {
3976
3990
  table-layout: fixed;
@@ -3988,9 +4002,16 @@ a.th {
3988
4002
  .commits-table .badges .ref_label {
3989
4003
  font-size: 12px;
3990
4004
  border-radius: 8px;
3991
- padding: 0 2px; }
4005
+ padding: 0 2px;
4006
+ max-width: 134px;
4007
+ word-wrap: break-word;
4008
+ text-align: center; }
4009
+ .commits-table .badges .sha {
4010
+ font-size: 10px; }
3992
4011
  .commits-table .author {
3993
4012
  width: 180px; }
4013
+ .commits-table .message div {
4014
+ max-height: 56px; }
3994
4015
  .commits-table tbody tr.selected {
3995
4016
  background: #c3e2ff; }
3996
4017
  .commits-table tbody tr.selected td {
@@ -4009,15 +4030,19 @@ a.th {
4009
4030
  padding-top: 14px;
4010
4031
  list-style-type: none; }
4011
4032
  .diff-names li {
4012
- margin-bottom: -8px; }
4033
+ margin-bottom: -4px;
4034
+ padding: 0 4px; }
4013
4035
  .diff-names li .new_file {
4014
4036
  color: green; }
4015
4037
  .diff-names li .deleted {
4016
4038
  color: red; }
4039
+ .diff-names .selected {
4040
+ background: #a7d5ff; }
4017
4041
 
4018
4042
  .diffs {
4019
4043
  background: #fff;
4020
- list-style-type: none; }
4044
+ list-style-type: none;
4045
+ font-family: monospace; }
4021
4046
  .diffs li {
4022
4047
  border-bottom: solid #ddd 8px;
4023
4048
  overflow-x: scroll; }
@@ -4026,20 +4051,26 @@ a.th {
4026
4051
  font-size: 14px; }
4027
4052
  .diffs li .diff-first-line {
4028
4053
  font-weight: bold;
4029
- background: #A7B5FF;
4030
- border-bottom: 1px solid black; }
4054
+ background: #eee;
4055
+ border-bottom: 1px solid #777; }
4031
4056
  .diffs li .diff-summ-line {
4032
- background: #A7B5FF;
4057
+ background: #eee;
4033
4058
  font-weight: bold; }
4034
4059
  .diffs li .diff-added-line {
4035
4060
  color: #096707;
4036
4061
  background: #87f49f; }
4062
+ .diffs li .diff-added-line .trailing {
4063
+ background: #036420; }
4037
4064
  .diffs li .diff-removed-line {
4038
4065
  position: relative;
4039
4066
  left: 0;
4040
4067
  right: 0;
4041
4068
  color: #742b2b;
4042
4069
  background: #ffb1cb; }
4070
+ .diffs li .diff-removed-line .trailing {
4071
+ background: #c10000; }
4072
+ .diffs img {
4073
+ display: block; }
4043
4074
 
4044
4075
  .hidden {
4045
4076
  display: none; }
@@ -4049,19 +4080,30 @@ a.th {
4049
4080
  background: #ddd;
4050
4081
  border-radius: 16px; }
4051
4082
  .show_commit .commit .author_info {
4052
- /*width: 50%;*/
4053
4083
  float: left;
4054
- font-weight: bold; }
4084
+ font-weight: bold;
4085
+ clear: left;
4086
+ color: #eee;
4087
+ text-shadow: 1px 1px 0px #333, 1px -1px 0px #333, -1px 1px 0px #333, -1px -1px 0px #333; }
4055
4088
  .show_commit .commit .commit_sha {
4056
4089
  margin-bottom: 14px;
4057
- margin-top: -14px;
4058
- clear: left; }
4059
- .show_commit .commit .stats {
4090
+ clear: left;
4091
+ float: left; }
4092
+ .show_commit .commit .commit_date {
4093
+ margin-bottom: 14px;
4060
4094
  float: right; }
4095
+ .show_commit .commit .stats {
4096
+ float: right;
4097
+ text-align: right; }
4061
4098
  .show_commit .commit .stats .additions {
4062
4099
  color: green; }
4063
4100
  .show_commit .commit .stats .deletions {
4064
4101
  color: red; }
4102
+ .show_commit .commit .stats .merge_commit {
4103
+ font-weight: bold;
4104
+ position: relative;
4105
+ top: 8px;
4106
+ color: #0300ff; }
4065
4107
 
4066
4108
  .loader {
4067
4109
  margin: 0 auto;
@@ -4069,3 +4111,21 @@ a.th {
4069
4111
  height: 64px;
4070
4112
  background: url("/images/loader.gif") no-repeat;
4071
4113
  display: none; }
4114
+
4115
+ .status {
4116
+ margin-bottom: 8px;
4117
+ padding: 4px 0; }
4118
+ .status .status_content {
4119
+ display: none; }
4120
+ .status .status-link {
4121
+ display: block;
4122
+ font-weight: bold;
4123
+ color: #000;
4124
+ padding-left: 16px;
4125
+ font-size: 20px; }
4126
+ .status.selected {
4127
+ background: #c3e2ff;
4128
+ border-bottom: 2px solid #78c3ff;
4129
+ border-top: 2px solid #78c3ff;
4130
+ border-left: 1px solid #78c3ff;
4131
+ border-right: 1px solid #78c3ff; }