jit 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: f5c2cd92ea33331677eeff3e83280c1ae12fda655d906bc64872e8f6f657c010
4
- data.tar.gz: 154e5620d4540ded17b667edd7757450d9ad27fe8cf5bdd2f218fe8984407a75
2
+ SHA1:
3
+ metadata.gz: aa9a39f5359292f9749f7103c29f3a6eadf1dfc1
4
+ data.tar.gz: 061d790a80ac6f7307a749527c4683f95c28b7d3
5
5
  SHA512:
6
- metadata.gz: 616339725efbc5a38303469c729d512e5223b0850d139bd7d317205df5271be691bb506b052a3a60630f08459a97e737dfba051bbfcd4cc79eb1bdf285d2ca77
7
- data.tar.gz: 951f13df966b69f1e29596aa24e3117c41efb3c330c167974c64773f83f413bd2afbd060849dc7af5479a55b8c9d02790837366870fe16944f0942a2ab3ff757
6
+ metadata.gz: 47ae83e85a0b9f76e57d61dd76acca5402665b98ffd44f085ada67a2c49d9ae69ed81d43059d3d8aca824ccb084714b55f629b1af51992256ddce1eeeac3701e
7
+ data.tar.gz: 6207ab63be2d26bb76d97451b98212c7f1e37c014cc200698643bb7921139dc80cddc890211d40cd0480399b78db2bc7b5cecb09ccb24a818e99ad90b424923d
@@ -96,10 +96,7 @@ module Command
96
96
 
97
97
  ahead = divergence.ahead
98
98
  behind = divergence.behind
99
-
100
- return "" if ahead == 0 and behind == 0
101
-
102
- info = []
99
+ info = []
103
100
 
104
101
  if @options[:verbose] > 1
105
102
  info.push(fmt(:blue, repo.refs.short_name(divergence.upstream)))
@@ -107,7 +104,7 @@ module Command
107
104
  info.push("ahead #{ ahead }") if ahead > 0
108
105
  info.push("behind #{ behind }") if behind > 0
109
106
 
110
- " [#{ info.join(", ") }]"
107
+ info.empty? ? "" : " [#{ info.join(", ") }]"
111
108
  end
112
109
 
113
110
  def create_branch
@@ -68,17 +68,10 @@ module Command
68
68
  print_upstream_status
69
69
  print_pending_commit_status
70
70
 
71
- print_changes("Changes to be committed",
72
- @status.index_changes, :green)
73
-
74
- print_changes("Unmerged paths",
75
- @status.conflicts, :red, :conflict)
76
-
77
- print_changes("Changes not staged for commit",
78
- @status.workspace_changes, :red)
79
-
80
- print_changes("Untracked files",
81
- @status.untracked_files, :red)
71
+ print_changes("Changes to be committed", @status.index_changes, :green)
72
+ print_changes("Unmerged paths", @status.conflicts, :red, :conflict)
73
+ print_changes("Changes not staged for commit", @status.workspace_changes, :red)
74
+ print_changes("Untracked files", @status.untracked_files, :red)
82
75
 
83
76
  print_commit_status
84
77
  end
@@ -135,15 +128,18 @@ module Command
135
128
  end
136
129
  puts ""
137
130
  when :cherry_pick
138
- print_pending_type("cherry-pick")
131
+ print_pending_type(:cherry_pick)
139
132
  when :revert
140
- print_pending_type("revert")
133
+ print_pending_type(:revert)
141
134
  end
142
135
  end
143
136
 
144
- def print_pending_type(op)
145
- oid = repo.database.short_oid(repo.pending_commit.merge_oid)
146
- puts "You are currently #{ op }ing commit #{ oid }."
137
+ def print_pending_type(merge_type)
138
+ oid = repo.pending_commit.merge_oid(merge_type)
139
+ short = repo.database.short_oid(oid)
140
+ op = merge_type.to_s.sub("_", "-")
141
+
142
+ puts "You are currently #{ op }ing commit #{ short }."
147
143
 
