Skip to content

Commit

Permalink
Git: delete old interfaces that were only used by Pkg1.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Oct 17, 2013
1 parent 1888cd2 commit 995138c
Showing 1 changed file with 0 additions and 130 deletions.
130 changes: 0 additions & 130 deletions base/git.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,134 +87,4 @@ function set_remote_url(url::String; remote::String="origin", dir="")
push != url && run(`config remote.$remote.pushurl $push`, dir=dir)
end

## below here to be retired ##

function each_tagged_version()
git_dir = abspath(dir())
@task for line in eachline(`git --git-dir=$git_dir show-ref --tags`)
m = match(r"^([0-9a-f]{40}) refs/tags/(v\S+)$", line)
if m != nothing && ismatch(Base.VERSION_REGEX, m.captures[2])
produce((convert(VersionNumber,m.captures[2]),m.captures[1]))
end
end
end
each_tagged_version(dir::String) = cd(each_tagged_version,dir)

function each_submodule(f::Function, recursive::Bool, dir::ByteString)
cmd = `git submodule foreach --quiet 'echo "$name $path $sha1"'`
for line in eachline(cmd)
name, path, sha1 = match(r"^(.*) (.*) ([0-9a-f]{40})$", line).captures
cd(dir) do
f(name, path, sha1)
end
if recursive
cd(path) do
each_submodule(true, dir) do n,p,s
cd(dir) do
f(n,"$path/$p",s)
end
end
end
end
end
end
each_submodule(f::Function, r::Bool) = each_submodule(f, r, pwd())

function read_config(file::String)
cfg = Dict()
# TODO: use --null option for better handling of weird values.
for line in eachline(`git config -f $file --get-regexp '.*'`)
key, val = match(r"^(\S+)\s+(.*)$", line).captures
cfg[key] = haskey(cfg,key) ? [cfg[key],val] : val
end
return cfg
end

# TODO: provide a clean way to avoid this disaster
function read_config_blob(blob::String)
tmp, io = mktemp()
try
write(io, readall(`cat-file blob $blob`))
finally
close(io)
end
cfg = read_config(tmp)
run(`rm -f tmp`)
return cfg
end

function write_config(file::String, cfg::Dict)
tmp = tempname()
for key in sort!(collect(keys(cfg)))
val = cfg[key]
if isa(val,Array)
for x in val
run(`config -f $tmp --add $key $x`)
end
else
run(`config -f $tmp $key $val`)
end
end
if isfile(tmp)
open(file,"w") do io
print(io,readall(tmp))
end
end
end

canonicalize_config(file::String) = write_config(file, read_config(file))

function config_sections(cfg::Dict)
sections = Set{ByteString}()
for (key,_) in cfg
m = match(r"^(.+)\.", key)
if m != nothing; push!(sections,m.captures[1]); end
end
sections
end

function merge_configs(Bc::Dict, Lc::Dict, Rc::Dict)
# extract section names
Bs = config_sections(Bc)
Ls = config_sections(Lc)
Rs = config_sections(Rc)
# expunge removed submodules from left and right sides
deleted = Set{ByteString}()
for section in Bs - Ls & Rs
filter!((k,v)->!beginswith(k,"$section."),Lc)
filter!((k,v)->!beginswith(k,"$section."),Rc)
push!(deleted, section)
end
# merge the remaining config key-value pairs
cfg = Dict()
conflicts = Dict()
for (key,_) in merge(Lc,Rc)
Lv = get(Lc,key,nothing)
Rv = get(Rc,key,nothing)
Bv = get(Bc,key,nothing)
if Lv == Rv || Rv == Bv
if Lv != nothing cfg[key] = Lv end
elseif Lv == Bv
if Rv != nothing cfg[key] = Rv end
else # conflict!
conflicts[key] = [Lv,Rv]
cfg[key] = Bv
end
end
return cfg, conflicts, deleted
end

# setup a repo's push URL intelligently

function autoconfig_pushurl()
url = readchomp(`config remote.origin.url`)
m = match(GITHUB_REGEX,url)
if m != nothing
pushurl = "[email protected]:$(m.captures[1])"
if pushurl != url
run(`config remote.origin.pushurl $pushurl`)
end
end
end

end # module

0 comments on commit 995138c

Please sign in to comment.