Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Factor out the logic that tries to deduce an appropriate repository name from a remote URL and put it in the url_to_repo_basename() routine of url.c. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
f978fcdce15d4f82ef013646e86ab17f |
| User & Date: | drh 2020-11-01 20:37:44.920 |
Context
|
2020-11-01
| ||
| 20:44 | Fix a harmless compiler warning. check-in: 2ba5ddb9d9 user: drh tags: trunk | |
| 20:37 | Factor out the logic that tries to deduce an appropriate repository name from a remote URL and put it in the url_to_repo_basename() routine of url.c. check-in: f978fcdce1 user: drh tags: trunk | |
| 20:22 | Added the "Init In Place" section to the gitusers doc. check-in: b564baa67f user: wyoung tags: trunk | |
Changes
Changes to src/clone.c.
| ︙ | ︙ | |||
169 170 171 172 173 174 175 |
/* We should be done with options.. */
verify_all_options();
if( g.argc < 3 ){
usage("?OPTIONS? FILE-OR-URL ?NEW-REPOSITORY?");
}
db_open_config(0, 0);
| > | < < | | | < < < | | | > | | | < > | 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
/* We should be done with options.. */
verify_all_options();
if( g.argc < 3 ){
usage("?OPTIONS? FILE-OR-URL ?NEW-REPOSITORY?");
}
db_open_config(0, 0);
if( g.argc==4 ){
zRepo = g.argv[3];
}else{
char *zBase = url_to_repo_basename(g.argv[2]);
if( zBase==0 ){
fossil_fatal(
"unable to guess a repository name from the url \"%s\".\n"
"give the repository filename as an additional argument.",
g.argv[2]);
}
zRepo = mprintf("./%s.fossil", zBase);
if( zWorkDir==0 ){
zWorkDir = mprintf("./%s", zBase);
}
fossil_free(zBase);
}
if( -1 != file_size(zRepo, ExtFILE) ){
fossil_fatal("file already exists: %s", zRepo);
}
url_parse(g.argv[2], urlFlags);
if( zDefaultUser==0 && g.url.user!=0 ) zDefaultUser = g.url.user;
if( g.url.isFile ){
file_copy(g.url.name, zRepo);
db_close(1);
db_open_repository(zRepo);
db_open_config(1,0);
db_record_repository_filename(zRepo);
|
| ︙ | ︙ |
Changes to src/db.c.
| ︙ | ︙ | |||
3503 3504 3505 3506 3507 3508 3509 |
const char *zUri; /* URI to clone */
int i; /* Loop counter */
int rc; /* Result code from fossil_system() */
Blob cmd; /* Clone command to be run */
char *zCmd; /* String version of the clone command */
zUri = zRepo;
| | < | > > > | 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 |
const char *zUri; /* URI to clone */
int i; /* Loop counter */
int rc; /* Result code from fossil_system() */
Blob cmd; /* Clone command to be run */
char *zCmd; /* String version of the clone command */
zUri = zRepo;
zNewBase = url_to_repo_basename(zUri);
if( zNewBase==0 ){
fossil_fatal("unable to deduce a repository name from the url \"%s\"",
zUri);
}
if( zRepoDir==0 ) zRepoDir = zPwd;
zRepo = mprintf("%s/%s.fossil", zRepoDir, zNewBase);
fossil_free(zNewBase);
blob_init(&cmd, 0, 0);
blob_append_escaped_arg(&cmd, g.nameOfExe);
blob_append(&cmd, " clone", -1);
blob_append_escaped_arg(&cmd, zUri);
|
| ︙ | ︙ |
Changes to src/url.c.
| ︙ | ︙ | |||
626 627 628 629 630 631 632 |
if( (g.url.user && g.url.user[0])
&& (g.url.passwd==0 || g.url.passwd[0]==0)
&& isatty(fileno(stdin))
){
url_prompt_for_password();
}
}
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 626 627 628 629 630 631 632 633 634 635 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 |
if( (g.url.user && g.url.user[0])
&& (g.url.passwd==0 || g.url.passwd[0]==0)
&& isatty(fileno(stdin))
){
url_prompt_for_password();
}
}
/*
** Given a URL for a remote repository clone point, try to come up with a
** 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){
char *zTail;
int i;
if( zUrl==0 ) return;
for(i=0; zUrl[i]; i++){
if( zUrl[i]=='?' ) break;
if( 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[i]==0 ) return 0;
for(i=0; zTail[i] && zTail[i]!='.' && zTail[i]!='?'; i++){}
if( i==0 ) return 0;
return mprintf("%.*s", i, zTail);
}
|