git-story 0.0.3 → 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.
- data/lib/git-story +62 -37
- metadata +2 -2
data/lib/git-story
CHANGED
@@ -4,67 +4,92 @@ require 'set'
|
|
4
4
|
require 'grit'
|
5
5
|
require 'trollop'
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def describe(commit, suffix)
|
8
|
+
"#{commit.committed_date} #{commit.sha} #{commit.message.strip.split("\n").first} #{commit.committer} #{suffix}\n"
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def get_travel_path(current_commit, head, merge_commits, merge_commits_directions)
|
12
|
+
travel_path = ''
|
13
|
+
travel_path << "\n"
|
14
|
+
travel_path << "Possible path\n"
|
15
|
+
travel_path << "-------------\n"
|
15
16
|
|
16
|
-
|
17
|
+
travel_path << describe(current_commit, 'START')
|
17
18
|
i = (merge_commits.length - 1)
|
18
19
|
while(i >= 0)
|
19
|
-
#direction 0 indicates there was no branch change
|
20
|
-
|
20
|
+
# direction 0 indicates there was no branch change
|
21
|
+
travel_path << describe(merge_commits[i], 'MERGE') if(merge_commits_directions[i] != 0)
|
21
22
|
i -= 1
|
22
23
|
end
|
23
|
-
|
24
|
+
travel_path << describe(head, 'HEAD')
|
25
|
+
travel_path
|
24
26
|
end
|
25
27
|
|
26
28
|
def story(searched_sha, branch, repo)
|
29
|
+
travel_paths = Set.new
|
30
|
+
encountered_shas = Set.new
|
31
|
+
nb_commits = (`git rev-list #{branch} | wc -l`).chomp!.to_i
|
32
|
+
|
27
33
|
merge_commits = []
|
28
34
|
merge_commits_directions = []
|
29
|
-
processed_shas = Set.new
|
30
35
|
|
31
36
|
head = repo.commits(branch).first
|
32
37
|
next_commit = head
|
33
|
-
finished = false
|
34
38
|
|
35
|
-
while(!
|
39
|
+
while(!next_commit.nil?)
|
40
|
+
# move to next commit
|
36
41
|
current_commit = next_commit
|
37
42
|
|
38
|
-
#
|
39
|
-
|
43
|
+
# current commit is the one we're looking for
|
44
|
+
# collect travel paths
|
45
|
+
if(current_commit.sha == searched_sha)
|
46
|
+
travel_paths << get_travel_path(current_commit, head, merge_commits, merge_commits_directions)
|
47
|
+
end
|
40
48
|
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
if(merge_commits_directions.last == merge_commits.last.parents.length)
|
47
|
-
processed_shas << merge_commits.pop.sha
|
48
|
-
merge_commits_directions.pop
|
49
|
-
else
|
50
|
-
done = true
|
51
|
-
end
|
52
|
-
end
|
53
|
-
finished = merge_commits.empty?
|
54
|
-
next_commit = merge_commits.last.parents[merge_commits_directions.last] if !finished
|
49
|
+
# current commit has no parents
|
50
|
+
# add sha to set of encountered shas and jump back to last merge commit
|
51
|
+
if(current_commit.parents.length == 0)
|
52
|
+
encountered_shas << current_commit.sha
|
53
|
+
next_commit = merge_commits.last
|
55
54
|
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
# current commit only has 1 parent
|
56
|
+
# add sha to set of encountered shas and go to parent
|
57
|
+
elsif(current_commit.parents.length == 1)
|
58
|
+
encountered_shas << current_commit.sha
|
60
59
|
next_commit = current_commit.parents[0]
|
61
60
|
|
62
|
-
#
|
63
|
-
else
|
64
|
-
|
65
|
-
|
61
|
+
# current commit is merge commit
|
62
|
+
else(current_commit.parents.length > 1)
|
63
|
+
|
64
|
+
# newly encountered merge commit
|
65
|
+
# add sha to set of encountered shas, update merge commits and go to first parent
|
66
|
+
if(!encountered_shas.include?(current_commit.sha))
|
67
|
+
encountered_shas << current_commit.sha
|
68
|
+
merge_commits << current_commit
|
69
|
+
merge_commits_directions << 0
|
70
|
+
next_commit = merge_commits.last.parents[merge_commits_directions.last]
|
71
|
+
|
72
|
+
# previously encountered merge commit
|
73
|
+
# go to next parent if possible, otherwise jump back to last merge commit
|
74
|
+
else
|
75
|
+
if(merge_commits_directions.last < (merge_commits.last.parents.length - 1))
|
76
|
+
merge_commits_directions[merge_commits_directions.length - 1] += 1
|
77
|
+
next_commit = merge_commits.last.parents[merge_commits_directions.last]
|
78
|
+
else
|
79
|
+
merge_commits.pop
|
80
|
+
merge_commits_directions.pop
|
81
|
+
next_commit = merge_commits.last
|
82
|
+
end
|
83
|
+
end
|
66
84
|
end
|
85
|
+
|
86
|
+
# display progress
|
87
|
+
puts "progress: #{encountered_shas.length} / #{nb_commits}"
|
67
88
|
end
|
89
|
+
|
90
|
+
# display travel paths
|
91
|
+
travel_paths.each { |travel_path| puts travel_path }
|
92
|
+
puts "\n"
|
68
93
|
end
|
69
94
|
|
70
95
|
opts = Trollop::options do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-story
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grit
|