Fossil

Check-in [73e363ea]
Login

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

Overview
Comment:Add ability to show ticket history from command line. fossil ticket now takes a new history option, which prints the history of a ticket - somewhat like what the history button does on the ticket web GUI.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | venks-emacs
Files: files | file ages | folders
SHA1:73e363ea96424d3fd036e145bc6cce593621bba5
User & Date: venkat 2011-08-30 21:50:18
Context
2011-08-31
07:50
Improve formatting for fossil ticket history. Make small fields print on same line, and make longer ones look better. Closed-Leaf check-in: 374920b2 user: venkat tags: venks-emacs
2011-08-30
21:50
Add ability to show ticket history from command line. fossil ticket now takes a new history option, which prints the history of a ticket - somewhat like what the history button does on the ticket web GUI. check-in: 73e363ea user: venkat tags: venks-emacs
21:46
merge trunk before changes check-in: ffa3b1ea user: venkat tags: venks-emacs
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/tkt.c.

897
898
899
900
901
902
903




904
905
906
907
908
909
910
...
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
...
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982




983

984
985
986
987
988
989
990
...
994
995
996
997
998
999
1000
1001
1002
1003







































































1004
1005
1006
1007
1008
1009
1010
**         in "ticket show". So it's possible, to set multiline text or
**         text with special characters.
**
**     %fossil ticket add FIELD VALUE ?FIELD VALUE .. ? ?-q|--quote?
**
**         like set, but create a new ticket with the given values.
**




