Fossil

Check-in [a05bbff4]
Login

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

Overview
Comment:By default, the changes and status commands list all changed files relative to the current working directory, unless the --non-relative option is used.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ben-changes-report
Files: files | file ages | folders
SHA1: a05bbff46acb84964af5aaae53b11f6939030a38
User & Date: ben 2011-07-10 15:01:34
Context
2011-07-11
10:00
By default, the extras command lists all the uncontrolled files relative to the current working directory, unless the --non-relative option is used. check-in: b9a38cf3 user: ben tags: ben-changes-report
2011-07-10
15:01
By default, the changes and status commands list all changed files relative to the current working directory, unless the --non-relative option is used. check-in: a05bbff4 user: ben tags: ben-changes-report
13:01
When running the changes or status command from inside a sub-directory of the check out, only show the changes in or below the current directory unless the --show-all option is used. check-in: e0d2e1f9 user: ben tags: ben-changes-report
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/checkin.c.

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88







89
90
91
92
93
94
95
...
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
** If missingIsFatal is true, then any files that are missing or which
** are not true files results in a fatal error.
*/
static void status_report(
  Blob *report,          /* Append the status report here */
  const char *zPrefix,   /* Prefix on each line of the report */
  int missingIsFatal,    /* MISSING and NOT_A_FILE are fatal errors */
  int reportSubdirOnly   /* Only report for the current sub-dir */ 
){
  Stmt q;
  int nPrefix = strlen(zPrefix);
  int nErr = 0;
  Blob currentDir, rootDir;
  const char *zShowSubDir = 0;
  int showSubDirLen = 0;
  int otherChanges = 0;
  db_prepare(&q, 
    "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
    "  FROM vfile "
    " WHERE file_is_selected(id)"
    "   AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1"
  );
  /* If sub-directory only reports are acceptable, check to see if we're
  ** in a sub-directory of the checkout. */
  if( reportSubdirOnly ){
    blob_zero(&currentDir);
    file_canonical_name(".", &currentDir);
    blob_zero(&rootDir);
    file_canonical_name(g.zLocalRoot, &rootDir);
    if( blob_compare(&currentDir, &rootDir)!=0
        && blob_size(&currentDir)>blob_size(&rootDir) ){
      /* Current directory is not the root of the repository */
      blob_appendf(report, "%sIn sub-directory %s:\n", zPrefix,
        blob_str(&currentDir) + blob_size(&rootDir) + 1);
      blob_append(&currentDir,"/",1);
      zShowSubDir = blob_str(&currentDir) + blob_size(&rootDir) + 1;
      showSubDirLen = blob_size(&currentDir) - blob_size(&rootDir) - 1;
    }
  }
  /* Show the changes */
  while( db_step(&q)==SQLITE_ROW ){
    const char *zPathname = db_column_text(&q,0);
    const char *zDisplayName = zPathname;
    if( zShowSubDir!=0 ){
      if( strncmp(zPathname,zShowSubDir,showSubDirLen)!=0 ){
        /* Not in sub-directory, don't display this file */
        otherChanges++;
        continue;
      }else{
        /* In sub directory, so hide the prefix */
        zDisplayName += showSubDirLen;
      }
    }
    int isDeleted = db_column_int(&q, 1);
    int isChnged = db_column_int(&q,2);
    int isNew = db_column_int(&q,3)==0;
    int isRenamed = db_column_int(&q,4);
    char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);







    blob_append(report, zPrefix, nPrefix);
    if( isDeleted ){
      blob_appendf(report, "DELETED    %s\n", zDisplayName);
    }else if( !file_isfile(zFullName) ){
      if( file_access(zFullName, 0)==0 ){
        blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
        if( missingIsFatal ){
................................................................................
    }else if( isChnged==1 ){
      blob_appendf(report, "EDITED     %s\n", zDisplayName);
    }else if( isRenamed ){
      blob_appendf(report, "RENAMED    %s\n", zDisplayName);
    }
    free(zFullName);
  }

  db_finalize(&q);
  db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid"
                 " WHERE id=0");
  while( db_step(&q)==SQLITE_ROW ){
    blob_append(report, zPrefix, nPrefix);
    blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0));
  }
  db_finalize(&q);
  if( otherChanges!=0 ){
    blob_appendf(report, "%d other changes. Use --show-all option to list all changes.\n");
  }
  if( nErr ){
    fossil_fatal("aborting due to prior errors");
  }
}

