ghq-cache 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/ghq/cache/builder.rb +25 -22
- data/lib/ghq/cache/cli.rb +7 -0
- data/lib/ghq/cache/directory.rb +15 -1
- data/lib/ghq/cache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 029edda1d5f7d745b5e4716a54cac2da429fb476
|
4
|
+
data.tar.gz: 2d5a4ba671db6667b1704c7b72a4ce1306b7f67c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cb1143dabf1600831a6ca22f07575b88044e7cccd76074f09c9da9bec9ba37095350cf856ac77bd2f1f151202c77c08f43a4cf759206c26907980fbf99d0108
|
7
|
+
data.tar.gz: 756f5a3794784ce4c690b051214c70729b429d4f11b881e686a6fe4d47a1f58553ac5465ff887601d7acd4ea7516a864f22c30dbde6cf6353c2aee5b4d393248
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ function ghq() {
|
|
32
32
|
$GHQ $@
|
33
33
|
|
34
34
|
# hook after ghq get
|
35
|
-
ghq-cache refresh &
|
35
|
+
(ghq-cache refresh &)
|
36
36
|
;;
|
37
37
|
list )
|
38
38
|
if [ ! -e ~/.ghq-cache ]; then
|
@@ -54,7 +54,7 @@ function peco-src() {
|
|
54
54
|
full_dir="${GOPATH}/src/${selected_dir}"
|
55
55
|
|
56
56
|
# Log repository access to ghq-cache
|
57
|
-
ghq-cache log $full_dir &
|
57
|
+
(ghq-cache log $full_dir &)
|
58
58
|
|
59
59
|
BUFFER="cd ${full_dir}"
|
60
60
|
zle accept-line
|
data/lib/ghq/cache/builder.rb
CHANGED
@@ -7,43 +7,46 @@ module Ghq
|
|
7
7
|
class << self
|
8
8
|
def build
|
9
9
|
root = Logger.resume
|
10
|
+
obsolete_paths.each do |path|
|
11
|
+
root.remove_path(path)
|
12
|
+
end
|
10
13
|
ghq_list.each do |path|
|
11
14
|
root.register_path(File.join(root.name, path))
|
12
15
|
end
|
13
16
|
|
14
|
-
|
17
|
+
dirs = flatten(root).sort_by do |dir|
|
18
|
+
sort_key(dir)
|
19
|
+
end.reverse
|
20
|
+
cache = dirs.map(&:full_path).join("\n").concat("\n")
|
15
21
|
File.write(CACHE_PATH, cache)
|
16
22
|
end
|
17
23
|
|
18
24
|
private
|
19
25
|
|
20
|
-
def
|
21
|
-
|
26
|
+
def flatten(*dirs)
|
27
|
+
dirs.map do |dir|
|
28
|
+
next dir if dir.children.empty?
|
29
|
+
flatten(*dir.children)
|
30
|
+
end.flatten
|
22
31
|
end
|
23
32
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
paths << File.join(directory.name, child.name)
|
29
|
-
next
|
30
|
-
end
|
33
|
+
def sort_key(dir)
|
34
|
+
return [dir.count] unless dir.parent
|
35
|
+
[dir.count, *sort_key(dir.parent)]
|
36
|
+
end
|
31
37
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
def obsolete_paths
|
39
|
+
cached_paths =
|
40
|
+
if File.exist?(CACHE_PATH)
|
41
|
+
File.read(CACHE_PATH).split("\n")
|
42
|
+
else
|
43
|
+
[]
|
38
44
|
end
|
39
|
-
|
40
|
-
paths
|
45
|
+
cached_paths - ghq_list
|
41
46
|
end
|
42
47
|
|
43
|
-
def
|
44
|
-
|
45
|
-
[-1 * child.count, child.name]
|
46
|
-
end
|
48
|
+
def ghq_list
|
49
|
+
`#{GHQ_PATH} list`.split("\n")
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
data/lib/ghq/cache/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
module Ghq
|
4
5
|
module Cache
|
@@ -13,6 +14,12 @@ module Ghq
|
|
13
14
|
Logger.log(path)
|
14
15
|
refresh
|
15
16
|
end
|
17
|
+
|
18
|
+
desc 'purge', 'Delete ~/.ghq-cache and ~/.ghq-cache.log'
|
19
|
+
def purge
|
20
|
+
FileUtils.rm_f(Logger::LOG_PATH)
|
21
|
+
FileUtils.rm_f(Builder::CACHE_PATH)
|
22
|
+
end
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
data/lib/ghq/cache/directory.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Ghq
|
2
2
|
module Cache
|
3
|
-
class Directory < Struct.new(:name, :count, :children)
|
3
|
+
class Directory < Struct.new(:name, :count, :children, :parent)
|
4
4
|
def initialize(*)
|
5
5
|
super
|
6
6
|
self.count ||= 0
|
@@ -28,10 +28,23 @@ module Ghq
|
|
28
28
|
child.register_path(relative_path)
|
29
29
|
end
|
30
30
|
|
31
|
+
def remove_path(path)
|
32
|
+
relative_path = path.gsub(%r[^#{name}/?], '')
|
33
|
+
return if relative_path.empty?
|
34
|
+
|
35
|
+
child = create_or_find(relative_path.split('/').first)
|
36
|
+
children.delete(child)
|
37
|
+
end
|
38
|
+
|
31
39
|
def root?
|
32
40
|
self.name.include?('/')
|
33
41
|
end
|
34
42
|
|
43
|
+
def full_path
|
44
|
+
return name unless parent
|
45
|
+
File.join(parent.full_path, name)
|
46
|
+
end
|
47
|
+
|
35
48
|
private
|
36
49
|
|
37
50
|
def create_or_find(child_name)
|
@@ -42,6 +55,7 @@ module Ghq
|
|
42
55
|
|
43
56
|
child = Directory.new(child_name)
|
44
57
|
self.children << child
|
58
|
+
child.parent = self
|
45
59
|
child
|
46
60
|
end
|
47
61
|
end
|
data/lib/ghq/cache/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghq-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|