Fossil SCM

Add the "fossil remote hyperlink" and "fossil remote ui" subcommands.

drh 2022-09-23 13:04 trunk
Commit b2e2fc0372a08df1f8355d9952e497ad851ac926b827896e40bf3346d38f870f
1 file changed +92 -1
+92 -1
--- src/sync.c
+++ src/sync.c
@@ -507,10 +507,18 @@
507507
**
508508
** > fossil remote delete NAME
509509
**
510510
** Delete a named URL previously created by the "add" subcommand.
511511
**
512
+** > fossil remote hyperlink ?FILENAME? ?LINENUM? ?LINENUM?
513
+**
514
+** Print a URL that will access the current checkout on the remote
515
+** repository. Or if the FILENAME argument is included, print the
516
+** URL to access that particular file within the current checkout.
517
+** If one or two linenumber arguments are provided after the filename,
518
+** then the URL is for the line or range of lines specified.
519
+**
512520
** > fossil remote list|ls
513521
**
514522
** Show all remote repository URLs.
515523
**
516524
** > fossil remote off
@@ -532,10 +540,19 @@
532540
**
533541
** Forget any saved passwords for remote repositories, but continue
534542
** to remember the URLs themselves. You will be prompted for the
535543
** password the next time it is needed.
536544
**
545
+** > fossil remote ui ?FILENAME? ?LINENUM? ?LINENUM?
546
+**
547
+** Bring up a web browser pointing at the remote repository, and
548
+** specifically to the page that describes the current checkout
549
+** on that remote repository. Or if FILENAME and/or LINENUM arguments
550
+** are provided, to the specific file and range of lines. This
551
+** command is similar to "fossil remote hyperlink" except that instead
552
+** of printing the URL, it passes the URL off to the web browser.
553
+**
537554
** > fossil remote REF
538555
**
539556
** Make REF the new default URL, replacing the prior default.
540557
** REF may be a URL or a NAME from a prior "add".
541558
*/
@@ -651,10 +668,84 @@
651668
db_multi_exec("DELETE FROM config WHERE name glob 'sync-url:%q'", zName);
652669
db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:%q'", zName);
653670
db_protect_pop();
654671
db_commit_transaction();
655672
return;
673
+ }
674
+ if( strncmp(zArg, "hyperlink", nArg)==0
675
+ || (nArg==2 && strcmp(zArg, "ui")==0)
676
+ ){
677
+ char *zBase;
678
+ char *zUuid;
679
+ Blob fname;
680
+ Blob url;
681
+ char *zSubCmd = g.argv[2][0]=='u' ? "ui" : "hyperlink";
682
+ if( !db_table_exists("localdb","vvar") ){
683
+ fossil_fatal("the \"remote %s\" command only works from "
684
+ "within an open check-out", zSubCmd);
685
+ }
686
+ zUrl = db_get("last-sync-url", 0);
687
+ if( zUrl==0 ){
688
+ zUrl = "http://localhost:8080/";
689
+ }
690
+ url_parse(zUrl, 0);
691
+ if( g.url.isFile ){
692
+ url_parse("http://localhost:8080/", 0);
693
+ }
694
+ zBase = url_nouser(&g.url);
695
+ blob_init(&url, 0, 0);
696
+ if( g.argc==3 ){
697
+ blob_appendf(&url, "%s/info/%!S\n",
698
+ zBase,
699
+ db_text("???",
700
+ "SELECT uuid FROM blob, vvar"
701
+ " WHERE blob.rid=0+vvar.value"
702
+ " AND vvar.name='checkout';"
703
+ ));
704
+ }else{
705
+ blob_init(&fname, 0, 0);
706
+ file_tree_name(g.argv[3], &fname, 0, 1);
707
+ zUuid = db_text(0,
708
+ "SELECT uuid FROM files_of_checkin"
709
+ " WHERE checkinID=(SELECT value FROM vvar WHERE name='checkout')"
710
+ " AND filename=%Q",
711
+ blob_str(&fname)
712
+ );
713
+ if( zUuid==0 ){
714
+ fossil_fatal("not a managed file: \"%s\"", g.argv[3]);
715
+ }
716
+ blob_appendf(&url, "%s/info/%S",zBase,zUuid);
717
+ if( g.argc>4 ){
718
+ int ln1 = atoi(g.argv[4]);
719
+ if( ln1<=0 || sqlite3_strglob("*[^0-9]*",g.argv[4])==0 ){
720
+ fossil_fatal("\"%s\" is not a valid line number", g.argv[4]);
721
+ }
722
+ if( g.argc>5 ){
723
+ int ln2 = atoi(g.argv[5]);
724
+ if( ln2==0 || sqlite3_strglob("*[^0-9]*",g.argv[5])==0 ){
725
+ fossil_fatal("\"%s\" is not a valid line number", g.argv[5]);
726
+ }
727
+ if( ln2<=ln1 ){
728
+ fossil_fatal("second line number should be greater than the first");
729
+ }
730
+ blob_appendf(&url,"?ln=%d,%d", ln1, ln2);
731
+ }else{
732
+ blob_appendf(&url,"?ln=%d", ln1);
733
+ }
734
+ }
735
+ if( g.argc>6 ){
736
+ usage(mprintf("%s ?FILENAME? ?LINENUMBER? ?LINENUMBER?", zSubCmd));
737
+ }
738
+ }
739
+ if( g.argv[2][0]=='u' ){
740
+ char *zCmd;
741
+ zCmd = mprintf("%s %!$ &", fossil_web_browser(), blob_str(&url));
742
+ fossil_system(zCmd);
743
+ }else{
744
+ fossil_print("%s\n", blob_str(&url));
745
+ }
746
+ return;
656747
}
657748
if( strncmp(zArg, "scrub", nArg)==0 ){
658749
if( g.argc!=3 ) usage("scrub");
659750
db_begin_write();
660751
db_unprotect(PROTECT_CONFIG);
@@ -706,11 +797,11 @@
706797
URL_USE_CONFIG|URL_ASK_REMEMBER_PW);
707798
url_remember();
708799
return;
709800
}
710801
fossil_fatal("unknown command \"%s\" - should be a URL or one of: "
711
- "add delete list off", zArg);
802
+ "add delete hyperlink list off scrub", zArg);
712803
}
713804
714805
/*
715806
** COMMAND: backup*
716807
**
717808
--- src/sync.c
+++ src/sync.c
@@ -507,10 +507,18 @@
507 **
508 ** > fossil remote delete NAME
509 **
510 ** Delete a named URL previously created by the "add" subcommand.
511 **
 
 
 
 
 
 
 
 
512 ** > fossil remote list|ls
513 **
514 ** Show all remote repository URLs.
515 **
516 ** > fossil remote off
@@ -532,10 +540,19 @@
532 **
533 ** Forget any saved passwords for remote repositories, but continue
534 ** to remember the URLs themselves. You will be prompted for the
535 ** password the next time it is needed.
536 **
 
 
 
 
 
 
 
 
 
537 ** > fossil remote REF
538 **
539 ** Make REF the new default URL, replacing the prior default.
540 ** REF may be a URL or a NAME from a prior "add".
541 */
@@ -651,10 +668,84 @@
651 db_multi_exec("DELETE FROM config WHERE name glob 'sync-url:%q'", zName);
652 db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:%q'", zName);
653 db_protect_pop();
654 db_commit_transaction();
655 return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656 }
657 if( strncmp(zArg, "scrub", nArg)==0 ){
658 if( g.argc!=3 ) usage("scrub");
659 db_begin_write();
660 db_unprotect(PROTECT_CONFIG);
@@ -706,11 +797,11 @@
706 URL_USE_CONFIG|URL_ASK_REMEMBER_PW);
707 url_remember();
708 return;
709 }
710 fossil_fatal("unknown command \"%s\" - should be a URL or one of: "
711 "add delete list off", zArg);
712 }
713
714 /*
715 ** COMMAND: backup*
716 **
717
--- src/sync.c
+++ src/sync.c
@@ -507,10 +507,18 @@
507 **
508 ** > fossil remote delete NAME
509 **
510 ** Delete a named URL previously created by the "add" subcommand.
511 **
512 ** > fossil remote hyperlink ?FILENAME? ?LINENUM? ?LINENUM?
513 **
514 ** Print a URL that will access the current checkout on the remote
515 ** repository. Or if the FILENAME argument is included, print the
516 ** URL to access that particular file within the current checkout.
517 ** If one or two linenumber arguments are provided after the filename,
518 ** then the URL is for the line or range of lines specified.
519 **
520 ** > fossil remote list|ls
521 **
522 ** Show all remote repository URLs.
523 **
524 ** > fossil remote off
@@ -532,10 +540,19 @@
540 **
541 ** Forget any saved passwords for remote repositories, but continue
542 ** to remember the URLs themselves. You will be prompted for the
543 ** password the next time it is needed.
544 **
545 ** > fossil remote ui ?FILENAME? ?LINENUM? ?LINENUM?
546 **
547 ** Bring up a web browser pointing at the remote repository, and
548 ** specifically to the page that describes the current checkout
549 ** on that remote repository. Or if FILENAME and/or LINENUM arguments
550 ** are provided, to the specific file and range of lines. This
551 ** command is similar to "fossil remote hyperlink" except that instead
552 ** of printing the URL, it passes the URL off to the web browser.
553 **
554 ** > fossil remote REF
555 **
556 ** Make REF the new default URL, replacing the prior default.
557 ** REF may be a URL or a NAME from a prior "add".
558 */
@@ -651,10 +668,84 @@
668 db_multi_exec("DELETE FROM config WHERE name glob 'sync-url:%q'", zName);
669 db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:%q'", zName);
670 db_protect_pop();
671 db_commit_transaction();
672 return;
673 }
674 if( strncmp(zArg, "hyperlink", nArg)==0
675 || (nArg==2 && strcmp(zArg, "ui")==0)
676 ){
677 char *zBase;
678 char *zUuid;
679 Blob fname;
680 Blob url;
681 char *zSubCmd = g.argv[2][0]=='u' ? "ui" : "hyperlink";
682 if( !db_table_exists("localdb","vvar") ){
683 fossil_fatal("the \"remote %s\" command only works from "
684 "within an open check-out", zSubCmd);
685 }
686 zUrl = db_get("last-sync-url", 0);
687 if( zUrl==0 ){
688 zUrl = "http://localhost:8080/";
689 }
690 url_parse(zUrl, 0);
691 if( g.url.isFile ){
692 url_parse("http://localhost:8080/", 0);
693 }
694 zBase = url_nouser(&g.url);
695 blob_init(&url, 0, 0);
696 if( g.argc==3 ){
697 blob_appendf(&url, "%s/info/%!S\n",
698 zBase,
699 db_text("???",
700 "SELECT uuid FROM blob, vvar"
701 " WHERE blob.rid=0+vvar.value"
702 " AND vvar.name='checkout';"
703 ));
704 }else{
705 blob_init(&fname, 0, 0);
706 file_tree_name(g.argv[3], &fname, 0, 1);
707 zUuid = db_text(0,
708 "SELECT uuid FROM files_of_checkin"
709 " WHERE checkinID=(SELECT value FROM vvar WHERE name='checkout')"
710 " AND filename=%Q",
711 blob_str(&fname)
712 );
713 if( zUuid==0 ){
714 fossil_fatal("not a managed file: \"%s\"", g.argv[3]);
715 }
716 blob_appendf(&url, "%s/info/%S",zBase,zUuid);
717 if( g.argc>4 ){
718 int ln1 = atoi(g.argv[4]);
719 if( ln1<=0 || sqlite3_strglob("*[^0-9]*",g.argv[4])==0 ){
720 fossil_fatal("\"%s\" is not a valid line number", g.argv[4]);
721 }
722 if( g.argc>5 ){
723 int ln2 = atoi(g.argv[5]);
724 if( ln2==0 || sqlite3_strglob("*[^0-9]*",g.argv[5])==0 ){
725 fossil_fatal("\"%s\" is not a valid line number", g.argv[5]);
726 }
727 if( ln2<=ln1 ){
728 fossil_fatal("second line number should be greater than the first");
729 }
730 blob_appendf(&url,"?ln=%d,%d", ln1, ln2);
731 }else{
732 blob_appendf(&url,"?ln=%d", ln1);
733 }
734 }
735 if( g.argc>6 ){
736 usage(mprintf("%s ?FILENAME? ?LINENUMBER? ?LINENUMBER?", zSubCmd));
737 }
738 }
739 if( g.argv[2][0]=='u' ){
740 char *zCmd;
741 zCmd = mprintf("%s %!$ &", fossil_web_browser(), blob_str(&url));
742 fossil_system(zCmd);
743 }else{
744 fossil_print("%s\n", blob_str(&url));
745 }
746 return;
747 }
748 if( strncmp(zArg, "scrub", nArg)==0 ){
749 if( g.argc!=3 ) usage("scrub");
750 db_begin_write();
751 db_unprotect(PROTECT_CONFIG);
@@ -706,11 +797,11 @@
797 URL_USE_CONFIG|URL_ASK_REMEMBER_PW);
798 url_remember();
799 return;
800 }
801 fossil_fatal("unknown command \"%s\" - should be a URL or one of: "
802 "add delete hyperlink list off scrub", zArg);
803 }
804
805 /*
806 ** COMMAND: backup*
807 **
808

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button