Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3011ac41
Commit
3011ac41
authored
Apr 03, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring and cleanup. Removed unused commit finders
parent
9f4fde04
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
119 additions
and
176 deletions
+119
-176
app/controllers/repositories_controller.rb
app/controllers/repositories_controller.rb
+1
-1
app/controllers/wikis_controller.rb
app/controllers/wikis_controller.rb
+3
-3
app/models/gollum_wiki.rb
app/models/gollum_wiki.rb
+0
-6
app/models/network/graph.rb
app/models/network/graph.rb
+10
-13
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+6
-66
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+23
-13
lib/gitlab/git/stats.rb
lib/gitlab/git/stats.rb
+75
-0
lib/gitlab/git/tree.rb
lib/gitlab/git/tree.rb
+1
-1
lib/gitlab/git_stats.rb
lib/gitlab/git_stats.rb
+0
-73
No files found.
app/controllers/repositories_controller.rb
View file @
3011ac41
...
...
@@ -17,7 +17,7 @@ class RepositoriesController < ProjectResourceController
end
def
stats
@stats
=
Gitlab
::
GitStats
.
new
(
@repository
.
raw
,
@repository
.
root_ref
)
@stats
=
Gitlab
::
Git
::
Stats
.
new
(
@repository
.
raw
,
@repository
.
root_ref
)
@graph
=
@stats
.
graph
end
...
...
app/controllers/wikis_controller.rb
View file @
3011ac41
...
...
@@ -49,9 +49,9 @@ class WikisController < ProjectResourceController
end
def
history
unless
@wiki
=
@gollum_wiki
.
find_page
(
params
[
:id
])
redirect_to
project_wiki_path
(
@project
,
:home
),
notice:
"Page not found"
end
@wiki
=
@gollum_wiki
.
find_page
(
params
[
:id
])
redirect_to
(
project_wiki_path
(
@project
,
:home
),
notice:
"Page not found"
)
unless
@wiki
end
def
destroy
...
...
app/models/gollum_wiki.rb
View file @
3011ac41
...
...
@@ -47,12 +47,6 @@ class GollumWiki
wiki
.
pages
.
map
{
|
page
|
WikiPage
.
new
(
self
,
page
,
true
)
}
end
# Returns the last 30 Commit objects across the entire
# repository.
def
recent_history
Gitlab
::
Git
::
Commit
.
fresh_commits
(
wiki
.
repo
,
30
)
end
# Finds a page within the repository based on a tile
# or slug.
#
...
...
app/models/network/graph.rb
View file @
3011ac41
...
...
@@ -25,10 +25,9 @@ module Network
def
collect_commits
refs_cache
=
build_refs_cache
find_commits
(
count_to_display_commit_in_center
)
.
map
do
|
commit
|
# Decorate with app/model/network/commit.rb
Network
::
Commit
.
new
(
commit
,
refs_cache
[
commit
.
id
])
find_commits
(
count_to_display_commit_in_center
).
map
do
|
commit
|
# Decorate with app/model/network/commit.rb
Network
::
Commit
.
new
(
commit
,
refs_cache
[
commit
.
id
])
end
end
...
...
@@ -93,15 +92,13 @@ module Network
end
def
find_commits
(
skip
=
0
)
Grit
::
Commit
.
find_all
(
@repo
,
nil
,
{
date_order:
true
,
max_count:
self
.
class
.
max_count
,
skip:
skip
}
)
opts
=
{
date_order:
true
,
max_count:
self
.
class
.
max_count
,
skip:
skip
}
Grit
::
Commit
.
find_all
(
@repo
,
opts
,
nil
)
end
def
commits_sort_by_ref
...
...
lib/gitlab/git/commit.rb
View file @
3011ac41
...
...
@@ -12,70 +12,6 @@ module Gitlab
delegate
:parents
,
:diffs
,
:tree
,
:stats
,
:to_patch
,
to: :raw_commit
class
<<
self
def
serialize_keys
%w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids)
end
def
find_or_first
(
repo
,
commit_id
=
nil
,
root_ref
)
commit
=
if
commit_id
repo
.
commit
(
commit_id
)
else
repo
.
commits
(
root_ref
).
first
end
Commit
.
new
(
commit
)
if
commit
end
def
fresh_commits
(
repo
,
n
=
10
)
commits
=
repo
.
heads
.
map
do
|
h
|
repo
.
commits
(
h
.
name
,
n
).
map
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
[
0
...
n
]
end
def
commits_with_refs
(
repo
,
n
=
20
)
commits
=
repo
.
branches
.
map
{
|
ref
|
Commit
.
new
(
ref
.
commit
,
ref
)
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
[
0
..
n
]
end
def
commits_since
(
repo
,
date
)
commits
=
repo
.
heads
.
map
do
|
h
|
repo
.
log
(
h
.
name
,
nil
,
since:
date
).
each
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
end
def
commits
(
repo
,
ref
,
path
=
nil
,
limit
=
nil
,
offset
=
nil
)
if
path
repo
.
log
(
ref
,
path
,
max_count:
limit
,
skip:
offset
)
elsif
limit
&&
offset
repo
.
commits
(
ref
,
limit
,
offset
)
else
repo
.
commits
(
ref
)
end
.
map
{
|
c
|
Commit
.
new
(
c
)
}
end
def
commits_between
(
repo
,
from
,
to
)
repo
.
commits_between
(
from
,
to
).
map
{
|
c
|
Commit
.
new
(
c
)
}
end
end
def
initialize
(
raw_commit
,
head
=
nil
)
raise
"Nil as raw commit passed"
unless
raw_commit
...
...
@@ -88,6 +24,10 @@ module Gitlab
@head
=
head
end
def
serialize_keys
%w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids)
end
def
sha
id
end
...
...
@@ -143,7 +83,7 @@ module Gitlab
def
to_hash
hash
=
{}
keys
=
Commit
.
serialize_keys
keys
=
serialize_keys
keys
.
each
do
|
key
|
hash
[
key
]
=
send
(
key
)
...
...
@@ -172,7 +112,7 @@ module Gitlab
end
def
init_from_hash
(
hash
)
Commit
.
serialize_keys
.
each
do
|
key
|
serialize_keys
.
each
do
|
key
|
send
(
:"
#{
key
}
="
,
hash
[
key
])
end
end
...
...
lib/gitlab/git/repository.rb
View file @
3011ac41
...
...
@@ -48,31 +48,41 @@ module Gitlab
end
def
commit
(
commit_id
=
nil
)
Gitlab
::
Git
::
Commit
.
find_or_first
(
repo
,
commit_id
,
root_ref
)
end
commit
=
if
commit_id
repo
.
commit
(
commit_id
)
else
repo
.
commits
(
root_ref
).
first
end
def
fresh_commits
(
n
=
10
)
Gitlab
::
Git
::
Commit
.
fresh_commits
(
repo
,
n
)
Commit
.
new
(
commit
)
if
commit
end
def
commits_with_refs
(
n
=
20
)
Gitlab
::
Git
::
Commit
.
commits_with_refs
(
repo
,
n
)
end
commits
=
repo
.
branches
.
map
{
|
ref
|
Commit
.
new
(
ref
.
commit
,
ref
)
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
def
commits_since
(
date
)
Gitlab
::
Git
::
Commit
.
commits_since
(
repo
,
date
)
commits
[
0
..
n
]
end
def
commits
(
ref
,
path
=
nil
,
limit
=
nil
,
offset
=
nil
)
Gitlab
::
Git
::
Commit
.
commits
(
repo
,
ref
,
path
,
limit
,
offset
)
if
path
repo
.
log
(
ref
,
path
,
max_count:
limit
,
skip:
offset
)
elsif
limit
&&
offset
repo
.
commits
(
ref
,
limit
,
offset
)
else
repo
.
commits
(
ref
)
end
.
map
{
|
c
|
Commit
.
new
(
c
)
}
end
def
last_commit_for
(
ref
,
path
=
nil
)
commits
(
ref
,
path
,
1
).
first
def
commits_between
(
from
,
to
)
repo
.
commits_between
(
from
,
to
).
map
{
|
c
|
Commit
.
new
(
c
)
}
end
def
commits_between
(
from
,
to
)
Gitlab
::
Git
::
Commit
.
commits_between
(
repo
,
from
,
to
)
def
last_commit_for
(
ref
,
path
=
nil
)
commits
(
ref
,
path
,
1
).
first
end
# Returns an Array of branch names
...
...
lib/gitlab/git/stats.rb
0 → 100644
View file @
3011ac41
module
Gitlab
module
Git
class
Stats
attr_accessor
:repo
,
:ref
def
initialize
repo
,
ref
@repo
,
@ref
=
repo
,
ref
end
def
authors
@authors
||=
collect_authors
end
def
commits_count
@commits_count
||=
repo
.
commit_count
(
ref
)
end
def
files_count
args
=
[
ref
,
'-r'
,
'--name-only'
]
repo
.
git
.
run
(
nil
,
'ls-tree'
,
nil
,
{},
args
).
split
(
"
\n
"
).
count
end
def
authors_count
authors
.
size
end
def
graph
@graph
||=
build_graph
end
protected
def
collect_authors
shortlog
=
repo
.
git
.
shortlog
({
e:
true
,
s:
true
},
ref
)
authors
=
[]
lines
=
shortlog
.
split
(
"
\n
"
)
lines
.
each
do
|
line
|
data
=
line
.
split
(
"
\t
"
)
commits
=
data
.
first
author
=
Grit
::
Actor
.
from_string
(
data
.
last
)
authors
<<
OpenStruct
.
new
(
name:
author
.
name
,
email:
author
.
email
,
commits:
commits
.
to_i
)
end
authors
.
sort_by
(
&
:commits
).
reverse
end
def
build_graph
n
=
4
from
,
to
=
(
Date
.
today
-
n
.
weeks
),
Date
.
today
args
=
[
'--all'
,
"--since=
#{
from
.
to_s
(
:date
)
}
"
,
'--format=%ad'
]
rev_list
=
repo
.
git
.
run
(
nil
,
'rev-list'
,
nil
,
{},
args
).
split
(
"
\n
"
)
commits_dates
=
rev_list
.
values_at
(
*
rev_list
.
each_index
.
select
{
|
i
|
i
.
odd?
})
commits_dates
=
commits_dates
.
map
{
|
date_str
|
Time
.
parse
(
date_str
).
to_date
.
to_s
(
:date
)
}
commits_per_day
=
from
.
upto
(
to
).
map
do
|
day
|
commits_dates
.
count
(
day
.
to_date
.
to_s
(
:date
))
end
OpenStruct
.
new
(
labels:
from
.
upto
(
to
).
map
{
|
day
|
day
.
stamp
(
'Aug 23'
)
},
commits:
commits_per_day
,
weeks:
n
)
end
end
end
end
lib/gitlab/git/tree.rb
View file @
3011ac41
...
...
@@ -38,7 +38,7 @@ module Gitlab
end
def
readme
@readme
||=
entries
.
find
{
|
c
|
c
.
is_a?
(
Grit
::
Blob
)
and
c
.
name
=~
/^readme/i
}
@readme
||=
blobs
.
find
{
|
c
|
c
.
name
=~
/^readme/i
}
end
protected
...
...
lib/gitlab/git_stats.rb
deleted
100644 → 0
View file @
9f4fde04
module
Gitlab
class
GitStats
attr_accessor
:repo
,
:ref
def
initialize
repo
,
ref
@repo
,
@ref
=
repo
,
ref
end
def
authors
@authors
||=
collect_authors
end
def
commits_count
@commits_count
||=
repo
.
commit_count
(
ref
)
end
def
files_count
args
=
[
ref
,
'-r'
,
'--name-only'
]
repo
.
git
.
run
(
nil
,
'ls-tree'
,
nil
,
{},
args
).
split
(
"
\n
"
).
count
end
def
authors_count
authors
.
size
end
def
graph
@graph
||=
build_graph
end
protected
def
collect_authors
shortlog
=
repo
.
git
.
shortlog
({
e:
true
,
s:
true
},
ref
)
authors
=
[]
lines
=
shortlog
.
split
(
"
\n
"
)
lines
.
each
do
|
line
|
data
=
line
.
split
(
"
\t
"
)
commits
=
data
.
first
author
=
Grit
::
Actor
.
from_string
(
data
.
last
)
authors
<<
OpenStruct
.
new
(
name:
author
.
name
,
email:
author
.
email
,
commits:
commits
.
to_i
)
end
authors
.
sort_by
(
&
:commits
).
reverse
end
def
build_graph
n
=
4
from
,
to
=
(
Date
.
today
-
n
.
weeks
),
Date
.
today
args
=
[
'--all'
,
"--since=
#{
from
.
to_s
(
:date
)
}
"
,
'--format=%ad'
]
rev_list
=
repo
.
git
.
run
(
nil
,
'rev-list'
,
nil
,
{},
args
).
split
(
"
\n
"
)
commits_dates
=
rev_list
.
values_at
(
*
rev_list
.
each_index
.
select
{
|
i
|
i
.
odd?
})
commits_dates
=
commits_dates
.
map
{
|
date_str
|
Time
.
parse
(
date_str
).
to_date
.
to_s
(
:date
)
}
commits_per_day
=
from
.
upto
(
to
).
map
do
|
day
|
commits_dates
.
count
(
day
.
to_date
.
to_s
(
:date
))
end
OpenStruct
.
new
(
labels:
from
.
upto
(
to
).
map
{
|
day
|
day
.
stamp
(
'Aug 23'
)
},
commits:
commits_per_day
,
weeks:
n
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment