git_fame 2.2.0 → 2.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56ed28564572151ef8368874a40c3a78b7450bf6
4
- data.tar.gz: 69f85cbc4d81f337b6c32963805030329303f5f8
3
+ metadata.gz: f60cc8e1ebb619b563a10256cd86549fdd59a901
4
+ data.tar.gz: 93a5887855e265c463bd3c8ab1a48c24a107cfa1
5
5
  SHA512:
6
- metadata.gz: bca32c460a55a96cee4cb5673ff371d6695589185e9b86ab3b7ce5e480b59c1f254f996452b8ee10d11d095b7bff122aad67703192607612dadf3d7cd0d30ac1
7
- data.tar.gz: 05270545850772755df28042a05088a64c6b60566948019834e20fe718b05bb5da1a1cfb3b06b86cae87ec0647342c1bb5b72a7a581abfa0d685faf1f0314c92
6
+ metadata.gz: 20cbb0c37d9d3637c0b9c3e73241c4a10e73ffa877e76e97014e7ddcfab064d03c1f2932b3d1b6e441ce298bdb8b7d96dffb9530f570a1ac19c75f844cb63673
7
+ data.tar.gz: 86e2e53e6f36480ec4bb3b9f99925a77429c4c9d5af99809558ff65b49fab52f82b523a7aea5219f7ae5e8f72ae4169d7f431f8e87c7887d52fb7ab56cea9569
@@ -28,7 +28,7 @@ unless GitFame::SORT.include?(opts[:sort])
28
28
  Trollop::die :sort, "must be one of the following; #{GitFame::SORT.join(", ")}"
29
29
  end
30
30
 
31
- if opts[:timeout] <= 0
31
+ if opts[:timeout] != -1 and opts[:timeout] <= 0
32
32
  Trollop::die :timeout, "must be positive"
33
33
  end
34
34
 
@@ -52,11 +52,12 @@ module GitFame
52
52
  # Default sorting option is by loc
53
53
  @include = args.fetch(:include, "").split(",")
54
54
  @sort = args.fetch(:sort, @default_settings.fetch(:sorting))
55
- @repository = args.fetch(:repository)
55
+ @repository = File.expand_path(args.fetch(:repository))
56
56
  @by_type = args.fetch(:by_type, false)
57
57
  @branch = args.fetch(:branch, nil)
58
58
  @everything = args.fetch(:everything, false)
59
59
  @timeout = args.fetch(:timeout, CMD_TIMEOUT)
60
+ @git_dir = File.join(@repository, ".git")
60
61
 
61
62
  # Figure out what branch the caller is using
62
63
  if present?(@branch = args[:branch])
@@ -89,7 +90,6 @@ module GitFame
89
90
  @authors = {}
90
91
  @cache = {}
91
92
  @verbose = args.fetch(:verbose, false)
92
-
93
93
  populate
94
94
  end
95
95
 
@@ -186,7 +186,7 @@ module GitFame
186
186
  # -w ignore whitespaces (defined in @wopt)
187
187
  # -M detect moved or copied lines.
188
188
  # -p procelain mode (parsed by BlameParser)
189
- execute("git blame #{encoding_opt} -p -M #{default_params} #{commit_range.to_s} #{@wopt} -- '#{file}'") do |result|
189
+ execute("git #{git_directory_params} blame #{encoding_opt} -p -M #{default_params} #{commit_range.to_s} #{@wopt} -- '#{file}'") do |result|
190
190
  BlameParser.new(result.to_s).parse.each do |row|
191
191
  next if row[:boundary]
192
192
 
@@ -206,7 +206,7 @@ module GitFame
206
206
  end
207
207
 
208
208
  # Get repository summery and update each author accordingly
209
- execute("git shortlog #{encoding_opt} #{default_params} -se #{commit_range.to_s}") do |result|
209
+ execute("git #{git_directory_params} shortlog #{encoding_opt} #{default_params} -se #{commit_range.to_s}") do |result|
210
210
  result.to_s.split("\n").map do |line|
211
211
  _, commits, name, email = line.match(/(\d+)\s+(.+)\s+<(.+?)>/).to_a
