Fossil SCM
Resolve patch aliases and add help text.
Commit
d6ef7ff1f8d1455f07a355fcedce5a85594733e9575a508a2ec0e2fb4baf96f2
Parent
efe37cf77d88fbc…
1 file changed
+43
-22
+43
-22
| --- src/patch.c | ||
| +++ src/patch.c | ||
| @@ -698,10 +698,30 @@ | ||
| 698 | 698 | fossil_fatal("cannot change to directory \"%s\"", zDir); |
| 699 | 699 | } |
| 700 | 700 | fossil_free(zToFree); |
| 701 | 701 | return zPatchFile; |
| 702 | 702 | } |
| 703 | + | |
| 704 | +/* | |
| 705 | +** Resolves a patch-command remote system name, accounting for patch | |
| 706 | +** aliases. | |
| 707 | +** | |
| 708 | +** If a CONFIG table entry matching name='patch-alias:zKey' is found, | |
| 709 | +** the corresponding value is returned, else a fossil_strdup() of zKey | |
| 710 | +** is returned. | |
| 711 | +*/ | |
| 712 | +static char * patch_resolve_remote(const char *zKey){ | |
| 713 | + char * zAlias; | |
| 714 | + | |
| 715 | + zAlias = db_text(0, "SELECT value FROM config " | |
| 716 | + "WHERE name = 'patch-alias:' || %Q", | |
| 717 | + zKey); | |
| 718 | + if( 0!=zAlias ){ | |
| 719 | + return zAlias; | |
| 720 | + } | |
| 721 | + return fossil_strdup(zKey); | |
| 722 | +} | |
| 703 | 723 | |
| 704 | 724 | /* |
| 705 | 725 | ** Create a FILE* that will execute the remote side of a push or pull |
| 706 | 726 | ** using ssh (probably) or fossil for local pushes and pulls. Return |
| 707 | 727 | ** a FILE* obtained from popen() into which we write the patch, or from |
| @@ -729,11 +749,11 @@ | ||
| 729 | 749 | if( mFlags & PATCH_DRYRUN ) blob_appendf(&flgs, " -n"); |
| 730 | 750 | zForce = blob_size(&flgs)>0 ? blob_str(&flgs) : ""; |
| 731 | 751 | if( g.argc!=4 ){ |
| 732 | 752 | usage(mprintf("%s [USER@]HOST:DIRECTORY", zThisCmd)); |
| 733 | 753 | } |
| 734 | - zRemote = fossil_strdup(g.argv[3]); | |
| 754 | + zRemote = patch_resolve_remote(g.argv[3]); | |
| 735 | 755 | zDir = (char*)file_skip_userhost(zRemote); |
| 736 | 756 | if( zDir==0 ){ |
| 737 | 757 | if( isRetry ) goto remote_command_error; |
| 738 | 758 | zDir = zRemote; |
| 739 | 759 | blob_append_escaped_arg(&cmd, g.nameOfExe, 1); |
| @@ -905,24 +925,10 @@ | ||
| 905 | 925 | db_finalize(&q); |
| 906 | 926 | diff_end(pCfg, nErr); |
| 907 | 927 | if( nErr ) fossil_fatal("abort due to prior errors"); |
| 908 | 928 | } |
| 909 | 929 | |
| 910 | -#if 0 /*TODO*/ | |
| 911 | -static char * patch_resolve_remote(const char *zKey){ | |
| 912 | - char * zAlias; | |
| 913 | - | |
| 914 | - zAlias = db_text(0, "SELECT value FROM config " | |
| 915 | - "WHERE name GLOB 'patch-alias:' || %Q", | |
| 916 | - zKey); | |
| 917 | - if( 0!=zAlias ){ | |
| 918 | - return zAlias; | |
| 919 | - } | |
| 920 | - return mprintf("%s", zKey); | |
| 921 | -} | |
| 922 | -#endif | |
| 923 | - | |
| 924 | 930 | /* |
| 925 | 931 | ** COMMAND: patch |
| 926 | 932 | ** |
| 927 | 933 | ** Usage: %fossil patch SUBCOMMAND ?ARGS ..? |
| 928 | 934 | ** |
| @@ -1003,10 +1009,29 @@ | ||
| 1003 | 1009 | ** View a summary of the changes in the binary patch in PATCHFILE. |
| 1004 | 1010 | ** Use "fossil patch diff" for detailed patch content. |
| 1005 | 1011 | ** |
| 1006 | 1012 | ** -v|--verbose Show extra detail about the patch |
| 1007 | 1013 | ** |
| 1014 | +** > fossil patch alias add|rm|ls|list ?ARGS? | |
| 1015 | +** | |
| 1016 | +** Manage remote-name aliases, which act as short-form equivalents | |
| 1017 | +** to REMOTE-CHECKOUT strings. | |
| 1018 | +** | |
| 1019 | +** Subcommands: | |
| 1020 | +** | |
| 1021 | +** > add local-name REMOTE-CHECKOUT | |
| 1022 | +** | |
| 1023 | +** Add local-name as an alias for REMOTE-CHECKOUT. | |
| 1024 | +** | |
| 1025 | +** > ls|list | |
| 1026 | +** | |
| 1027 | +** List all local aliases. | |
| 1028 | +** | |
| 1029 | +** > rm [-all]| local-name [...local-nameN] | |
| 1030 | +** | |
| 1031 | +** Remove all aliases which match the given GLOB patterns, or | |
| 1032 | +** all aliases if -all is specified. | |
| 1008 | 1033 | */ |
| 1009 | 1034 | void patch_cmd(void){ |
| 1010 | 1035 | const char *zCmd; |
| 1011 | 1036 | size_t n; |
| 1012 | 1037 | if( g.argc<3 ){ |
| @@ -1027,17 +1052,13 @@ | ||
| 1027 | 1052 | |
| 1028 | 1053 | verify_all_options(); |
| 1029 | 1054 | db_prepare(&q, "SELECT substr(name,13), value FROM config " |
| 1030 | 1055 | "WHERE name GLOB 'patch-alias:*' ORDER BY name"); |
| 1031 | 1056 | while( SQLITE_ROW==db_step(&q) ){ |
| 1032 | - const char *zName; | |
| 1033 | - const char *zVal; | |
| 1034 | - if( 0==nAlias++ ){ | |
| 1035 | - fossil_print("Local patch aliases:\n"); | |
| 1036 | - } | |
| 1037 | - zName = db_column_text(&q, 0); | |
| 1038 | - zVal = db_column_text(&q, 1); | |
| 1057 | + const char *zName = db_column_text(&q, 0); | |
| 1058 | + const char *zVal = db_column_text(&q, 1); | |
| 1059 | + ++nAlias; | |
| 1039 | 1060 | fossil_print("%s = %s\n", zName, zVal); |
| 1040 | 1061 | } |
| 1041 | 1062 | db_finalize(&q); |
| 1042 | 1063 | if( 0==nAlias ){ |
| 1043 | 1064 | fossil_print("No patch aliases defined\n"); |
| 1044 | 1065 |
| --- src/patch.c | |
| +++ src/patch.c | |
| @@ -698,10 +698,30 @@ | |
| 698 | fossil_fatal("cannot change to directory \"%s\"", zDir); |
| 699 | } |
| 700 | fossil_free(zToFree); |
| 701 | return zPatchFile; |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | ** Create a FILE* that will execute the remote side of a push or pull |
| 706 | ** using ssh (probably) or fossil for local pushes and pulls. Return |
| 707 | ** a FILE* obtained from popen() into which we write the patch, or from |
| @@ -729,11 +749,11 @@ | |
| 729 | if( mFlags & PATCH_DRYRUN ) blob_appendf(&flgs, " -n"); |
| 730 | zForce = blob_size(&flgs)>0 ? blob_str(&flgs) : ""; |
| 731 | if( g.argc!=4 ){ |
| 732 | usage(mprintf("%s [USER@]HOST:DIRECTORY", zThisCmd)); |
| 733 | } |
| 734 | zRemote = fossil_strdup(g.argv[3]); |
| 735 | zDir = (char*)file_skip_userhost(zRemote); |
| 736 | if( zDir==0 ){ |
| 737 | if( isRetry ) goto remote_command_error; |
| 738 | zDir = zRemote; |
| 739 | blob_append_escaped_arg(&cmd, g.nameOfExe, 1); |
| @@ -905,24 +925,10 @@ | |
| 905 | db_finalize(&q); |
| 906 | diff_end(pCfg, nErr); |
| 907 | if( nErr ) fossil_fatal("abort due to prior errors"); |
| 908 | } |
| 909 | |
| 910 | #if 0 /*TODO*/ |
| 911 | static char * patch_resolve_remote(const char *zKey){ |
| 912 | char * zAlias; |
| 913 | |
| 914 | zAlias = db_text(0, "SELECT value FROM config " |
| 915 | "WHERE name GLOB 'patch-alias:' || %Q", |
| 916 | zKey); |
| 917 | if( 0!=zAlias ){ |
| 918 | return zAlias; |
| 919 | } |
| 920 | return mprintf("%s", zKey); |
| 921 | } |
| 922 | #endif |
| 923 | |
| 924 | /* |
| 925 | ** COMMAND: patch |
| 926 | ** |
| 927 | ** Usage: %fossil patch SUBCOMMAND ?ARGS ..? |
| 928 | ** |
| @@ -1003,10 +1009,29 @@ | |
| 1003 | ** View a summary of the changes in the binary patch in PATCHFILE. |
| 1004 | ** Use "fossil patch diff" for detailed patch content. |
| 1005 | ** |
| 1006 | ** -v|--verbose Show extra detail about the patch |
| 1007 | ** |
| 1008 | */ |
| 1009 | void patch_cmd(void){ |
| 1010 | const char *zCmd; |
| 1011 | size_t n; |
| 1012 | if( g.argc<3 ){ |
| @@ -1027,17 +1052,13 @@ | |
| 1027 | |
| 1028 | verify_all_options(); |
| 1029 | db_prepare(&q, "SELECT substr(name,13), value FROM config " |
| 1030 | "WHERE name GLOB 'patch-alias:*' ORDER BY name"); |
| 1031 | while( SQLITE_ROW==db_step(&q) ){ |
| 1032 | const char *zName; |
| 1033 | const char *zVal; |
| 1034 | if( 0==nAlias++ ){ |
| 1035 | fossil_print("Local patch aliases:\n"); |
| 1036 | } |
| 1037 | zName = db_column_text(&q, 0); |
| 1038 | zVal = db_column_text(&q, 1); |
| 1039 | fossil_print("%s = %s\n", zName, zVal); |
| 1040 | } |
| 1041 | db_finalize(&q); |
| 1042 | if( 0==nAlias ){ |
| 1043 | fossil_print("No patch aliases defined\n"); |
| 1044 |
| --- src/patch.c | |
| +++ src/patch.c | |
| @@ -698,10 +698,30 @@ | |
| 698 | fossil_fatal("cannot change to directory \"%s\"", zDir); |
| 699 | } |
| 700 | fossil_free(zToFree); |
| 701 | return zPatchFile; |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | ** Resolves a patch-command remote system name, accounting for patch |
| 706 | ** aliases. |
| 707 | ** |
| 708 | ** If a CONFIG table entry matching name='patch-alias:zKey' is found, |
| 709 | ** the corresponding value is returned, else a fossil_strdup() of zKey |
| 710 | ** is returned. |
| 711 | */ |
| 712 | static char * patch_resolve_remote(const char *zKey){ |
| 713 | char * zAlias; |
| 714 | |
| 715 | zAlias = db_text(0, "SELECT value FROM config " |
| 716 | "WHERE name = 'patch-alias:' || %Q", |
| 717 | zKey); |
| 718 | if( 0!=zAlias ){ |
| 719 | return zAlias; |
| 720 | } |
| 721 | return fossil_strdup(zKey); |
| 722 | } |
| 723 | |
| 724 | /* |
| 725 | ** Create a FILE* that will execute the remote side of a push or pull |
| 726 | ** using ssh (probably) or fossil for local pushes and pulls. Return |
| 727 | ** a FILE* obtained from popen() into which we write the patch, or from |
| @@ -729,11 +749,11 @@ | |
| 749 | if( mFlags & PATCH_DRYRUN ) blob_appendf(&flgs, " -n"); |
| 750 | zForce = blob_size(&flgs)>0 ? blob_str(&flgs) : ""; |
| 751 | if( g.argc!=4 ){ |
| 752 | usage(mprintf("%s [USER@]HOST:DIRECTORY", zThisCmd)); |
| 753 | } |
| 754 | zRemote = patch_resolve_remote(g.argv[3]); |
| 755 | zDir = (char*)file_skip_userhost(zRemote); |
| 756 | if( zDir==0 ){ |
| 757 | if( isRetry ) goto remote_command_error; |
| 758 | zDir = zRemote; |
| 759 | blob_append_escaped_arg(&cmd, g.nameOfExe, 1); |
| @@ -905,24 +925,10 @@ | |
| 925 | db_finalize(&q); |
| 926 | diff_end(pCfg, nErr); |
| 927 | if( nErr ) fossil_fatal("abort due to prior errors"); |
| 928 | } |
| 929 | |
| 930 | /* |
| 931 | ** COMMAND: patch |
| 932 | ** |
| 933 | ** Usage: %fossil patch SUBCOMMAND ?ARGS ..? |
| 934 | ** |
| @@ -1003,10 +1009,29 @@ | |
| 1009 | ** View a summary of the changes in the binary patch in PATCHFILE. |
| 1010 | ** Use "fossil patch diff" for detailed patch content. |
| 1011 | ** |
| 1012 | ** -v|--verbose Show extra detail about the patch |
| 1013 | ** |
| 1014 | ** > fossil patch alias add|rm|ls|list ?ARGS? |
| 1015 | ** |
| 1016 | ** Manage remote-name aliases, which act as short-form equivalents |
| 1017 | ** to REMOTE-CHECKOUT strings. |
| 1018 | ** |
| 1019 | ** Subcommands: |
| 1020 | ** |
| 1021 | ** > add local-name REMOTE-CHECKOUT |
| 1022 | ** |
| 1023 | ** Add local-name as an alias for REMOTE-CHECKOUT. |
| 1024 | ** |
| 1025 | ** > ls|list |
| 1026 | ** |
| 1027 | ** List all local aliases. |
| 1028 | ** |
| 1029 | ** > rm [-all]| local-name [...local-nameN] |
| 1030 | ** |
| 1031 | ** Remove all aliases which match the given GLOB patterns, or |
| 1032 | ** all aliases if -all is specified. |
| 1033 | */ |
| 1034 | void patch_cmd(void){ |
| 1035 | const char *zCmd; |
| 1036 | size_t n; |
| 1037 | if( g.argc<3 ){ |
| @@ -1027,17 +1052,13 @@ | |
| 1052 | |
| 1053 | verify_all_options(); |
| 1054 | db_prepare(&q, "SELECT substr(name,13), value FROM config " |
| 1055 | "WHERE name GLOB 'patch-alias:*' ORDER BY name"); |
| 1056 | while( SQLITE_ROW==db_step(&q) ){ |
| 1057 | const char *zName = db_column_text(&q, 0); |
| 1058 | const char *zVal = db_column_text(&q, 1); |
| 1059 | ++nAlias; |
| 1060 | fossil_print("%s = %s\n", zName, zVal); |
| 1061 | } |
| 1062 | db_finalize(&q); |
| 1063 | if( 0==nAlias ){ |
| 1064 | fossil_print("No patch aliases defined\n"); |
| 1065 |