better selection of next id number (now reusing lower numbers)
This commit is contained in:
parent
cfe5d42e5d
commit
4aa14b73b2
41
t.sh
41
t.sh
|
@ -141,6 +141,21 @@ function getuid() {
|
|||
return 0
|
||||
}
|
||||
|
||||
function updatenextid() {
|
||||
local nextid2=1
|
||||
nextid2=1
|
||||
while [[ " ${taskid[@]}" == *\ $nextid2* ]]; do
|
||||
nextid2=$((nextid2 + 1))
|
||||
done
|
||||
nextid=$nextid2
|
||||
}
|
||||
|
||||
function addidmap() { #1=id 2=uid
|
||||
local id="$1" uid="$2"
|
||||
idmap[$id]=$uid
|
||||
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id
|
||||
}
|
||||
|
||||
function loadids() {
|
||||
local LINE n uid id max count
|
||||
count=0
|
||||
|
@ -160,8 +175,7 @@ function loadids() {
|
|||
id=${LINE#*:}
|
||||
#uid=$(echo "$LINE" | sed 's/:.*$//g')
|
||||
#id=$(echo "$LINE" | sed 's/^.*://g')
|
||||
idmap[$id]=$uid
|
||||
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id
|
||||
addidmap $id $uid
|
||||
if [[ -z $uid || -z $id ]]; then
|
||||
error "invalid idmapping line: '$LINE'"
|
||||
profile "end"
|
||||
|
@ -170,7 +184,7 @@ function loadids() {
|
|||
[[ $id -gt $max ]] && max=$id
|
||||
count=$((count + 1))
|
||||
done < "$idfile"
|
||||
nextid=$((max + 1))
|
||||
updatenextid
|
||||
profile "end"
|
||||
dblog "got $count IDs from $idfile"
|
||||
|
||||
|
@ -209,7 +223,7 @@ function dumpids() {
|
|||
|
||||
function loadtasks() {
|
||||
local f ess x thislev par parid show thissum thisdesc
|
||||
local verbose=0 nextid2=1
|
||||
local verbose=0
|
||||
|
||||
profile "start"
|
||||
maxid=-1
|
||||
|
@ -228,15 +242,7 @@ function loadtasks() {
|
|||
numwid=${#maxid}
|
||||
profile "finished loadtask calls"
|
||||
|
||||
# ---ooooo implement get_next_id()
|
||||
# minid=$( echo "${taskid[@]}" | tr ' ' '\n' | sort -nr | tail -1)
|
||||
# if [[ $minid -lt $nextid ]]; then
|
||||
# nextid2=1
|
||||
# while [[ " ${taskid[@]}" == *\ $nextid2* ]]; do
|
||||
# nextid2=$((nextid2 + 1))
|
||||
# done
|
||||
# nextid=$nextid2
|
||||
# fi
|
||||
updatenextid
|
||||
|
||||
dblog "Calculating max indent level"
|
||||
# figure out max indent level and next id
|
||||
|
@ -334,9 +340,8 @@ dblog "process token '${tok[$i]}'"
|
|||
id=$(getid $uid)
|
||||
if [[ -z $id ]]; then
|
||||
id=$nextid
|
||||
idmap[$nextid]=$uid
|
||||
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id
|
||||
nextid=$((nextid + 1))
|
||||
addidmap $nextid $uid
|
||||
updatenextid
|
||||
needsave=1
|
||||
fi
|
||||
elif [[ ${tok[$i]} == "sum" ]]; then
|
||||
|
@ -1124,7 +1129,7 @@ function addtask() {
|
|||
fi
|
||||
uid=$(randomuid)
|
||||
thisid=$nextid
|
||||
idmap[$thisid]=$uid
|
||||
addidmap $thisid $uid
|
||||
taskid[$thisid]=$thisid
|
||||
taskuid[$thisid]=$uid
|
||||
tasksum[$thisid]="$*"
|
||||
|
@ -1156,7 +1161,7 @@ END:VTODO
|
|||
END:VCALENDAR
|
||||
EOF2
|
||||
|
||||
nextid=$((nextid + 1))
|
||||
updatenextid
|
||||
saveids
|
||||
needtitle=1
|
||||
if [[ -z ${parentuid} ]]; then
|
||||
|
|
Loading…
Reference in New Issue