Fossil

Check-in [a6a679f11e]
Login

Check-in [a6a679f11e]

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

Overview
Comment:Remove the db_protect() handling made unnecessary by moving patch aliases into the vvar table. Fix argc count validation for (patch alias rm).
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | mistake
Files: files | file ages | folders
SHA3-256: a6a679f11e3fd89620c2667fc51ea41e8e6ceba467e205c712611527005992c9
User & Date: stephan 2025-02-28 05:44:02.715
References
2025-02-28
21:26
Replace doc and arg validation pieces which were removed when [a6a679f11e3fd896] was split into a different branch but are still applicable. ... (Closed-Leaf check-in: da172e6ee3 user: stephan tags: patch-alias)
Context
2025-02-28
05:44
Remove the db_protect() handling made unnecessary by moving patch aliases into the vvar table. Fix argc count validation for (patch alias rm). ... (Closed-Leaf check-in: a6a679f11e user: stephan tags: mistake)
01:31
Place patch aliases in the vvar (checkout) table, not config (repo). (Edit: rolling this back because of request in [forum:8b785d510d|forum post 8b785d510d].) ... (check-in: a10f55ba3f user: stephan tags: mistake)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/patch.c.
703
704
705
706
707
708
709
710

711
712
713
714
715
716
717

/*
** Resolves a patch-command remote system name, accounting for patch
** aliases.
**
** If a VVAR table entry matching name='patch-alias:$zKey' is found,
** the corresponding value is returned, else a fossil_strdup() of zKey
** is returned.

*/
static char * patch_resolve_remote(const char *zKey){
  char * zAlias = db_text(0, "SELECT value FROM vvar "
                          "WHERE name = 'patch-alias:' || %Q",
                          zKey);
  return zAlias ? zAlias : fossil_strdup(zKey);
}







|
>







703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718

/*
** Resolves a patch-command remote system name, accounting for patch
** aliases.
**
** If a VVAR table entry matching name='patch-alias:$zKey' is found,
** the corresponding value is returned, else a fossil_strdup() of zKey
** is returned. The caller is responsible for passing the resulting
** string to fossil_free().
*/
static char * patch_resolve_remote(const char *zKey){
  char * zAlias = db_text(0, "SELECT value FROM vvar "
                          "WHERE name = 'patch-alias:' || %Q",
                          zKey);
  return zAlias ? zAlias : fossil_strdup(zKey);
}
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
      }
    }else if( 0==strcmp("add", zArg) ){
      /* alias add localName remote */
      verify_all_options();
      if( 6!=g.argc ){
        usage("alias add localName remote");
      }
      db_unprotect(PROTECT_CONFIG);
      db_multi_exec("REPLACE INTO vvar (name, value) "
                    "VALUES ('patch-alias:%q', %Q)",
                    g.argv[4], g.argv[5]);
      db_protect_pop();
    }else if( 0==strcmp("rm", zArg) ){
      /* alias rm */
      const int fAll = 0!=find_option("all", 0, 0);
      verify_all_options();
      if( g.argc<5 ){
        usage("alias rm [-all] [aliasGlob [...aliasGlobN]]");
      }
      db_unprotect(PROTECT_CONFIG);

      if( 0!=fAll ){
        db_multi_exec("DELETE FROM vvar WHERE name GLOB 'patch-alias:*'");
      }else{
        Stmt q;
        int i;
        db_prepare(&q, "DELETE FROM vvar WHERE name "
                   "GLOB 'patch-alias:' || :pattern");
        for(i = 4; i < g.argc; ++i){
          db_bind_text(&q, ":pattern", g.argv[i]);
          db_step(&q);
          db_reset(&q);
        }
        db_finalize(&q);
      }
      db_protect_pop();
    }else{
    usage_patch_alias:
      usage("alias ls|list|add|rm ...");
    }
  }else
  if( strncmp(zCmd, "apply", n)==0 ){
    char *zIn;







<



<



<
|


<
>














<







1061
1062
1063
1064
1065
1066
1067

1068
1069
1070

1071
1072
1073

1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091

1092
1093
1094
1095
1096
1097
1098
      }
    }else if( 0==strcmp("add", zArg) ){
      /* alias add localName remote */
      verify_all_options();
      if( 6!=g.argc ){
        usage("alias add localName remote");
      }

      db_multi_exec("REPLACE INTO vvar (name, value) "
                    "VALUES ('patch-alias:%q', %Q)",
                    g.argv[4], g.argv[5]);

    }else if( 0==strcmp("rm", zArg) ){
      /* alias rm */
      const int fAll = 0!=find_option("all", 0, 0);

      if( fAll ? g.argc<4 : g.argc<5 ){
        usage("alias rm [-all] [aliasGlob [...aliasGlobN]]");
      }

      verify_all_options();
      if( 0!=fAll ){
        db_multi_exec("DELETE FROM vvar WHERE name GLOB 'patch-alias:*'");
      }else{
        Stmt q;
        int i;
        db_prepare(&q, "DELETE FROM vvar WHERE name "
                   "GLOB 'patch-alias:' || :pattern");
        for(i = 4; i < g.argc; ++i){
          db_bind_text(&q, ":pattern", g.argv[i]);
          db_step(&q);
          db_reset(&q);
        }
        db_finalize(&q);
      }

    }else{
    usage_patch_alias:
      usage("alias ls|list|add|rm ...");
    }
  }else
  if( strncmp(zCmd, "apply", n)==0 ){
    char *zIn;