148
144
  if @status.conflicts.empty?
149
145
  hint "all conflicts fixed: run 'jit #{ op } --continue'"
@@ -131,11 +131,13 @@ class Config
131
131
 
132
132
  def subsections(name)
133
133
  name, _ = Section.normalize([name])
134
- sections = @lines.keys
134
+ sections = []
135
135
 
136
- sections.select { |main, _| main == name }
137
- .reject { |_, sub| sub == nil }
138
- .map(&:last)
136
+ @lines.each_key do |main, sub|
137
+ sections.push(sub) if main == name and sub != ""
138
+ end
139
+
140
+ sections
139
141
  end
140
142
 
141
143
  def section?(key)
@@ -11,6 +11,7 @@ require_relative "./database/tree"
11
11
  require_relative "./database/tree_diff"
12
12
 
13
13
  require_relative "./database/backends"
14
+ require_relative "./path_filter"
14
15
 
15
16
  class Database
16
17
  TYPES = {
@@ -70,7 +71,7 @@ class Database
70
71
  return unless entry
71
72
  return list[prefix.to_s] = entry unless entry.tree?
72
73
 
73
- load(entry.oid).each_entry do |name, item|
74
+ load(entry.oid).entries.each do |name, item|
74
75
  build_list(list, item, prefix.join(name))
75
76
  end
76
77
  end
@@ -83,9 +84,9 @@ class Database
83
84
  oid[0..6]
84
85
  end
85
86
 
86
- def tree_diff(a, b, prune = [])
87
- diff = TreeDiff.new(self, prune)
88
- diff.compare_oids(a, b)
87
+ def tree_diff(a, b, filter = PathFilter.new)
88
+ diff = TreeDiff.new(self)
89
+ diff.compare_oids(a, b, filter)
89
90
  diff.changes
90
91
  end
91
92
 
@@ -4,7 +4,8 @@ class Database
4
4
  ENTRY_FORMAT = "Z*H40"
5
5
  TREE_MODE = 040000
6
6
 
7
- attr_accessor :oid, :entries
7
+ attr_accessor :oid
8
+ attr_reader :entries
8
9
 
9
10
  def self.parse(scanner)
10
11
  entries = {}
@@ -36,10 +37,6 @@ class Database
36
37
  @entries = entries
37
38
  end
38
39
 
39
- def each_entry(&block)
40
- @entries.each(&block)
41
- end
42
-
43
40
  def add_entry(parents, entry)
44
41
  if parents.empty?
45
42
  @entries[entry.basename] = entry
@@ -1,42 +1,25 @@
1
- require "pathname"
2
-
3
1
  class Database
4
2
  class TreeDiff
5
3
 
6
4
  attr_reader :changes
7
5
 
8
- def initialize(database, prune = [])
6
+ def initialize(database)
9
7
  @database = database
10
8
  @changes = {}
11
-
12
- build_routing_table(prune)
13
9
  end
14
10
 
15
- def compare_oids(a, b, prefix = Pathname.new(""))
11
+ def compare_oids(a, b, filter)
16
12
  return if a == b
17
13
 
18
14
  a_entries = a ? oid_to_tree(a).entries : {}
19
15
  b_entries = b ? oid_to_tree(b).entries : {}
20
16
 
21
- detect_deletions(a_entries, b_entries, prefix)
22
- detect_additions(a_entries, b_entries, prefix)
17
+ detect_deletions(a_entries, b_entries, filter)
18
+ detect_additions(a_entries, b_entries, filter)
23
19
  end
24
20
 
25
21
  private
26
22
 
27
- def build_routing_table(prune)
28
- @routes = {}
29
-
30
- prune.each do |path|
31
- table = @routes
32
- path.each_filename { |name| table = table[name] ||= {} }
33
- end
34
- end
35
-
36
- def routes_for_prefix(prefix)
37
- prefix.each_filename.reduce(@routes) { |table, name| table[name] || {} }
38
- end
39
-
40
23
  def oid_to_tree(oid)
41
24
  object = @database.load(oid)
42
25
 
@@ -46,40 +29,32 @@ class Database
46
29
  end
47
30
  end
48
31
 
49
- def detect_deletions(a, b, prefix)
50
- routes = routes_for_prefix(prefix)
51
-
52
- a.each do |name, entry|
53
- next unless routes.empty? or routes.has_key?(name)
54
-
55
- path = prefix.join(name)
32
+ def detect_deletions(a, b, filter)
33
+ filter.each_entry(a) do |name, entry|
56
34
  other = b[name]
57
-
58
35
  next if entry == other
59
36
 
37
+ sub_filter = filter.join(name)
38
+
60
39
  tree_a, tree_b = [entry, other].map { |e| e&.tree? ? e.oid : nil }
61
- compare_oids(tree_a, tree_b, path)
40
+ compare_oids(tree_a, tree_b, sub_filter)
62
41
 
63
42
  blobs = [entry, other].map { |e| e&.tree? ? nil : e }
64
- @changes[path] = blobs if blobs.any?
43
+ @changes[sub_filter.path] = blobs if blobs.any?
65
44
  end
66
45
  end
67
46
 
68
- def detect_additions(a, b, prefix)
69
- routes = routes_for_prefix(prefix)
70
-
71
- b.each do |name, entry|
72
- next unless routes.empty? or routes.has_key?(name)
73
-
74
- path = prefix.join(name)
47
+ def detect_additions(a, b, filter)
48
+ filter.each_entry(b) do |name, entry|
75
49
  other = a[name]
76
-
77
50
  next if other
78
51
 
52
+ sub_filter = filter.join(name)
53
+
79
54
  if entry.tree?
80
- compare_oids(nil, entry.oid, path)
55
+ compare_oids(nil, entry.oid, sub_filter)
81
56
  else
82
- @changes[path] = [nil, entry]
57
+ @changes[sub_filter.path] = [nil, entry]
83
58
  end
84
59
  end
85
60
  end
@@ -28,19 +28,19 @@ module Diff
28
28
  end
29
29
 
30
30
  def self.diff(a, b)
31
- Myers.diff(lines(a), lines(b))
31
+ Myers.diff(Diff.lines(a), Diff.lines(b))
32
32
  end
33
33
 
34
34
  def self.diff_hunks(a, b)
35
- Hunk.filter(diff(a, b))
35
+ Hunk.filter(Diff.diff(a, b))
36
36
  end
37
37
 
38
38
  def self.combined(as, b)
39
- diffs = as.map { |a| diff(a, b) }
39
+ diffs = as.map { |a| Diff.diff(a, b) }
40
40
  Combined.new(diffs).to_a
41
41
  end
42
42
 
43
43
  def self.combined_hunks(as, b)
44
- Hunk.filter(combined(as, b))
44
+ Hunk.filter(Diff.combined(as, b))
45
45
  end
46
46
  end
@@ -17,11 +17,11 @@ module Diff
17
17
  b_start = (offset < 0) ? nil : edits[offset].b_line.number
18
18
 
19
19
  hunks.push(Hunk.new(a_starts, b_start, []))
20
- offset = build_hunk(hunks.last, edits, offset)
20
+ offset = Hunk.build(hunks.last, edits, offset)
21
21
  end
22
22
  end
23
23
 
24
- def self.build_hunk(hunk, edits, offset)
24
+ def self.build(hunk, edits, offset)
25
25
  counter = -1
26
26
 
27
27
  until counter == 0
@@ -2,7 +2,7 @@ module Diff
2
2
  class Myers
3
3
 
4
4
  def self.diff(a, b)
5
- new(a, b).diff
5
+ Myers.new(a, b).diff
6
6
  end
7
7
 
8
8
  def initialize(a, b)
@@ -4,7 +4,7 @@ class Editor
4
4
  DEFAULT_EDITOR = "vi"
5
5
 
6
6
  def self.edit(path, command)
7
- editor = new(path, command)
7
+ editor = Editor.new(path, command)
8
8
  yield editor
9
9
  editor.edit_file
10
10
  end
@@ -19,7 +19,7 @@ class Index
19
19
  Entry = Struct.new(*entry_fields) do
20
20
  def self.create(pathname, oid, stat)
21
21
  path = pathname.to_s
22
- mode = mode_for_stat(stat)
22
+ mode = Entry.mode_for_stat(stat)
23
23
  flags = [path.bytesize, MAX_PATH_SIZE].min
24
24
 
25
25
  Entry.new(
@@ -73,5 +73,6 @@ module Merge
73
73
  index = list.find_index { |c| c.date < commit.date }
74
74
  list.insert(index || list.size, commit)
75
75
  end
76
+
76
77
  end
77
78
  end
@@ -42,7 +42,7 @@ module Merge
42
42
  a = a.lines if a.is_a?(String)
43
43
  b = b.lines if b.is_a?(String)
44
44
 
45
- new(o, a, b).merge
45
+ Diff3.new(o, a, b).merge
46
46
  end
47
47
 
48
48
  def initialize(o, a, b)
@@ -9,7 +9,7 @@ module Pack
9
9
  attr_reader :source_size, :target_size
10
10
 
11
11
  def self.expand(source, delta)
12
- new(delta).expand(source)
12
+ Expander.new(delta).expand(source)
13
13
  end
14
14
 
15
15
  def initialize(delta)
@@ -59,19 +59,28 @@ module Pack
59
59
 
60
60
  module PackedInt56LE
61
61
  def self.write(value)
62
- bytes = (0..6).map { |i| (value >> (8 * i)) & 0xff }
62
+ bytes = [0]
63
63
 
64
- flags = bytes.map.with_index { |b, i| b == 0 ? 0 : 1 << i }
65
- header = flags.reduce(0) { |a, b| a | b }
64
+ (0...7).each do |i|
65
+ byte = (value >> (8 * i)) & 0xff
66
+ next if byte == 0
66
67
 
67
- [header] + bytes.reject { |b| b == 0 }
68
+ bytes[0] |= 1 << i
69
+ bytes.push(byte)
70
+ end
71
+
72
+ bytes
68
73
  end
69
74
 
70
75
  def self.read(input, header)
71
- flags = (0..6).reject { |i| header & (1 << i) == 0 }
72
- bytes = flags.map { |i| input.readbyte << (8 * i) }
76
+ value = 0
73
77
 
74
- bytes.reduce(0) { |a, b| a | b }
78
+ (0...7).each do |i|
79
+ next if header & (1 << i) == 0
80
+ value |= input.readbyte << (8 * i)
81
+ end
82
+
83
+ value
75
84
  end
76
85
  end
77
86
 
@@ -15,7 +15,7 @@ module Pack
15
15
  index[slice].push(offset)
16
16
  end
17
17
 
18
- new(source, index)
18
+ XDelta.new(source, index)
19
19
  end
20
20
 
21
21
  def initialize(source, index)
@@ -0,0 +1,44 @@
1
+ require "pathname"
2
+
3
+ class PathFilter
4
+ Trie = Struct.new(:matched, :children) do
5
+ def self.from_paths(paths)
6
+ root = Trie.node
7
+ root.matched = true if paths.empty?
8
+
9
+ paths.each do |path|
10
+ trie = root
11
+ path.each_filename { |name| trie = trie.children[name] }
12
+ trie.matched = true
13
+ end
14
+
15
+ root
16
+ end
17
+
18
+ def self.node
19
+ Trie.new(false, Hash.new { |hash, key| hash[key] = Trie.node })
20
+ end
21
+ end
22
+
23
+ attr_reader :path
24
+
25
+ def self.build(paths)
26
+ PathFilter.new(Trie.from_paths(paths))
27
+ end
28
+
29
+ def initialize(routes = Trie.new(true), path = Pathname.new(""))
30
+ @routes = routes
31
+ @path = path
32
+ end
33
+
34
+ def each_entry(entries)
35
+ entries.each do |name, entry|
36
+ yield name, entry if @routes.matched or @routes.children.has_key?(name)
37
+ end
38
+ end
39
+
40
+ def join(name)
41
+ next_routes = @routes.matched ? @routes : @routes.children[name]
42
+ PathFilter.new(next_routes, @path.join(name))
43
+ end
44
+ end
@@ -101,7 +101,6 @@ class Refs
101
101
  raise InvalidBranch, "A branch named '#{ branch_name }' already exists."
102
102
  end
103
103
 
104
- FileUtils.mkdir_p(path.dirname)
105
104
  update_ref_file(path, start_oid)
106
105
  end
107
106
 
@@ -115,6 +114,8 @@ class Refs
115
114
  raise InvalidBranch, "branch '#{ branch_name }' not found." unless oid
116
115
 
117
116
  File.unlink(path)
117
+ delete_parent_directories(path)
118
+
118
119
  oid
119
120
  ensure
120
121
  lockfile.rollback
@@ -195,6 +196,17 @@ class Refs
195
196
  prefix ? prefix.join(name) : nil
196
197
  end
197
198
 
199
+ def delete_parent_directories(path)
200
+ path.dirname.ascend do |dir|
201
+ break if dir == @heads_path
202
+ begin
203
+ Dir.rmdir(dir)
204
+ rescue Errno::ENOTEMPTY
205
+ break
206
+ end
207
+ end
208
+ end
209
+
198
210
  def read_oid_or_symref(path)
199
211
  data = File.read(path).strip
200
212
  match = SYMREF.match(data)
@@ -23,8 +23,8 @@ class Remotes
23
23
  return @output.write("0000") if line == nil
24
24
 
25
25
  line = append_caps(line)
26
-
27
26
  size = line.bytesize + 5
27
+
28
28
  @output.write(size.to_s(16).rjust(4, "0"))
29
29
  @output.write(line)
30
30
  @output.write("\n")
@@ -10,8 +10,8 @@ class Remotes
10
10
  Refspec = Struct.new(:source, :target, :forced) do
11
11
  def self.parse(spec)
12
12
  match = REFSPEC_FORMAT.match(spec)
13
- source = canonical(match[2])
14
- target = canonical(match[4]) || source
13
+ source = Refspec.canonical(match[2])
14
+ target = Refspec.canonical(match[4]) || source
15
15
 
16
16
  Refspec.new(source, target, match[1] == "+")
17
17
  end
@@ -20,15 +20,15 @@ class Remotes
20
20
  return nil if name.to_s == ""
21
21
  return name unless Revision.valid_ref?(name)
22
22
 
23
- first = Pathname.new(name).each_filename.first
23
+ first = Pathname.new(name).descend.first
24
24
  dirs = [Refs::REFS_DIR, Refs::HEADS_DIR, Refs::REMOTES_DIR]
25
- prefix = dirs.find { |dir| first == dir.basename.to_s }
25
+ prefix = dirs.find { |dir| dir.basename == first }
26
26
 
27
27
  (prefix&.dirname || Refs::HEADS_DIR).join(name).to_s
28
28
  end
29
29
 
30
30
  def self.expand(specs, refs)
31
- specs = specs.map { |spec| parse(spec) }
31
+ specs = specs.map { |spec| Refspec.parse(spec) }
32
32
 
33
33
  specs.reduce({}) do |mappings, spec|
34
34
  mappings.merge(spec.match_refs(refs))
@@ -36,7 +36,7 @@ class Remotes
36
36
  end
37
37
 
38
38
  def self.invert(specs, ref)
39
- specs = specs.map { |spec| parse(spec) }
39
+ specs = specs.map { |spec| Refspec.parse(spec) }
40
40
 
41
41
  map = specs.reduce({}) do |mappings, spec|
42
42
  spec.source, spec.target = spec.target, spec.source
@@ -23,7 +23,7 @@ class Repository
23
23
  end
24
24
 
25
25
  def in_progress?
26
- not merge_type.nil?
26
+ merge_type != nil
27
27
  end
28
28
 
29
29
  def merge_type
@@ -1,6 +1,7 @@
1
1
  require "pathname"
2
2
  require "set"
3
3
 
4
+ require_relative "./path_filter"
4
5
  require_relative "./revision"
5
6
 
6
7
  class RevList
@@ -31,6 +32,8 @@ class RevList
31
32
 
32
33
  revs.each { |rev| handle_revision(rev) }
33
34
  handle_revision(Revision::HEAD) if @queue.empty?
35
+
36
+ @filter = PathFilter.build(@prune)
34
37
  end
35
38
 
36
39
  def each
@@ -42,7 +45,7 @@ class RevList
42
45
 
43
46
  def tree_diff(old_oid, new_oid)
44
47
  key = [old_oid, new_oid]
45
- @diffs[key] ||= @repo.database.tree_diff(old_oid, new_oid, @prune)
48
+ @diffs[key] ||= @repo.database.tree_diff(old_oid, new_oid, @filter)
46
49
  end
47
50
 
48
51
  private
@@ -141,16 +144,10 @@ class RevList
141
144
 
142
145
  until queue.empty?
143
146
  oid = queue.shift
147
+ next unless mark(oid, :uninteresting)
144
148
 
145
- while oid
146
- break unless mark(oid, :uninteresting)
147
-
148
- parent = @commits[oid]
149
- break unless parent
150
-
151
- oid = parent.parents.first
152
- queue.concat(parent.parents.drop(1))
153
- end
149
+ commit = @commits[oid]
150
+ queue.concat(commit.parents) if commit
154
151
  end
155
152
  end
156
153
 
@@ -224,7 +221,7 @@ class RevList
224
221
 
225
222
  tree = @repo.database.load(entry.oid)
226
223
 
227
- tree.each_entry do |name, item|
224
+ tree.entries.each do |name, item|
228
225
  traverse_tree(item, path.join(name)) { |object| yield object }
229
226
  end
230
227
  end
@@ -54,16 +54,16 @@ class Revision
54
54
 
55
55
  def self.parse(revision)
56
56
  if match = PARENT.match(revision)
57
- rev = parse(match[1])
57
+ rev = Revision.parse(match[1])
58
58
  n = (match[2] == "") ? 1 : match[2].to_i
59
59
  rev ? Parent.new(rev, n) : nil
60
60
  elsif match = ANCESTOR.match(revision)
61
- rev = parse(match[1])
61
+ rev = Revision.parse(match[1])
62
62
  rev ? Ancestor.new(rev, match[2].to_i) : nil
63
63
  elsif match = UPSTREAM.match(revision)
64
- rev = parse(match[1])
64
+ rev = Revision.parse(match[1])
65
65
  rev ? Upstream.new(rev) : nil
66
- elsif valid_ref?(revision)
66
+ elsif Revision.valid_ref?(revision)
67
67
  name = REF_ALIASES[revision] || revision
68
68
  Ref.new(name)
69
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Coglan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: jcoglan@gmail.com
@@ -91,6 +91,7 @@ files:
91
91
  - lib/pack/writer.rb
92
92
  - lib/pack/xdelta.rb
93
93
  - lib/pager.rb
94
+ - lib/path_filter.rb
94
95
  - lib/progress.rb
95
96
  - lib/refs.rb
96
97
  - lib/remotes.rb
@@ -129,7 +130,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
132
  requirements: []
132
- rubygems_version: 3.0.1
133
+ rubyforge_project:
134
+ rubygems_version: 2.5.2.3
133
135
  signing_key:
134
136
  specification_version: 4
135
137
  summary: The information manager from London