** The values in set|add are not validated against the definitions
** given in "Ticket Common Script".
*/
void ticket_cmd(void){
  int n;

  /* do some ints, we want to be inside a checkout */
................................................................................
  ** Check that the user exists.
  */
  if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.zLogin) ){
    fossil_fatal("no such user: %s", g.zLogin);
  }

  if( g.argc<3 ){
    usage("add|fieldlist|set|show");
  }else{
    n = strlen(g.argv[2]);
    if( n==1 && g.argv[2][0]=='s' ){
      /* set/show cannot be distinguished, so show the usage */
      usage("add|fieldlist|set|show");
    }else if( strncmp(g.argv[2],"list",n)==0 ){
      if( g.argc==3 ){
        usage("list fields|reports");
      }else{
        n = strlen(g.argv[3]);
        if( !strncmp(g.argv[3],"fields",n) ){
          /* simply show all field names */
................................................................................
          }

          rptshow( zRep, zSep, zFilterUuid, tktEncoding );

        }
      }else{
        /* add a new ticket or update an existing ticket */
        enum { set,add,err } eCmd = err;
        int i = 0;
        int rid;
        const char *zTktUuid = 0;
        Blob tktchng, cksum;

        /* get command type (set/add) and get uuid, if needed for set */
        if( strncmp(g.argv[2],"set",n)==0 || strncmp(g.argv[2],"change",n)==0 ){




          eCmd = set;

          if( g.argc==3 ){
            usage("set TICKETUUID");
          }
          zTktUuid = db_text(0, 
            "SELECT tkt_uuid FROM ticket WHERE tkt_uuid GLOB '%s*'", g.argv[3]
          );
          if( !zTktUuid ){
................................................................................
        }else if( strncmp(g.argv[2],"add",n)==0 ){
          eCmd = add;
          i = 3;
          zTktUuid = db_text(0, "SELECT lower(hex(randomblob(20)))");
        }
        /* none of set/add, so show the usage! */
        if( eCmd==err ){
          usage("add|fieldlist|set|show");
        }
        







































































        /* read all given ticket field/value pairs from command line */
        if( i==g.argc ){
          fossil_fatal("empty %s command aborted!",g.argv[2]);
        }
        getAllTicketFields();
        /* read commandline and assign fields in the azValue array */
        while( i<g.argc ){







>
>
>
>







 







|




|







 







|






|
>
>
>
>
|
>







 







|

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
...
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
...
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
....
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
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
**         in "ticket show". So it's possible, to set multiline text or
**         text with special characters.
**
**     %fossil ticket add FIELD VALUE ?FIELD VALUE .. ? ?-q|--quote?
**
**         like set, but create a new ticket with the given values.
**
**     %fossil ticket history TICKETUUID
**
**         Show the complete change history for the ticket
**
** The values in set|add are not validated against the definitions
** given in "Ticket Common Script".
*/
void ticket_cmd(void){
  int n;

  /* do some ints, we want to be inside a checkout */
................................................................................
  ** Check that the user exists.
  */
  if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.zLogin) ){
    fossil_fatal("no such user: %s", g.zLogin);
  }

  if( g.argc<3 ){
    usage("add|fieldlist|set|show|history");
  }else{
    n = strlen(g.argv[2]);
    if( n==1 && g.argv[2][0]=='s' ){
      /* set/show cannot be distinguished, so show the usage */
      usage("add|fieldlist|set|show|history");
    }else if( strncmp(g.argv[2],"list",n)==0 ){
      if( g.argc==3 ){
        usage("list fields|reports");
      }else{
        n = strlen(g.argv[3]);
        if( !strncmp(g.argv[3],"fields",n) ){
          /* simply show all field names */
................................................................................
          }

          rptshow( zRep, zSep, zFilterUuid, tktEncoding );

        }
      }else{
        /* add a new ticket or update an existing ticket */
        enum { set,add,history,err } eCmd = err;
        int i = 0;
        int rid;
        const char *zTktUuid = 0;
        Blob tktchng, cksum;

        /* get command type (set/add) and get uuid, if needed for set */
        if( strncmp(g.argv[2],"set",n)==0 || strncmp(g.argv[2],"change",n)==0 ||
           strncmp(g.argv[2],"history",n)==0 ){
          if( strncmp(g.argv[2],"history",n)==0 ){
            eCmd = history;
          }else{
            eCmd = set;
          }
          if( g.argc==3 ){
            usage("set TICKETUUID");
          }
          zTktUuid = db_text(0, 
            "SELECT tkt_uuid FROM ticket WHERE tkt_uuid GLOB '%s*'", g.argv[3]
          );
          if( !zTktUuid ){
................................................................................
        }else if( strncmp(g.argv[2],"add",n)==0 ){
          eCmd = add;
          i = 3;
          zTktUuid = db_text(0, "SELECT lower(hex(randomblob(20)))");
        }
        /* none of set/add, so show the usage! */
        if( eCmd==err ){
          usage("add|fieldlist|set|show|history");
        }

        /* we just handle history separately here, does not get out */
        if( eCmd==history ){
          Stmt q;
          char *zTitle;
          int tagid;

          if ( i != g.argc ){
            fossil_fatal("no other parameters expected to %s!",g.argv[2]);
          }
          tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname GLOB 'tkt-%q*'",zTktUuid);
          if( tagid==0 ){
            fossil_fatal("no such ticket %h", zTktUuid);
          }  
          db_prepare(&q,
            "SELECT datetime(mtime,'localtime'), objid, uuid, NULL, NULL, NULL"
            "  FROM event, blob"
            " WHERE objid IN (SELECT rid FROM tagxref WHERE tagid=%d)"
            "   AND blob.rid=event.objid"
            " UNION "
            "SELECT datetime(mtime,'localtime'), attachid, uuid, src, filename, user"
            "  FROM attachment, blob"
            " WHERE target=(SELECT substr(tagname,5) FROM tag WHERE tagid=%d)"
            "   AND blob.rid=attachid"
            " ORDER BY 1 DESC",
            tagid, tagid
          );
          while( db_step(&q)==SQLITE_ROW ){
            Manifest *pTicket;
            char zShort[12];
            const char *zDate = db_column_text(&q, 0);
            int rid = db_column_int(&q, 1);
            const char *zChngUuid = db_column_text(&q, 2);
            const char *zFile = db_column_text(&q, 4);
            memcpy(zShort, zChngUuid, 10);
            zShort[10] = 0;
            if( zFile!=0 ){
              const char *zSrc = db_column_text(&q, 3);
              const char *zUser = db_column_text(&q, 5);
              if( zSrc==0 || zSrc[0]==0 ){
                fossil_print("Delete attachment %h\n", zFile);
              }else{
                fossil_print("Add attachment %h\n", zFile);
              }
              fossil_print(" by %h on %h\n", zUser, zDate);
            }else{
              pTicket = manifest_get(rid, CFTYPE_TICKET);
              if( pTicket ){
                int i;

                fossil_print("Ticket Change by %h on %h:\n", pTicket->zUser, zDate);
                for(i=0; i<pTicket->nField; i++){
                  Blob val;
                  const char *z;
                  z = pTicket->aField[i].zName;
                  blob_set(&val, pTicket->aField[i].zValue);
                  if( z[0]=='+' ){
                    fossil_print("    Appended to %h:\n       ",&z[1]);
                    comment_print(blob_str(&val),7,79);
                  }else{
                    fossil_print("    Change %h to:\n       ",z);
                    comment_print(blob_str(&val),7,79);
                  }
                  blob_reset(&val);
                }
              }
              manifest_destroy(pTicket);
            }
          }
          db_finalize(&q);
          return;
        }
        /* read all given ticket field/value pairs from command line */
        if( i==g.argc ){
          fossil_fatal("empty %s command aborted!",g.argv[2]);
        }
        getAllTicketFields();
        /* read commandline and assign fields in the azValue array */
        while( i<g.argc ){