/*
** COMMAND: changes
................................................................................
** See also the "status" and "extra" commands.
**
** Options:
**
**    --sha1sum         Verify file status using SHA1 hashing rather
**                      than relying on file mtimes.
**
**    --show-all        When invoked from a sub-directory, show changes
**                      even if they're outside the current directory.
*/
void changes_cmd(void){
  Blob report;
  int vid;
  int useSha1sum = find_option("sha1sum", 0, 0)!=0;
  int showAllFlag = find_option("show-all","S",0)!=0;
  db_must_be_within_tree();
  blob_zero(&report);
  vid = db_lget_int("checkout", 0);
  vfile_check_signature(vid, 0, useSha1sum);
  status_report(&report, "", 0, !showAllFlag);
  blob_write_to_file(&report, "-");
}

/*
** COMMAND: status
**
** Usage: %fossil status







|




|
<
<
<






<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<



<
<
<
<
<
<
<
<
<
<





>
>
>
>
>
>
>







 







>








<
<
<







 







|
|





|




|







31
32
33
34
35
36
37
38
39
40
41
42
43



44
45
46
47
48
49





50












51
52
53










54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106



107
108
109
110
111
112
113
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
** If missingIsFatal is true, then any files that are missing or which
** are not true files results in a fatal error.
*/
static void status_report(
  Blob *report,          /* Append the status report here */
  const char *zPrefix,   /* Prefix on each line of the report */
  int missingIsFatal,    /* MISSING and NOT_A_FILE are fatal errors */
  int cwdRelative        /* Report relative to the current working dir */ 
){
  Stmt q;
  int nPrefix = strlen(zPrefix);
  int nErr = 0;
  Blob rewrittenPathname;



  db_prepare(&q, 
    "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
    "  FROM vfile "
    " WHERE file_is_selected(id)"
    "   AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1"
  );





  blob_zero(&rewrittenPathname);












  while( db_step(&q)==SQLITE_ROW ){
    const char *zPathname = db_column_text(&q,0);
    const char *zDisplayName = zPathname;










    int isDeleted = db_column_int(&q, 1);
    int isChnged = db_column_int(&q,2);
    int isNew = db_column_int(&q,3)==0;
    int isRenamed = db_column_int(&q,4);
    char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
    if( cwdRelative ){
      file_relative_name(zFullName, &rewrittenPathname);
      zDisplayName = blob_str(&rewrittenPathname);
      if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
        zDisplayName += 2;  /* no unnecessary ./ prefix */
      }
    }
    blob_append(report, zPrefix, nPrefix);
    if( isDeleted ){
      blob_appendf(report, "DELETED    %s\n", zDisplayName);
    }else if( !file_isfile(zFullName) ){
      if( file_access(zFullName, 0)==0 ){
        blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
        if( missingIsFatal ){
................................................................................
    }else if( isChnged==1 ){
      blob_appendf(report, "EDITED     %s\n", zDisplayName);
    }else if( isRenamed ){
      blob_appendf(report, "RENAMED    %s\n", zDisplayName);
    }
    free(zFullName);
  }
  blob_reset(&rewrittenPathname);
  db_finalize(&q);
  db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid"
                 " WHERE id=0");
  while( db_step(&q)==SQLITE_ROW ){
    blob_append(report, zPrefix, nPrefix);
    blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0));
  }
  db_finalize(&q);



  if( nErr ){
    fossil_fatal("aborting due to prior errors");
  }
}

/*
** COMMAND: changes
................................................................................
** See also the "status" and "extra" commands.
**
** Options:
**
**    --sha1sum         Verify file status using SHA1 hashing rather
**                      than relying on file mtimes.
**
**    --non-relative    Don't display filenames relative to the current
**                      working directory.
*/
void changes_cmd(void){
  Blob report;
  int vid;
  int useSha1sum = find_option("sha1sum", 0, 0)!=0;
  int nonRelative = find_option("non-relative", 0, 0)!=0;
  db_must_be_within_tree();
  blob_zero(&report);
  vid = db_lget_int("checkout", 0);
  vfile_check_signature(vid, 0, useSha1sum);
  status_report(&report, "", 0, !nonRelative);
  blob_write_to_file(&report, "-");
}

/*
** COMMAND: status
**
** Usage: %fossil status