git-wayback-machine 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 506871b142bb9a734b7c0fcd44dadbdbf27fa2c2
4
+ data.tar.gz: 3755bb82db5b3976a7512d6bea86388658153fb8
5
+ SHA512:
6
+ metadata.gz: 3de03fc5e7279a60143c3ee8c5a22d9640009792b24c6901264ed09f73e7b094bedaf807ca84be74e9a3a8755e121194d0c365b3c9cbf6e0b62c8f7917ddfab4
7
+ data.tar.gz: 352e37d74d38217be7d5d60645c6ddc6d120ca3b984bdeeaeea32eb96aec0d5326c8d41ce87d867d49cebb9e37357df12cb09700b96b9749cf5e00393fe31bda
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git-wayback-machine.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,15 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git-wayback-machine (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ bundler (~> 1.9)
15
+ git-wayback-machine!
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Git Wayback Machine
2
+
3
+ A handy dandy tool to quickly navigate a project's state through it's GIT history
4
+
5
+ ![Screenshot](./screenshot.png)
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'git-wayback-machine'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install git-wayback-machine
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
27
+
28
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/MadRabbit/git-wayback-machine/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
37
+
38
+ ## Copyright & License
39
+
40
+ All code in this repository is released under the terms of the MIT License
41
+
42
+ Copyright (C) 2015 Nikolay Nemshilov
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/git-wayback-machine"
4
+
5
+ GitWaybackMachine.boot
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git_wayback_machine/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git-wayback-machine"
8
+ spec.version = GitWaybackMachine::VERSION
9
+ spec.authors = ["Nikolay Nemshilov"]
10
+ spec.email = ["nemshilov@gmail.com"]
11
+ spec.licenses = ["MIT"]
12
+
13
+ spec.summary = "Wayback machine to navigate GIT log"
14
+ spec.description = "Wayback machine to navigate GIT log, for real!"
15
+ spec.homepage = "https://github.com/MadRabbit/git-wayback-machine"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ end
@@ -0,0 +1 @@
1
+ require_relative "./git_wayback_machine"
@@ -0,0 +1,44 @@
1
+ module GitWaybackMachine
2
+
3
+ class Controls
4
+
5
+ def initialize
6
+ end
7
+
8
+ def on_event(&callback)
9
+ while true
10
+ case read_key
11
+ when "\e[A" then callback.call(:up) # UP
12
+ when "\e[B" then callback.call(:down) # DOWN
13
+ when "\r", "\n" then callback.call(:enter) # ENTER
14
+ when "\u0003", "\e" # Ctrl+C, ESC
15
+ exit(0)
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def read_key
23
+ old_state = `stty -g`
24
+ `stty raw -echo`
25
+
26
+ c = STDIN.getc.chr
27
+
28
+ if c == "\e" # reading escape sequences
29
+ extra_thread = Thread.new do
30
+ c += STDIN.getc.chr + STDIN.getc.chr
31
+ end
32
+ extra_thread.join(0.001)
33
+ extra_thread.kill
34
+ end
35
+
36
+ c
37
+
38
+ ensure
39
+ `stty #{old_state}`
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,38 @@
1
+ module GitWaybackMachine
2
+
3
+ class Engine
4
+ def initialize
5
+ @history = GitWaybackMachine::History.new
6
+ @navigator = GitWaybackMachine::Navigator.new(@history)
7
+ end
8
+
9
+ def start!
10
+ stash!
11
+
12
+ @navigator.on_change do |commit|
13
+ move_to commit
14
+ end
15
+
16
+ rescue Interrupt => e
17
+ nil # that's cool
18
+ ensure
19
+ rollback!
20
+ end
21
+
22
+ def move_to(entry)
23
+ `git reset --hard #{entry.sha}`
24
+ end
25
+
26
+ def stash!
27
+ @stash = `git stash -u`
28
+ end
29
+
30
+ def rollback!
31
+ puts "\rJumping back to the reality!"
32
+ move_to @history[0]
33
+ `git stash pop` unless @stash.include?("No local changes to save")
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,26 @@
1
+ module GitWaybackMachine
2
+
3
+ class History < Array
4
+ SIZE = 200
5
+
6
+ def initialize
7
+ super raw_entries.map { |entry| Entry.new *entry }
8
+ end
9
+
10
+ class Entry < Struct.new(:sha, :name, :time, :comment)
11
+ def to_s
12
+ "\e[33m#{sha}\e[37m | \e[35m#{name} \e[36m(#{time})\e[37m - #{comment}\e[0m"
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def raw_entries
19
+ `git log --pretty=format:'%h|%an|%cr|%s' --graph -#{SIZE}`.split("\n").map do |entry|
20
+ entry.sub(/\A\s*\*\s*/, "").split("|")
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,78 @@
1
+ module GitWaybackMachine
2
+
3
+ class Navigator
4
+ WINDOW_SIZE = 10 # the number of entries to show
5
+
6
+ def initialize(history)
7
+ @history = history
8
+ @current_entry = @history[0]
9
+ @controls = GitWaybackMachine::Controls.new
10
+ end
11
+
12
+ def on_change(&callback)
13
+ render
14
+
15
+ @controls.on_event do |event|
16
+ case event
17
+ when :up then @current_entry = prev_entry
18
+ when :down then @current_entry = next_entry
19
+ end
20
+
21
+ callback.call(@current_entry)
22
+ cleanup
23
+ render
24
+ end
25
+
26
+ ensure
27
+ cleanup
28
+ end
29
+
30
+ def render
31
+ puts intro_text
32
+
33
+ entries_slice.each do |entry|
34
+ if entry == @current_entry
35
+ puts " \e[37;1m#{entry}\e[0m"
36
+ else
37
+ puts " \e[37;2m#{entry}\e[0m"
38
+ end
39
+ end
40
+ end
41
+
42
+ def cleanup
43
+ navigator_size = entries_slice.size + 2
44
+ print "\r\e[#{navigator_size}A"
45
+ print (" " * 120 + "\n") * navigator_size
46
+ print "\r\e[#{navigator_size}A"
47
+ end
48
+
49
+ private
50
+
51
+ def intro_text
52
+ " \e[37;2mUse \e[0m\e[37;0mUP\e[0m\e[37;2m and \e[0m\e[37;1mDOWN\e[0m\e[37;2m keys to switch between commits:\n\e[0m"
53
+ end
54
+
55
+ def prev_entry
56
+ index = @history.index(@current_entry)
57
+ index == 0 ? @current_entry : @history[index-1]
58
+ end
59
+
60
+ def next_entry
61
+ index = @history.index(@current_entry)
62
+ index == @history.size-1 ? @current_entry : @history[index+1]
63
+ end
64
+
65
+ def entries_slice
66
+ return [] if @history.size == 0
67
+
68
+ index = @history.index(@current_entry)
69
+ start = index - WINDOW_SIZE / 2
70
+ start = @history.size - WINDOW_SIZE if start > @history.size - WINDOW_SIZE
71
+ start = 0 if start < 0
72
+
73
+ @history.slice(start, WINDOW_SIZE)
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -0,0 +1,3 @@
1
+ module GitWaybackMachine
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ module GitWaybackMachine
2
+
3
+ def self.boot
4
+ Engine.new.tap { |e| e.start! }
5
+ end
6
+
7
+ end
8
+
9
+ require_relative "./git_wayback_machine/version"
10
+ require_relative "./git_wayback_machine/engine"
11
+ require_relative "./git_wayback_machine/history"
12
+ require_relative "./git_wayback_machine/navigator"
13
+ require_relative "./git_wayback_machine/controls"
data/screenshot.png ADDED
Binary file
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-wayback-machine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Nemshilov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ description: Wayback machine to navigate GIT log, for real!
28
+ email:
29
+ - nemshilov@gmail.com
30
+ executables:
31
+ - git-wayback-machine
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README.md
39
+ - bin/git-wayback-machine
40
+ - git-wayback-machine.gemspec
41
+ - lib/git-wayback-machine.rb
42
+ - lib/git_wayback_machine.rb
43
+ - lib/git_wayback_machine/controls.rb
44
+ - lib/git_wayback_machine/engine.rb
45
+ - lib/git_wayback_machine/history.rb
46
+ - lib/git_wayback_machine/navigator.rb
47
+ - lib/git_wayback_machine/version.rb
48
+ - screenshot.png
49
+ homepage: https://github.com/MadRabbit/git-wayback-machine
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.5
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Wayback machine to navigate GIT log
73
+ test_files: []