Julian Noble
1 year ago
3 changed files with 240 additions and 5 deletions
@ -0,0 +1,160 @@
|
||||
# -*- tcl -*- |
||||
# Maintenance Instruction: leave the 999999.xxx.x as is and use 'pmix make' or src/make.tcl to update from <pkg>-buildversion.txt |
||||
# |
||||
# Please consider using a BSD or MIT style license for greatest compatibility with the Tcl ecosystem. |
||||
# Code using preferred Tcl licenses can be eligible for inclusion in Tcllib, Tklib and the punk package repository. |
||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||
#Copyright (c) 2023 Julian Noble |
||||
#Copyright (c) 2012-2018 Andreas Kupries |
||||
# - code from A.K's 'kettle' project used in this module |
||||
# |
||||
# @@ Meta Begin |
||||
# Application punk::repo 999999.0a1.0 |
||||
# Meta platform tcl |
||||
# Meta license BSD |
||||
# @@ Meta End |
||||
|
||||
|
||||
|
||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||
## Requirements |
||||
##e.g package require frobz |
||||
|
||||
|
||||
|
||||
|
||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||
namespace eval punk::repo { |
||||
|
||||
proc is_fossil {{path {}}} { |
||||
if {$path eq {}} { set path [pwd] } |
||||
return [expr {[find_fossil $path] ne {}}] |
||||
} |
||||
proc is_git {{path {}}} { |
||||
if {$path eq {}} { set path [pwd] } |
||||
return [expr {[find_git $path] ne {}}] |
||||
} |
||||
|
||||
proc find_fossil {{path {}}} { |
||||
if {$path eq {}} { set path [pwd] } |
||||
scanup $path is_fossil_root |
||||
} |
||||
proc find_git {{path {}}} { |
||||
if {$path eq {}} { set path [pwd] } |
||||
scanup $path is_git_root |
||||
} |
||||
|
||||
proc is_fossil_root {{path {}}} { |
||||
if {$path eq {}} { set path [pwd] } |
||||
#from kettle::path::is.fossil |
||||
foreach control { |
||||
_FOSSIL_ |
||||
.fslckout |
||||
.fos |
||||
} { |
||||
set control $path/$control |
||||
if {[file exists $control] && [file isfile $control]} {return 1} |
||||
} |
||||
return 0 |
||||
} |
||||
proc is_git_root {{path {}}} { |
||||
if {$path eq {}} { set path [pwd] } |
||||
set control $path/.git |
||||
expr {[file exists $control] && [file isdirectory $control]} |
||||
} |
||||
|
||||
proc git_revision {{path {}}} { |
||||
if {$path eq {}} { set path [pwd] } |
||||
# ::kettle::path::revision.git |
||||
do_in_path $path { |
||||
try { |
||||
set v [::exec {*}[auto_execok git] describe] |
||||
} on error {e o} { |
||||
set v [lindex [split [dict get $o -errorinfo] \n] 0] |
||||
} |
||||
} |
||||
return [string trim $v] |
||||
} |
||||
|
||||
proc fossil_revision {{path {}}} { |
||||
if {$path eq {}} { set path [pwd] } |
||||
# ::kettle::path::revision.fossil |
||||
set fossilcmd [auto_execok fossil] |
||||
if {[llength $fossilcmd]} { |
||||
do_in_path $path { |
||||
set info [::exec {*}$fossilcmd info] |
||||
} |
||||
return [lindex [grep {checkout:*} $info] 0 1] |
||||
} else { |
||||
return Unknown |
||||
} |
||||
} |
||||
|
||||
#temporarily cd to workpath to run script - return to correct path even on failure |
||||
proc do_in_path {path script} { |
||||
#from ::kettle::path::in |
||||
set here [pwd] |
||||
try { |
||||
cd $path |
||||
uplevel 1 $script |
||||
} finally { |
||||
cd $here |
||||
} |
||||
} |
||||
proc scanup {path cmd} { |
||||
if {$path eq {}} { set path [pwd] } |
||||
#based on kettle::path::scanup |
||||
set path [file normalize $path] |
||||
while {1} { |
||||
# Found the proper directory, per the predicate. |
||||
if {[{*}$cmd $path]} { return $path } |
||||
|
||||
# Not found, walk to parent |
||||
set new [file dirname $path] |
||||
|
||||
# Stop when reaching the root. |
||||
if {$new eq $path} { return {} } |
||||
if {$new eq {}} { return {} } |
||||
|
||||
# Ok, truly walk up. |
||||
set path $new |
||||
} |
||||
return {} |
||||
} |
||||
|
||||
proc grep {pattern data} { |
||||
set data [string map [list \r\n \n] $data] |
||||
return [lsearch -all -inline -glob [split $data \n] $pattern] |
||||
} |
||||
|
||||
proc rgrep {pattern data} { |
||||
set data [string map [list \r\n \n] $data] |
||||
return [lsearch -all -inline -regexp [split $data \n] $pattern] |
||||
} |
||||
|
||||
interp alias {} is_fossil {} ::punk::repo::is_fossil |
||||
interp alias {} is_fossil_root {} ::punk::repo::is_fossil_root |
||||
interp alias {} find_fossil {} ::punk::repo::find_fossil |
||||
interp alias {} fossil_revision {} ::punk::repo::fossil_revision |
||||
interp alias {} is_git {} ::punk::repo::is_git |
||||
interp alias {} is_git_root {} ::punk::repo::is_git_root |
||||
interp alias {} find_git {} ::punk::repo::find_git |
||||
interp alias {} git_revision {} ::punk::repo::git_revision |
||||
|
||||
|
||||
interp alias {} gs {} git status -sb |
||||
interp alias {} gr {} ::punk::repo::git_revision |
||||
interp alias {} gl {} git log --oneline --decorate ;#decorate so stdout consistent with what we see on console |
||||
interp alias {} glast {} git log -1 HEAD --stat |
||||
interp alias {} gconf {} git config --global -l |
||||
|
||||
} |
||||
|
||||
|
||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||
## Ready |
||||
package provide punk::repo [namespace eval punk::repo { |
||||
variable version |
||||
set version 999999.0a1.0 |
||||
}] |
||||
return |
Loading…
Reference in new issue