Fossil

Check-in [380aa578]
Login

Check-in [380aa578]

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

Overview
Comment:Refinement to the URL-to-basename algorithm used to construct a repository filename from a clone URL so that the "www." prefix is not omitted if it is immediately followed by the suffix. forum post 74e111a2ee.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 380aa578a8ecbc952672b9dad5b4d8a90a09a93be1948c6602d097183d6eb756
User & Date: drh 2021-05-13 19:38:51
Original Comment: Refinement to the URL-to-basename algorithm used to construct a repository filename from a clone URL so that the "www." prefix is not omitted if it is immediately followed by the suffix. [forum/forumpost/74e111a2ee|forum post 74e111a2ee].
Context
2021-05-14
18:52
When doing a clone that automatically does an open, run the "fossil open" command as a subprocess (usingn fossil_system()) to avoid problems with misconfigured database connections in the event that the clone uses the "file:" scheme. See forum post b1da662b00 for the bug report. ... (check-in: ebd604f8 user: drh tags: trunk)
2021-05-13
19:38
Refinement to the URL-to-basename algorithm used to construct a repository filename from a clone URL so that the "www." prefix is not omitted if it is immediately followed by the suffix. forum post 74e111a2ee. ... (check-in: 380aa578 user: drh tags: trunk)
2021-05-12
02:14
Change log updates. ... (check-in: 705d519f user: stephan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/url.c.

636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657





658
659
660
661
662
663
664
** reasonable basename of a local clone of that repository.
**
**    *  If the URL has a path, use the tail of the path, with any suffix
**       elided.
**
**    *  If the URL is just a domain name, without a path, then use the
**       first element of the domain name, except skip over "www." if 
**       present.
**
** The string returned is obtained from fossil_malloc().  NULL might be
** returned if there is an error.
*/
char *url_to_repo_basename(const char *zUrl){
  const char *zTail = 0;
  int i;
  if( zUrl==0 ) return 0;
  for(i=0; zUrl[i]; i++){
    if( zUrl[i]=='?' ) break;
    if( (zUrl[i]=='/' || zUrl[i]=='@') && zUrl[i+1]!=0 ) zTail = &zUrl[i+1];
  }
  if( zTail==0 ) return 0;
  if( sqlite3_strnicmp(zTail, "www.", 4)==0 ) zTail += 4;





  if( zTail[0]==0 ) return 0;
  for(i=0; zTail[i] && zTail[i]!='.' && zTail[i]!='?'; i++){}
  if( i==0 ) return 0;
  return mprintf("%.*s", i, zTail);
}

/*







|













|
>
>
>
>
>







636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
** reasonable basename of a local clone of that repository.
**
**    *  If the URL has a path, use the tail of the path, with any suffix
**       elided.
**
**    *  If the URL is just a domain name, without a path, then use the
**       first element of the domain name, except skip over "www." if 
**       present and if there is a ".com" or ".org" or similar suffix.
**
** The string returned is obtained from fossil_malloc().  NULL might be
** returned if there is an error.
*/
char *url_to_repo_basename(const char *zUrl){
  const char *zTail = 0;
  int i;
  if( zUrl==0 ) return 0;
  for(i=0; zUrl[i]; i++){
    if( zUrl[i]=='?' ) break;
    if( (zUrl[i]=='/' || zUrl[i]=='@') && zUrl[i+1]!=0 ) zTail = &zUrl[i+1];
  }
  if( zTail==0 ) return 0;
  if( sqlite3_strnicmp(zTail, "www.", 4)==0 && strchr(zTail+4,'.')!=0 ){
    /* Remove the "www." prefix if there are more "." characters later.
    ** But don't remove the "www." prefix if what follows is the suffix.
    ** forum:/forumpost/74e111a2ee */
    zTail += 4;
  }
  if( zTail[0]==0 ) return 0;
  for(i=0; zTail[i] && zTail[i]!='.' && zTail[i]!='?'; i++){}
  if( i==0 ) return 0;
  return mprintf("%.*s", i, zTail);
}

/*