212
212
  author = author_by_email(email)
@@ -233,7 +233,7 @@ module GitFame
233
233
 
234
234
  # Return mime type for file (form: x/y)
235
235
  def mime_type_for_file(file)
236
- execute("git show #{commit_range.range.last}:'#{file}' | LC_ALL=C file --mime-type -").to_s.
236
+ execute("git #{git_directory_params} show #{commit_range.range.last}:'#{file}' | LC_ALL=C file --mime-type -").to_s.
237
237
  match(/.+: (.+?)$/).to_a[1]
238
238
  end
239
239
 
@@ -312,8 +312,7 @@ module GitFame
312
312
  # Command to be executed at @repository
313
313
  # @silent = true wont raise an error on exit code =! 0
314
314
  def execute(command, silent = false, &block)
315
- result = run(command)
316
-
315
+ result = run_with_timeout(command)
317
316
  if result.success? or silent
318
317
  warn command if @verbose
319
318
  return result unless block
@@ -324,21 +323,19 @@ module GitFame
324
323
  raise Error, cmd_error_message(command, $!.message)
325
324
  end
326
325
 
327
- def run(command)
326
+ def run_with_timeout(command)
328
327
  if @timeout != -1
329
- Timeout.timeout(CMD_TIMEOUT) { raw_run(command) }
328
+ Timeout.timeout(CMD_TIMEOUT) { run_no_timeout(command) }
330
329
  else
331
- raw_run(command)
330
+ run_no_timeout(command)
332
331
  end
333
332
  end
334
333
 
335
- def raw_run(command)
336
- Open3.popen3(command, chdir: @repository) do |_, out, err, thread|
337
- out_data = out.read
338
- err_data = err.read
339
- output = thread.value.success? ? out_data : err_data
340
- Result.new(output.scrub.strip, thread.value.success?)
341
- end
334
+ def run_no_timeout(command)
335
+ out, err, status = Open3.capture3(command)
336
+ ok = status.success?
337
+ output = ok ? out : err
338
+ Result.new(output.scrub.strip, ok)
342
339
  end
343
340
 
344
341
  def cmd_error_message(command, message)
@@ -347,7 +344,7 @@ module GitFame
347
344
 
348
345
  # Does @branch exist in the current git repo?
349
346
  def branch_exists?(branch)
350
- execute("git show-ref '#{branch}'", true) do |result|
347
+ execute("git #{git_directory_params} show-ref '#{branch}'", true) do |result|
351
348
  result.success?
352
349
  end
353
350
  end
@@ -361,7 +358,7 @@ module GitFame
361
358
  return @default_settings.fetch(:branch)
362
359
  end
363
360
 
364
- execute("git rev-parse HEAD | head -1") do |result|
361
+ execute("git #{git_directory_params} rev-parse HEAD | head -1") do |result|
365
362
  return result.data.split(" ")[0] if result.success?
366
363
  end
367
364
  raise Error, "No branch found. Define one using --branch=<branch>"
@@ -375,11 +372,11 @@ module GitFame
375
372
  # extensions in @extensions defined by the user
376
373
  def current_files
377
374
  if commit_range.is_range?
378
- execute("git diff -l 100 --name-status #{encoding_opt} #{default_params} #{commit_range.to_s} | grep -v '^D' | cut -f2-") do |result|
375
+ execute("git #{git_directory_params} -c diff.renames=0 -c diff.renameLimit=1000 diff -M -C -c --name-only --diff-filter=AM #{encoding_opt} #{default_params} #{commit_range.to_s}") do |result|
379
376
  filter_files(result)
380
377
  end
381
378
  else
382
- execute("git ls-tree -r #{commit_range.to_s} | grep blob | cut -f2-") do |result|
379
+ execute("git #{git_directory_params} ls-tree --name-only -r #{commit_range.to_s}") do |result|
383
380
  filter_files(result)
384
381
  end
385
382
  end
@@ -389,6 +386,10 @@ module GitFame
389
386
  "--date=local"
390
387
  end
391
388
 
