fx

Changes On Branch fx-peer-clear
Login

Changes On Branch fx-peer-clear

Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2018 Conference, Houston/TX, US, Oct 15-19
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Aug 20.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch fx-peer-clear Excluding Merge-Ins

This is equivalent to a diff from f6c9b02c30 to f3a440de75

2014-05-30
23:36
Accepted the advanced commands "peer state-(clear|reset)" check-in: 1bd6a27a5e user: aku tags: trunk
23:35
fx::peer - Fixed mapping of "state-clear" command. Closed-Leaf check-in: f3a440de75 user: aku tags: fx-peer-clear
23:27
Keeping track of trunk check-in: 438fa4e36a user: aku tags: fx-peer-clear
23:21
fx::user - Fixed the output generated by "user contact" (added colors, missing spaces) check-in: f6c9b02c30 user: andreask tags: trunk
23:11
fx - Added "users" alias for "user list", and made this the default when no sub-command specified. check-in: fe0772e765 user: andreask tags: trunk

Changes to lib/fx.tcl.
1390
1391
1392
1393
1394
1395
1396



















1397
1398
1399
1400
1401
1402
1403
	    } {
		optional
		default {}
		validate rwdirectory
	    }
	} [fx::call peer state-dir]




















	private list {
	    section Peering
	    section Introspection
	    description {
		List all peers stored in the repository, and associated
		definitions (what to synchronize, direction, type of peer).
	    }







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
	    } {
		optional
		default {}
		validate rwdirectory
	    }
	} [fx::call peer state-dir]

	private state-reset {
	    section Advanced {Armed & Dangerous} Peering
	    description {
		Resets the uuid information used to track new commits.
		This forces a re-import of the repository into the local
		git state, and further forces a push to the git peers on the
		next invokation of "peer exchange".
	    }
	} [fx::call peer state-reset]

	private state-clear {
	    section Advanced {Armed & Dangerous} Peering
	    description {
		Like "state-reset" but additionally discards the entire
		local git state, forcing a complete rebuild on the next
		invokation of "peer exchange".
	    }
	} [fx::call peer state-clear]

	private list {
	    section Peering
	    section Introspection
	    description {
		List all peers stored in the repository, and associated
		definitions (what to synchronize, direction, type of peer).
	    }
Changes to lib/peer.tcl.
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51

namespace eval ::fx {
    namespace export peer
    namespace ensemble create
}
namespace eval ::fx::peer {
    namespace export \
	list add remove add-git remove-git \

	exchange state-dir export import init
    namespace ensemble create

    namespace import ::cmdr::color
    namespace import ::fx::fossil
    namespace import ::fx::mailer
    namespace import ::fx::mgr::config
    namespace import ::fx::mgr::map







|
>
|







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

namespace eval ::fx {
    namespace export peer
    namespace ensemble create
}
namespace eval ::fx::peer {
    namespace export \
	list add remove add-git remove-git exchange \
	state-dir state-reset state-clear \
	export import init
    namespace ensemble create

    namespace import ::cmdr::color
    namespace import ::fx::fossil
    namespace import ::fx::mailer
    namespace import ::fx::mgr::config
    namespace import ::fx::mgr::map
249
250
251
252
253
254
255




























































256
257
258
259
260
261
262
	config set-local fx-aku-peer-git-state [$config @dir]
    }

    # Show current value, possibly set above.
    puts [Statedir]
    return
}





























































# # ## ### ##### ######## ############# ######################

proc ::fx::peer::exchange {config} {
    debug.fx/peer {}
    fossil show-repository-location
    init







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
	config set-local fx-aku-peer-git-state [$config @dir]
    }

    # Show current value, possibly set above.
    puts [Statedir]
    return
}

proc ::fx::peer::state-reset {config} {
    debug.fx/peer {}
    fossil show-repository-location
    init

    set state [Statedir]
    if {[IsState $state]} {
	if {[MyState $state _ _]} {
	    puts "  Drop tracked uuid from state [color note $state]"
	    GitDropLast $state
	} else {
	    puts "  [color error {Not touching}] non-owned state [color note $state]"
	}
    } else {
	puts "  Ignoring non-state [color note $state]"
    }

    fossil repository transaction {
	set peers [map get fx@peer@git]
	dict for {url last} $peers {
	    puts "  Cleared tracked uuid for git peer [color note $url]"
	    map remove1 fx@peer@git $url
	    map add1    fx@peer@git $url {}
	}
    }

    puts [color good OK]
    return
}

proc ::fx::peer::state-clear {config} {
    debug.fx/peer {}
    fossil show-repository-location
    init

    set state [Statedir]
    if {[IsState $state]} {
	if {[MyState $state _ _]} {
	    puts "  Discard state [color note $state]"
	    file delete -force $state
	} else {
	    puts "  [color error {Not touching}] non-owned state [color note $state]"
	}
    } else {
	puts "  Ignoring non-state [color note $state]"
    }

    fossil repository transaction {
	set peers [map get fx@peer@git]
	dict for {url last} $peers {
	    puts "  Cleared tracked uuid for git peer [color note $url]"
	    map remove1 fx@peer@git $url
	    map add1    fx@peer@git $url {}
	}
    }

    puts [color good OK]
    return
}

# # ## ### ##### ######## ############# ######################

