Fossil

Check-in [7595bdfb]
Login

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

Overview
Comment:Implement most of the new changes command, still need to do --all, --unmodified, and --extra
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | andygoth-changes
Files: files | file ages | folders
SHA1: 7595bdfbf099418b7b12780563ca1be3d24fc0e3
User & Date: andygoth 2016-11-05 22:22:41
Context
2016-11-05
22:40
Adjust the way --changed is implemented. Improve documentation. Avoid saying EDITED for files with other types of changes if those change types were not selected for display. check-in: 2408fd1c user: andygoth tags: andygoth-changes
22:22
Implement most of the new changes command, still need to do --all, --unmodified, and --extra check-in: 7595bdfb user: andygoth tags: andygoth-changes
21:26
Comment tweak check-in: c3f72593 user: andygoth tags: andygoth-changes
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/checkin.c.

    25     25   /*
    26     26   ** Change filter options.
    27     27   */
    28     28   enum {
    29     29     /* Zero-based bit indexes. */
    30     30     CB_EDITED , CB_UPDATED , CB_CHANGED, CB_MISSING   , CB_ADDED   , CB_DELETED,
    31     31     CB_RENAMED, CB_CONFLICT, CB_META   , CB_UNMODIFIED, CB_EXTRA   , CB_MERGE  ,
    32         -  CB_RELPATH, CB_SHA1SUM , CB_HEADER , CB_VERBOSE   , CB_CLASSIFY,
           32  +  CB_RELPATH, CB_SHA1SUM , CB_HEADER , CB_VERBOSE   , CB_CLASSIFY, CB_FATAL  ,
           33  +  CB_COMMENT,
    33     34   
    34     35     /* Bitmask values. */
    35         -  C_EDITED     = 1 << CB_EDITED,
    36         -  C_UPDATED    = 1 << CB_UPDATED,
    37         -  C_CHANGED    = 1 << CB_CHANGED, /* Becomes CB_EDITED|CB_UPDATED. */
    38         -  C_MISSING    = 1 << CB_MISSING,
    39         -  C_ADDED      = 1 << CB_ADDED,
    40         -  C_DELETED    = 1 << CB_DELETED,
    41         -  C_RENAMED    = 1 << CB_RENAMED,
    42         -  C_CONFLICT   = 1 << CB_CONFLICT,
    43         -  C_META       = 1 << CB_META,
    44         -  C_UNMODIFIED = 1 << CB_UNMODIFIED,
    45         -  C_EXTRA      = 1 << CB_EXTRA,
    46         -  C_MERGE      = 1 << CB_MERGE,
           36  +  C_EDITED     = 1 << CB_EDITED,    /* Edited, merged, and conflicted files. */
           37  +  C_UPDATED    = 1 << CB_UPDATED,   /* Files updated by merge/integrate. */
           38  +  C_CHANGED    = 1 << CB_CHANGED,   /* Becomes CB_EDITED|CB_UPDATED. */
           39  +  C_MISSING    = 1 << CB_MISSING,   /* Missing and non- files. */
           40  +  C_ADDED      = 1 << CB_ADDED,     /* Added files. */
           41  +  C_DELETED    = 1 << CB_DELETED,   /* Deleted files. */
           42  +  C_RENAMED    = 1 << CB_RENAMED,   /* Renamed files. */
           43  +  C_CONFLICT   = 1 << CB_CONFLICT,  /* Files having merge conflicts. */
           44  +  C_META       = 1 << CB_META,      /* Files with metadata changes. */
           45  +  C_UNMODIFIED = 1 << CB_UNMODIFIED,/* Unmodified files. */
           46  +  C_EXTRA      = 1 << CB_EXTRA,     /* Unmanaged files. */
           47  +  C_MERGE      = 1 << CB_MERGE,     /* Merge contributors. */
    47     48     C_FILTER     = C_EDITED  | C_UPDATED | C_CHANGED  | C_MISSING | C_ADDED
    48     49                  | C_DELETED | C_RENAMED | C_CONFLICT | C_META    | C_UNMODIFIED
    49     50                  | C_EXTRA   | C_MERGE,
    50     51     C_ALL        = C_FILTER & ~(C_CHANGED | C_EXTRA | C_MERGE),
    51         -  C_RELPATH    = 1 << CB_RELPATH,
    52         -  C_SHA1SUM    = 1 << CB_SHA1SUM,
    53         -  C_HEADER     = 1 << CB_HEADER,
    54         -  C_VERBOSE    = 1 << CB_VERBOSE,
    55         -  C_CLASSIFY   = 1 << CB_CLASSIFY,
           52  +  C_RELPATH    = 1 << CB_RELPATH,   /* Show relative paths. */
           53  +  C_SHA1SUM    = 1 << CB_SHA1SUM,   /* Use SHA1 checksums not mtimes. */
           54  +  C_HEADER     = 1 << CB_HEADER,    /* Display repository name if non-empty. */
           55  +  C_VERBOSE    = 1 << CB_VERBOSE,   /* Display "(none)" if empty. */
           56  +  C_CLASSIFY   = 1 << CB_CLASSIFY,  /* Show file change types. */
    56     57     C_DEFAULT    = (C_ALL & ~C_UNMODIFIED) | C_MERGE | C_CLASSIFY,
           58  +  C_FATAL      = (1 << CB_FATAL) | C_MISSING, /* Fail on MISSING/NOT_A_FILE. */
           59  +  C_COMMENT    = 1 << CB_COMMENT,   /* Precede each line with "# ". */
    57     60   };
    58     61   
    59     62   /*
    60         -** Generate text describing all changes.  Prepend zPrefix to each line
    61         -** of output.
           63  +** Generate text describing all changes.
    62     64   **
    63     65   ** We assume that vfile_check_signature has been run.
    64         -**
    65         -** If missingIsFatal is true, then any files that are missing or which
    66         -** are not true files results in a fatal error.
    67     66   */
    68     67   static void status_report(
    69     68     Blob *report,          /* Append the status report here */
    70         -  const char *zPrefix,   /* Prefix on each line of the report */
    71         -  int missingIsFatal,    /* MISSING and NOT_A_FILE are fatal errors */
    72         -  int cwdRelative        /* Report relative to the current working dir */
           69  +  unsigned flags         /* Filter and other configuration flags */
    73     70   ){
    74     71     Stmt q;
    75         -  int nPrefix = strlen(zPrefix);
    76     72     int nErr = 0;
    77     73     Blob rewrittenPathname;
    78     74     Blob where;
    79     75     const char *zName;
    80     76     int i;
    81     77   
    82     78     blob_zero(&where);
................................................................................
   105    101       "   AND (chnged OR deleted OR rid=0 OR pathname!=origname)"
   106    102       " ORDER BY 1 /*scan*/",
   107    103       blob_sql_text(&where)
   108    104     );
   109    105     blob_zero(&rewrittenPathname);
   110    106     while( db_step(&q)==SQLITE_ROW ){
   111    107       const char *zPathname = db_column_text(&q,0);
   112         -    const char *zDisplayName = zPathname;
          108  +    const char *zClass = 0;
   113    109       int isDeleted = db_column_int(&q, 1);
   114    110       int isChnged = db_column_int(&q,2);
   115    111       int isNew = db_column_int(&q,3)==0;
   116    112       int isRenamed = db_column_int(&q,4);
   117    113       int isLink = db_column_int(&q,5);
   118    114       char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
   119         -    if( cwdRelative ){
   120         -      file_relative_name(zFullName, &rewrittenPathname, 0);
   121         -      zDisplayName = blob_str(&rewrittenPathname);
   122         -      if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
   123         -        zDisplayName += 2;  /* no unnecessary ./ prefix */
   124         -      }
   125         -    }
   126         -    blob_append(report, zPrefix, nPrefix);
   127         -    if( isDeleted ){
   128         -      blob_appendf(report, "DELETED    %s\n", zDisplayName);
   129         -    }else if( !file_wd_isfile_or_link(zFullName) ){
          115  +    int isMissing = !file_wd_isfile_or_link(zFullName);
          116  +
          117  +    /* Determine the file change classification, if any. */
          118  +    if( (flags & C_DELETED) && isDeleted ){
          119  +      zClass = "DELETED";
          120  +    }else if( (flags & C_MISSING) && isMissing ){
   130    121         if( file_access(zFullName, F_OK)==0 ){
   131         -        blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
   132         -        if( missingIsFatal ){
   133         -          fossil_warning("not a file: %s", zDisplayName);
          122  +        zClass = "NOT_A_FILE";
          123  +        if( flags & C_FATAL ){
          124  +          fossil_warning("not a file: %s", zFullName);
   134    125             nErr++;
   135    126           }
   136    127         }else{
   137         -        blob_appendf(report, "MISSING    %s\n", zDisplayName);
   138         -        if( missingIsFatal ){
   139         -          fossil_warning("missing file: %s", zDisplayName);
          128  +        zClass = "MISSING";
          129  +        if( flags & C_FATAL ){
          130  +          fossil_warning("missing file: %s", zFullName);
   140    131             nErr++;
   141    132           }
   142    133         }
   143         -    }else if( isNew ){
   144         -      blob_appendf(report, "ADDED      %s\n", zDisplayName);
   145         -    }else if( isChnged ){
   146         -      if( isChnged==2 ){
   147         -        blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName);
   148         -      }else if( isChnged==3 ){
   149         -        blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
   150         -      }else if( isChnged==4 ){
   151         -        blob_appendf(report, "UPDATED_BY_INTEGRATE %s\n", zDisplayName);
   152         -      }else if( isChnged==5 ){
   153         -        blob_appendf(report, "ADDED_BY_INTEGRATE %s\n", zDisplayName);
   154         -      }else if( isChnged==6 ){
   155         -        blob_appendf(report, "EXECUTABLE %s\n", zDisplayName);
   156         -      }else if( isChnged==7 ){
   157         -        blob_appendf(report, "SYMLINK    %s\n", zDisplayName);
   158         -      }else if( isChnged==8 ){
   159         -        blob_appendf(report, "UNEXEC     %s\n", zDisplayName);
   160         -      }else if( isChnged==9 ){
   161         -        blob_appendf(report, "UNLINK     %s\n", zDisplayName);
   162         -      }else if( !isLink && file_contains_merge_marker(zFullName) ){
   163         -        blob_appendf(report, "CONFLICT   %s\n", zDisplayName);
          134  +    }else if( (flags & C_ADDED) && isNew ){
          135  +      zClass = "ADDED";
          136  +    }else if( (flags & C_UPDATED) && isChnged==2 ){
          137  +      zClass = "UPDATED_BY_MERGE";
          138  +    }else if( (flags & C_ADDED) && isChnged==3 ){
          139  +      zClass = "ADDED_BY_MERGE";
          140  +    }else if( (flags & C_UPDATED) && isChnged==4 ){
          141  +      zClass = "UPDATED_BY_INTEGRATE";
          142  +    }else if( (flags & C_ADDED) && isChnged==5 ){
          143  +      zClass = "ADDED_BY_INTEGRATE";
          144  +    }else if( (flags & C_META) && isChnged==6 ){
          145  +      zClass = "EXECUTABLE";
          146  +    }else if( (flags & C_META) && isChnged==7 ){
          147  +      zClass = "SYMLINK";
          148  +    }else if( (flags & C_META) && isChnged==8 ){
          149  +      zClass = "UNEXEC";
          150  +    }else if( (flags & C_META) && isChnged==9 ){
          151  +      zClass = "UNLINK";
          152  +    }else if( (flags & C_CONFLICT) && isChnged && !isLink
          153  +           && file_contains_merge_marker(zFullName) ){
          154  +      zClass = "CONFLICT";
          155  +    }else if( (flags & C_EDITED) && isChnged ){
          156  +      zClass = "EDITED";
          157  +    }else if( (flags & C_RENAMED) && isRenamed ){
          158  +      zClass = "RENAMED";
          159  +    }else if( (flags & C_UNMODIFIED) && !isDeleted && !isMissing && !isNew
          160  +                                     && !isChnged  && !isRenamed ){
          161  +      /* TODO: never gets executed because query only yields modified files. */
          162  +      zClass = "UNMODIFIED";
          163  +    }
          164  +    /* TODO: implement C_EXTRA. */
          165  +
          166  +    /* Only report files for which a change classification was determined. */
          167  +    if( zClass ){
          168  +      /* If C_COMMENT, precede each line with "# ". */
          169  +      if( flags & C_COMMENT ){
          170  +        blob_append(report, "# ", 2);
          171  +      }
          172  +
          173  +      /* If C_CLASSIFY, include the change classification. */
          174  +      if( flags & C_CLASSIFY ){
          175  +        blob_appendf(report, "%-10s ", zClass);
          176  +      }
          177  +
          178  +      /* Finish with the filename followed by newline. */
          179  +      if( flags & C_RELPATH ){
          180  +        /* If C_RELPATH, display paths relative to current directory. */
          181  +        const char *zDisplayName;
          182  +        file_relative_name(zFullName, &rewrittenPathname, 0);
          183  +        zDisplayName = blob_str(&rewrittenPathname);
          184  +        if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
          185  +          zDisplayName += 2;  /* no unnecessary ./ prefix */
          186  +        }
          187  +        blob_append(report, zDisplayName, -1);
   164    188         }else{
   165         -        blob_appendf(report, "EDITED     %s\n", zDisplayName);
          189  +        /* If not C_RELPATH, display paths relative to project root. */
          190  +        blob_append(report, zPathname, -1);
   166    191         }
   167         -    }else if( isRenamed ){
   168         -      blob_appendf(report, "RENAMED    %s\n", zDisplayName);
   169         -    }else{
   170         -      report->nUsed -= nPrefix;
          192  +      blob_append(report, "\n", 1);
   171    193       }
   172    194       free(zFullName);
   173    195     }
   174    196     blob_reset(&rewrittenPathname);
   175    197     db_finalize(&q);
   176         -  db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
   177         -                 " WHERE id<=0");
   178         -  while( db_step(&q)==SQLITE_ROW ){
   179         -    const char *zLabel = "MERGED_WITH ";
   180         -    switch( db_column_int(&q, 1) ){
   181         -      case -1:  zLabel = "CHERRYPICK ";  break;
   182         -      case -2:  zLabel = "BACKOUT    ";  break;
   183         -      case -4:  zLabel = "INTEGRATE  ";  break;
          198  +
          199  +  /* If C_MERGE, put merge contributors at the end of the report. */
          200  +  if( flags & C_MERGE ){
          201  +    db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
          202  +                   " WHERE id<=0");
          203  +    while( db_step(&q)==SQLITE_ROW ){
          204  +      /* If C_COMMENT, precede each line with "# ". */
          205  +      if( flags & C_COMMENT ){
          206  +        blob_append(report, "# ", 2);
          207  +      }
          208  +
          209  +      /* If C_CLASSIFY, include the merge type. */
          210  +      if( flags & C_CLASSIFY ){
          211  +        const char *zClass = "MERGED_WITH";
          212  +        switch( db_column_int(&q, 1) ){
          213  +          case -1: zClass = "CHERRYPICK"; break;
          214  +          case -2: zClass = "BACKOUT"   ; break;
          215  +          case -4: zClass = "INTEGRATE" ; break;
          216  +        }
          217  +        blob_appendf(report, "%-10s ", zClass);
          218  +      }
          219  +
          220  +      /* Finish the line with the full SHA1 of the merge contributor. */
          221  +      blob_append(report, db_column_text(&q, 0), -1);
          222  +      blob_append(report, "\n", 1);
   184    223       }
   185         -    blob_append(report, zPrefix, nPrefix);
   186         -    blob_appendf(report, "%s%s\n", zLabel, db_column_text(&q, 0));
          224  +    db_finalize(&q);
   187    225     }
   188         -  db_finalize(&q);
   189    226     if( nErr ){
   190    227       fossil_fatal("aborting due to prior errors");
   191    228     }
   192    229   }
   193    230   
   194    231   /*
   195    232   ** Use the "relative-paths" setting and the --abs-paths and
................................................................................
   204    241     int relPathOption = find_option("rel-paths", 0, 0)!=0;
   205    242     if( absPathOption ){ relativePaths = 0; }
   206    243     if( relPathOption ){ relativePaths = 1; }
   207    244     return relativePaths;
   208    245   }
   209    246   
   210    247   void print_changes(
   211         -  int useSha1sum,     /* Verify file status using SHA1 hashing rather
   212         -                         than relying on file mtimes. */
   213         -  int showHdr,        /* Identify the repository if there are changes */
   214         -  int verboseFlag,    /* Say "(none)" if there are no changes */
   215         -  int cwdRelative     /* Report relative to the current working dir */
          248  +  unsigned flags      /* Configuration flags */
   216    249   ){
   217    250     Blob report;
   218    251     int vid;
   219    252     blob_zero(&report);
   220    253   
   221    254     vid = db_lget_int("checkout", 0);
   222         -  vfile_check_signature(vid, useSha1sum ? CKSIG_SHA1 : 0);
   223         -  status_report(&report, "", 0, cwdRelative);
   224         -  if( verboseFlag && blob_size(&report)==0 ){
          255  +  vfile_check_signature(vid, flags & C_SHA1SUM ? CKSIG_SHA1 : 0);
          256  +  status_report(&report, flags);
          257  +  if( (flags & C_VERBOSE) && blob_size(&report)==0 ){
   225    258       blob_append(&report, "  (none)\n", -1);
   226    259     }
   227         -  if( showHdr && blob_size(&report)>0 ){
          260  +  if( (flags & C_HEADER) && blob_size(&report)>0 ){
   228    261       fossil_print("Changes for %s at %s:\n", db_get("project-name","???"),
   229    262                    g.zLocalRoot);
   230    263     }
   231    264     blob_write_to_file(&report, "-");
   232    265     blob_reset(&report);
   233    266   }
   234    267   
................................................................................
   376    409     }
   377    410     printf("\n");
   378    411   #endif
   379    412   
   380    413     /* We should be done with options. */
   381    414     verify_all_options();
   382    415   
   383         -  print_changes(flags & C_SHA1SUM, flags & C_HEADER,
   384         -                flags & C_VERBOSE, flags & C_RELPATH);
          416  +  print_changes(flags);
   385    417   }
   386    418   
   387    419   /*
   388    420   ** COMMAND: status
   389    421   **
   390    422   ** Usage: %fossil status ?OPTIONS?
   391    423   **
................................................................................
   402    434   **    --sha1sum         Verify file status using SHA1 hashing rather
   403    435   **                      than relying on file mtimes.
   404    436   **
   405    437   ** See also: changes, extras, ls
   406    438   */
   407    439   void status_cmd(void){
   408    440     int vid;
   409         -  int useSha1sum = find_option("sha1sum", 0, 0)!=0;
   410         -  int showHdr = find_option("header",0,0)!=0;
   411         -  int verboseFlag = find_option("verbose","v",0)!=0;
   412         -  int cwdRelative = 0;
          441  +  unsigned flags = C_DEFAULT;
          442  +
          443  +  /* Check options. */
   413    444     db_must_be_within_tree();
   414         -       /* 012345678901234 */
   415         -  cwdRelative = determine_cwd_relative_option();
   416         -
   417         -  /* We should be done with options.. */
          445  +  if( find_option("sha1sum", 0, 0) ){
          446  +    flags |= C_SHA1SUM;
          447  +  }
          448  +  if( find_option("header", 0, 0) ){
          449  +    flags |= C_HEADER;
          450  +  }
          451  +  if( find_option("verbose", "v", 0) ){
          452  +    flags |= C_VERBOSE;
          453  +  }
          454  +  if( determine_cwd_relative_option() ){
          455  +    flags |= C_RELPATH;
          456  +  }
   418    457     verify_all_options();
   419    458   
   420    459     fossil_print("repository:   %s\n", db_repository_filename());
   421    460     fossil_print("local-root:   %s\n", g.zLocalRoot);
   422    461     if( g.zConfigDbName ){
   423    462       fossil_print("config-db:    %s\n", g.zConfigDbName);
   424    463     }
   425    464     vid = db_lget_int("checkout", 0);
   426    465     if( vid ){
   427    466       show_common_info(vid, "checkout:", 1, 1);
   428    467     }
   429    468     db_record_repository_filename(0);
   430         -  print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
          469  +  print_changes(flags);
   431    470     leaf_ambiguity_warning(vid, vid);
   432    471   }
   433    472   
   434    473   /*
   435    474   ** Take care of -r version of ls command
   436    475   */
   437    476   static void ls_cmd_rev(
................................................................................
  1217   1256             blob_appendf(&prompt, "%s%s", p->azTag[i],
  1218   1257                          p->azTag[i+1] ? ", " : "");
  1219   1258           }
  1220   1259         }
  1221   1260         blob_appendf(&prompt, "\n#\n");
  1222   1261       }
  1223   1262     }
  1224         -  status_report(&prompt, "# ", 1, 0);
         1263  +  status_report(&prompt, C_DEFAULT | C_FATAL | C_COMMENT);
  1225   1264     if( g.markPrivate ){
  1226   1265       blob_append(&prompt,
  1227   1266         "# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
  1228   1267         "# repositories.\n"
  1229   1268         "#\n", -1
  1230   1269       );
  1231   1270     }