389
+ def git_directory_params
390
+ "--git-dir='#{@git_dir}' --work-tree='#{@repository}'"
391
+ end
392
+
392
393
  def encoding_opt
393
394
  "--encoding=UTF-8"
394
395
  end
@@ -436,11 +437,11 @@ module GitFame
436
437
  commit2 = @branch
437
438
  else
438
439
  # Try finding a commit that day
439
- commit2 = execute("git rev-list --before='#{@before} 23:59:59' --after='#{@before} 00:00:01' #{default_params} '#{@branch}' | head -1").to_s
440
+ commit2 = execute("git #{git_directory_params} rev-list --before='#{@before} 23:59:59' --after='#{@before} 00:00:01' #{default_params} '#{@branch}' | head -1").to_s
440
441
 
441
442
  # Otherwise, look for the closest commit
442
443
  if blank?(commit2)
443
- commit2 = execute("git rev-list --before='#{@before}' #{default_params} '#{@branch}' | head -1").to_s
444
+ commit2 = execute("git #{git_directory_params} rev-list --before='#{@before}' #{default_params} '#{@branch}' | head -1").to_s
444
445
  end
445
446
  end
446
447
  end
@@ -450,7 +451,7 @@ module GitFame
450
451
  return present?(commit2) ? commit2 : @branch
451
452
  end
452
453
 
453
- commit1 = execute("git rev-list --before='#{end_of_yesterday(@after)}' #{default_params} '#{@branch}' | head -1").to_s
454
+ commit1 = execute("git #{git_directory_params} rev-list --before='#{end_of_yesterday(@after)}' #{default_params} '#{@branch}' | head -1").to_s
454
455
 
455
456
  # No commit found this early
456
457
  # If NO end date is choosen, just use current branch
@@ -478,11 +479,11 @@ module GitFame
478
479
  end
479
480
 
480
481
  def start_commit_date
481
- Time.parse(execute("git log #{encoding_opt} --pretty=format:'%cd' #{default_params} #{@branch} | tail -1").to_s)
482
+ Time.parse(execute("git #{git_directory_params} log #{encoding_opt} --pretty=format:'%cd' #{default_params} #{@branch} | tail -1").to_s)
482
483
  end
483
484
 
484
485
  def end_commit_date
485
- Time.parse(execute("git log #{encoding_opt} --pretty=format:'%cd' #{default_params} #{@branch} | head -1").to_s)
486
+ Time.parse(execute("git #{git_directory_params} log #{encoding_opt} --pretty=format:'%cd' #{default_params} #{@branch} | head -1").to_s)
486
487
  end
487
488
 
488
489
  def end_date
@@ -514,7 +515,7 @@ module GitFame
514
515
  end
515
516
 
516
517
  # TODO: Are all these needed?
517
- memoize :populate, :run
518
+ memoize :populate, :run_with_timeout
518
519
  memoize :current_range, :current_files
519
520
  memoize :printable_fields, :files_from_author
520
521
  memoize :raw_fields, :fields, :file_list
@@ -1,3 +1,3 @@
1
1
  module GitFame
2
- VERSION = "2.2.0"
2
+ VERSION = "2.3.1"
3
3
  end
@@ -34,7 +34,8 @@ describe "bin/git-fame" do
34
34
  "--help",
35
35
  "--verbose",
36
36
  "--everything",
37
- "--timeout=10"
37
+ "--timeout=10",
38
+ "--timeout=-1"
38
39
  ].each do |option|
39
40
  it "should support #{option}" do
40
41
  run(option).should be_a_succees
@@ -67,8 +68,8 @@ describe "bin/git-fame" do
67
68
  it "should fail on invalid timeout" do
68
69
  run("--timeout=hello").should_not be_a_succees
69
70
  run("--timeout=").should_not be_a_succees
70
- run("--timeout=-1").should_not be_a_succees
71
71
  run("--timeout=0").should_not be_a_succees
72
+ run("--timeout=-2").should_not be_a_succees
72
73
  end
73
74
 
74
75
  it "should not print stack trace on invalid dates (--before)" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_fame
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linus Oleander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-09 00:00:00.000000000 Z
11
+ date: 2016-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-progressbar