Browse Source

punk::repo fixes

master
Julian Noble 2 months ago
parent
commit
8089558ea7
  1. 1
      src/modules/punk/mix/commandset/repo-999999.0a1.0.tm
  2. 62
      src/modules/punk/repo-999999.0a1.0.tm

1
src/modules/punk/mix/commandset/repo-999999.0a1.0.tm

@ -25,6 +25,7 @@
namespace eval punk::mix::commandset::repo {
namespace export *
proc tickets {{project ""}} {
#todo
set result ""
if {[string length $project]} {
puts stderr "project status unimplemented"

62
src/modules/punk/repo-999999.0a1.0.tm

@ -346,6 +346,11 @@ namespace eval punk::repo {
#does a dual git/fossil repo make sense if both are committing??
# see: https://fossil-scm.org/home/doc/trunk/www/inout.wiki for bidirectional sync info
proc workingdir_state {{abspath {}} args} {
#we should try to minimize executable calls
#an extra git/fossil executable call required for tags
#git seems to require more executable calls
set defaults [list\
-repotypes [list fossil git]\
-repopaths ""\
@ -408,6 +413,8 @@ namespace eval punk::repo {
set revision ""
set revision_iso8601 ""
set pathdict [dict create]
set branch ""
set tags ""
if {![llength $repotypes_to_query]} {
error "No tracking information available for project at $repodir with the chosen repotypes '$opt_repotypes'. Ensure project workingdir is a fossil (or git) checkout"
@ -437,6 +444,38 @@ namespace eval punk::repo {
}
set revision_iso8601 "${revision_ymd}T${revision_hms}${revision_tz}"
#REVIEW! what are the semantic difference between tags in fossil v git?
#fossil has tagtypes such as propagated and singleton(onetime)
#if we get all tag info for the revision - we can get the current branch (branch=somename tag) at the same time
#by retrieving with --raw - we have to process some prefixes such as sym- but probably best not done here
#we will return all tags that apply to the current revision and let the caller decide the meanings
if {![catch {punk::mix::util::do_in_path $repodir [list exec {*}$fossil_cmd tag ls --raw $revision]} cmdresult]} {
set branchinfo [lindex [grep {branch=*} $cmdresult] 0] ;#first line match - should only be one
set branch [lindex [split $branchinfo =] 1]
set tags [list]
foreach ln [split $cmdresult \n] {
if {[string trim $ln] eq ""} {
continue
}
lappend tags [string trim $ln]
}
}
#set tags_info [lindex [grep {tags:*} $fossilstate 0] ;#first line match - should only be one
#we get lines like:
#tags: trunk, main
#tags: trunk
#set rawtags [lrange $tags_info 1 end] ;#REVIEW
#set tags [list]
#foreach t $rawtags {
# lappend tags [string trimright $t ,]
#}
#if {![catch {punk::mix::util::do_in_path $repodir [list exec {*}$fossil_cmd branch current]} cmdresult]} {
# set branch $cmdresult ;#command result doesn't include newline etc
#}
dict set resultdict ahead ""
dict set resultdict behind ""
@ -490,6 +529,7 @@ namespace eval punk::repo {
set git_cmd [auto_execok git]
# -uno = suppress ? lines.
# -b = show ranch and tracking info
#our basic parsing/grepping assumes --porcelain=2
if {[catch {punk::mix::util::do_in_path $repodir [list exec {*}$git_cmd status --porcelain=2 -b -- $abspath]} gitstate]} {
error "workingdir_state error: Unable to retrieve workingdir state using git. Errormsg: $gitstate"
}
@ -499,6 +539,13 @@ namespace eval punk::repo {
puts stderr "workingdir_state: git revision is (initial) - no file state to gather"
break
}
# line: # branch.head somebranchname
set branch [lindex [grep {# branch.head *} $gitstate] 0 2]
if {![catch {punk::mix::util::do_in_path $repodir [list exec {*}$git_cmd describe --exact-match --tags]} cmdresult]} {
set tags $cmdresult ;#review - we have short tags vs longer.. e.g v0.1a vs v0.1a-184-g856fab4 - which is returned? Also how are multiple separated?
}
#often there will be no tag - so the common case is actually an error "fatal: not ag exactly matchs 'xxxx...'"
# -- --- --- --- ---
#could use %ci for ISO8601 data - see git-show manpage, but this will be in timezone of developer's machine - we need it in UTC for comparison to fossil outputs and other devs
@ -600,6 +647,8 @@ namespace eval punk::repo {
puts stderr "workingdir_state - repotype $rt not supported"
}
}
dict set resultdict branch $branch
dict set resultdict tags $tags
dict set resultdict revision $revision
dict set resultdict revision_iso8601 $revision_iso8601
dict set resultdict paths $pathdict
@ -610,8 +659,13 @@ namespace eval punk::repo {
error "workingdir_state_summary error repostate doesn't appear to be a repostate dict. (use workingdir_state <path> to create)"
}
package require overtype
#the revision branch and tags are highly relevant to the file state - and workingdir_state currently retrieves them anyway
# - so we'll include them in the defaults
# - when we are including working dir state as part of other output - we could be duplicating branch/tag retrievals
# - todo - flags to stop duplicating effort ??
set defaults [dict create\
-fields {ahead behind unchanged changed new missing extra}\
-fields {revision branch tags ahead behind unchanged changed new missing extra}\
]
set opts [dict merge $defaults $args]
# -- --- --- --- --- --- --- --- --- ---
@ -625,6 +679,8 @@ namespace eval punk::repo {
subpath subpath\
revision revision\
revision_iso8601 revision_iso8601\
branch branch\
tags tags\
ahead ahead\
behind behind\
repotype repotype\
@ -662,13 +718,15 @@ namespace eval punk::repo {
set result [string trimright $result \n]
return $result
}
#todo - describe purpose and possibly rename
proc workingdir_state_summary_dict {repostate} {
if {![dict exists $repostate repotype] || ![dict exists $repostate paths]} {
error "workingdir_state_summary_dict error repostate doesn't appear to be a repostate dict. (use workingdir_state <path> to create)"
}
set filestates [dict values [dict get $repostate paths]]
set path_count_fields [list unchanged changed new missing extra]
set state_fields [list ahead behind repodir subpath repotype revision revision_iso8601]
set state_fields [list ahead behind repodir subpath repotype revision revision_iso8601 branch tags]
set dresult [dict create]
if {[dict exists $repostate error]} {
foreach f $state_fields {

Loading…
Cancel
Save