proc ::fx::peer::exchange {config} {
    debug.fx/peer {}
    fossil show-repository-location
    init
364
365
366
367
368
369
370







371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
    # then create the peering links again.

    set i [interp::createEmpty]
    $i alias fossil ::fx::peer::IFossil
    $i alias git    ::fx::peer::IGit
    $i eval $data
    interp delete $i








    if {!$extend} {
	puts [color warning "Import replaces all existing peers ..."]
	# Inlined delete of all peers
	map delete fx@peer@fossil
	map delete fx@peer@git
    } else {
	puts [color note "Import keeps the existing peers ..."]
    }

    variable imported
    if {![llength $imported]} {
	puts [color note {No peers}]
	return
    }

    puts "New peers ..."
    init
    foreach {type url details} $imported {
	puts -nonewline "  Importing $type $url ($details) ... "
	flush stdout

	switch -exact -- $type {







>
>
>
>
>
>
>










<
<
<
<
<
<







425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448






449
450
451
452
453
454
455
    # then create the peering links again.

    set i [interp::createEmpty]
    $i alias fossil ::fx::peer::IFossil
    $i alias git    ::fx::peer::IGit
    $i eval $data
    interp delete $i

    variable imported 

    if {![llength $imported]} {
	puts [color note {No peers}]
	return
    }

    if {!$extend} {
	puts [color warning "Import replaces all existing peers ..."]
	# Inlined delete of all peers
	map delete fx@peer@fossil
	map delete fx@peer@git
    } else {
	puts [color note "Import keeps the existing peers ..."]
    }







    puts "New peers ..."
    init
    foreach {type url details} $imported {
	puts -nonewline "  Importing $type $url ($details) ... "
	flush stdout

	switch -exact -- $type {
486
487
488
489
490
491
492


















493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523


524
525
526
527
528
529
530

proc ::fx::peer::Statedir {} {
    debug.fx/peer {}
    return [config get-with-default \
		fx-aku-peer-git-state \
		[fossil repository-location].peer-state]
}



















# taken from old setup-import script.
proc ::fx::peer::GitSetup {statedir project location} {
    debug.fx/peer {}

    set pcode [config get-local project-code]

    puts "Exchange [string repeat _ 40]"
    puts "Git State Directory"

    if {[file exists      $statedir] &&
	[file isdirectory $statedir] &&
	[file exists      $statedir/git/git-daemon-export-ok] &&
	[file isfile      $statedir/git/git-daemon-export-ok]
    } {
	debug.fx/peer {/initialized}
	puts "  Ready at [color note $statedir]."

	# A ready directory may still belong to a different
	# project. Check this.

	set owner [string trim [fileutil::cat $statedir/owner]]
	if {$pcode ne $owner} {
	    puts [color error "  Error: Claimed by project \"$owner\""]
	    puts [color error "  Error: Which is not us    \"$pcode\""]
	    # Abort self, and caller (exchange).
	    return -code return
	}

	puts [color good OK]
	return


    }

    puts "  Initialize at [color note $statedir]."

    # State directory is not initialized. Do it now.
    # Drop anything else which may existed in its place.
    debug.fx/peer {initialize now}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





<
<



<
|
<
<
<






|
<








>
>







548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577


578
579
580

581



582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605

proc ::fx::peer::Statedir {} {
    debug.fx/peer {}
    return [config get-with-default \
		fx-aku-peer-git-state \
		[fossil repository-location].peer-state]
}

proc ::fx::peer::IsState {statedir} {
    debug.fx/peer {}
    return [expr {[file exists      $statedir] &&
		  [file isdirectory $statedir] &&
		  [file exists      $statedir/git/git-daemon-export-ok] &&
		  [file isfile      $statedir/git/git-daemon-export-ok]
	      }]
}

proc ::fx::peer::MyState {statedir pv ov} {
    upvar 1 $pv pcode $ov owner
    debug.fx/peer {}
    set pcode [config get-local project-code]
    set owner [string trim [fileutil::cat $statedir/owner]]
    return [expr {$pcode eq $owner}]
}


# taken from old setup-import script.
proc ::fx::peer::GitSetup {statedir project location} {
    debug.fx/peer {}



    puts "Exchange [string repeat _ 40]"
    puts "Git State Directory"


    if {[IsState $statedir]} {



	debug.fx/peer {/initialized}
	puts "  Ready at [color note $statedir]."

	# A ready directory may still belong to a different
	# project. Check this.

	if {![MyState $statedir pcode owner]} {

	    puts [color error "  Error: Claimed by project \"$owner\""]
	    puts [color error "  Error: Which is not us    \"$pcode\""]
	    # Abort self, and caller (exchange).
	    return -code return
	}

	puts [color good OK]
	return
    } else {
	set pcode [config get-local project-code]
    }

    puts "  Initialize at [color note $statedir]."

    # State directory is not initialized. Do it now.
    # Drop anything else which may existed in its place.
    debug.fx/peer {initialize now}
627
628
629
630
631
632
633






634
635
636
637
638
639
640
}

proc ::fx::peer::GitUpdateImported {git current} {
    set idfile $git/fossil-import-id
    fileutil::writeFile $idfile $current
    return
}







proc ::fx::peer::GitPull {tmp git first} {
    puts "  Pull"

    set begin [clock seconds]
    set src   [fossil repository-location]








>
>
>
>
>
>







702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
}

proc ::fx::peer::GitUpdateImported {git current} {
    set idfile $git/fossil-import-id
    fileutil::writeFile $idfile $current
    return
}

proc ::fx::peer::GitDropLast {statedir} {
    set idfile $statedir/git/fossil-import-id
    file delete -force $idfile
    return
}

proc ::fx::peer::GitPull {tmp git first} {
    puts "  Pull"

    set begin [clock seconds]
    set src   [fossil repository-location]