mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
vcs.rb: prettify debug print
This commit is contained in:
parent
1acbcf0e58
commit
b64514f132
Notes:
git
2022-10-30 08:06:51 +00:00
1 changed files with 27 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
# vcs
|
# vcs
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
require 'pp'
|
||||||
|
|
||||||
# This library is used by several other tools/ scripts to detect the current
|
# This library is used by several other tools/ scripts to detect the current
|
||||||
# VCS in use (e.g. SVN, Git) or to interact with that VCS.
|
# VCS in use (e.g. SVN, Git) or to interact with that VCS.
|
||||||
|
@ -9,6 +10,22 @@ ENV.delete('PWD')
|
||||||
|
|
||||||
class VCS
|
class VCS
|
||||||
DEBUG_OUT = STDERR.dup
|
DEBUG_OUT = STDERR.dup
|
||||||
|
|
||||||
|
def self.dump(obj, pre = nil)
|
||||||
|
out = DEBUG_OUT
|
||||||
|
@pp ||= PP.new(out)
|
||||||
|
@pp.guard_inspect_key do
|
||||||
|
if pre
|
||||||
|
@pp.group(pre.size, pre) {
|
||||||
|
obj.pretty_print(@pp)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
obj.pretty_print(@pp)
|
||||||
|
end
|
||||||
|
@pp.flush
|
||||||
|
out << "\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless File.respond_to? :realpath
|
unless File.respond_to? :realpath
|
||||||
|
@ -19,14 +36,14 @@ unless File.respond_to? :realpath
|
||||||
end
|
end
|
||||||
|
|
||||||
def IO.pread(*args)
|
def IO.pread(*args)
|
||||||
VCS::DEBUG_OUT.puts(args.inspect) if $DEBUG
|
VCS.dump(args, "args: ") if $DEBUG
|
||||||
popen(*args) {|f|f.read}
|
popen(*args) {|f|f.read}
|
||||||
end
|
end
|
||||||
|
|
||||||
module DebugPOpen
|
module DebugPOpen
|
||||||
refine IO.singleton_class do
|
refine IO.singleton_class do
|
||||||
def popen(*args)
|
def popen(*args)
|
||||||
VCS::DEBUG_OUT.puts args.inspect if $DEBUG
|
VCS.dump(args, "args: ") if $DEBUG
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,7 +51,7 @@ end
|
||||||
using DebugPOpen
|
using DebugPOpen
|
||||||
module DebugSystem
|
module DebugSystem
|
||||||
def system(*args)
|
def system(*args)
|
||||||
VCS::DEBUG_OUT.puts args.inspect if $DEBUG
|
VCS.dump(args, "args: ") if $DEBUG
|
||||||
exception = false
|
exception = false
|
||||||
opts = Hash.try_convert(args[-1])
|
opts = Hash.try_convert(args[-1])
|
||||||
if RUBY_VERSION >= "2.6"
|
if RUBY_VERSION >= "2.6"
|
||||||
|
@ -394,7 +411,7 @@ class VCS
|
||||||
def commit
|
def commit
|
||||||
args = %W"#{COMMAND} commit"
|
args = %W"#{COMMAND} commit"
|
||||||
if dryrun?
|
if dryrun?
|
||||||
VCS::DEBUG_OUT.puts(args.inspect)
|
VCS.dump(args, "commit: ")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
system(*args)
|
system(*args)
|
||||||
|
@ -411,7 +428,7 @@ class VCS
|
||||||
if srcdir
|
if srcdir
|
||||||
opts[:chdir] ||= srcdir
|
opts[:chdir] ||= srcdir
|
||||||
end
|
end
|
||||||
VCS::DEBUG_OUT.puts cmds.inspect if debug?
|
VCS.dump(cmds, "cmds: ") if debug? and !$DEBUG
|
||||||
cmds
|
cmds
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -421,7 +438,7 @@ class VCS
|
||||||
|
|
||||||
def cmd_read_at(srcdir, cmds)
|
def cmd_read_at(srcdir, cmds)
|
||||||
result = without_gitconfig { IO.pread(*cmd_args(cmds, srcdir)) }
|
result = without_gitconfig { IO.pread(*cmd_args(cmds, srcdir)) }
|
||||||
VCS::DEBUG_OUT.puts result.inspect if debug?
|
VCS.dump(result, "result: ") if debug?
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -516,7 +533,7 @@ class VCS
|
||||||
def initialize(*)
|
def initialize(*)
|
||||||
super
|
super
|
||||||
@srcdir = File.realpath(@srcdir)
|
@srcdir = File.realpath(@srcdir)
|
||||||
VCS::DEBUG_OUT.puts @srcdir.inspect if debug?
|
VCS.dump(@srcdir, "srcdir: ") if debug?
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -721,13 +738,13 @@ class VCS
|
||||||
|
|
||||||
def commit(opts = {})
|
def commit(opts = {})
|
||||||
args = [COMMAND, "push"]
|
args = [COMMAND, "push"]
|
||||||
args << "-n" if dryrun
|
args << "-n" if dryrun?
|
||||||
remote, branch = upstream
|
remote, branch = upstream
|
||||||
args << remote
|
args << remote
|
||||||
branches = %W[refs/notes/commits:refs/notes/commits HEAD:#{branch}]
|
branches = %W[refs/notes/commits:refs/notes/commits HEAD:#{branch}]
|
||||||
if dryrun?
|
if dryrun?
|
||||||
branches.each do |b|
|
branches.each do |b|
|
||||||
VCS::DEBUG_OUT.puts((args + [b]).inspect)
|
VCS.dump(args + [b], "commit: ")
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -757,7 +774,7 @@ class VCS
|
||||||
commits.each_with_index do |l, i|
|
commits.each_with_index do |l, i|
|
||||||
r, a, c = l.split(' ')
|
r, a, c = l.split(' ')
|
||||||
dcommit = [COMMAND, "svn", "dcommit"]
|
dcommit = [COMMAND, "svn", "dcommit"]
|
||||||
dcommit.insert(-2, "-n") if dryrun
|
dcommit.insert(-2, "-n") if dryrun?
|
||||||
dcommit << "--add-author-from" unless a == c
|
dcommit << "--add-author-from" unless a == c
|
||||||
dcommit << r
|
dcommit << r
|
||||||
system(*dcommit) or return false
|
system(*dcommit) or return false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue