Fossil

Check-in [c863ec1a]
Login

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

Overview
Comment:The "diff" command with no arguments now does a diff on all files in the checkout which have been edited.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c863ec1a98c424f6c1518a2f9fb72409dec32ff2
User & Date: drh 2008-10-21 06:52:23
Original Comment: The "diff" command with no arguments now does a diff on all files in the checkout which have been edited.
Context
2008-10-22
19:35
Add a --nofork option to "tag branch" so that --raw is not being used for two different purposes. Modify and tidy up the corresponding help text. check-in: c887b2b6 user: eric tags: trunk
2008-10-21
06:52
The "diff" command with no arguments now does a diff on all files in the checkout which have been edited. check-in: c863ec1a user: drh tags: trunk
06:10
Add "ci" as an alias for "commit". Make provisions for a future "fossil mv" command. check-in: 2bde9f9b user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/diffcmd.c.

29
30
31
32
33
34
35
36
37


38
39
40
41
42





























































43
44
45
46
47
48
49
..
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
96
97
98
99
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

/*
** Shell-escape the given string.  Append the result to a blob.
*/
static void shell_escape(Blob *pBlob, const char *zIn){
  int n = blob_size(pBlob);
  int k = strlen(zIn);
  int i;
  char *z;


  blob_appendf(pBlob, "\"%s\"", zIn);
  z = blob_buffer(pBlob);
  for(i=n+1; i<=n+k; i++){
    if( z[i]=='"' ) z[i] = '_';
  }





























































}

/*
** COMMAND: diff
** COMMAND: gdiff
**
** Usage: %fossil diff|gdiff ?-i? ?-r REVISION? FILE...
................................................................................
**   %fossil setting gdiff-command eskill22
**   %fossil setting gdiff-command tortoisemerge
**   %fossil setting gdiff-command meld
**   %fossil setting gdiff-command xxdiff
**   %fossil setting gdiff-command kdiff3
*/
void diff_cmd(void){

  const char *zFile, *zRevision;
  Blob cmd;
  Blob fname;
  Blob vname;
  Blob record;
  int cnt=0,internalDiff;

  internalDiff = find_option("internal","i",0)!=0;
  zRevision = find_option("revision", "r", 1);
  verify_all_options();






  if( g.argc<3 ){
    usage("?OPTIONS? FILE");
  }
  db_must_be_within_tree();

  if( internalDiff==0 ){
    const char *zExternalCommand;
    if( strcmp(g.argv[1], "diff")==0 ){
      zExternalCommand = db_get("diff-command", 0);
    }else{
      zExternalCommand = db_get("gdiff-command", 0);
    }
    if( zExternalCommand==0 ){
      internalDiff=1;
    }
................................................................................
  if( zRevision==0 ){
    int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
    if( rid==0 ){
      fossil_panic("no history for file: %b", &fname);
    }
    content_get(rid, &record);
  }else{
    historical_version_of_file(zRevision, zFile, &record);
  }
  if( internalDiff==1 ){
    Blob out;
    Blob current;
    blob_zero(&current);
    blob_read_from_file(&current, zFile);
    blob_zero(&out);
    text_diff(&record, &current, &out, 5);
    printf("%s\n", blob_str(&out));







|

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







 







>










>

>
>
>
>



<



|







 







|

|







29
30
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
...
130
131
132
133
134
135
136
137
138
139
140
141
142
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
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

/*
** Shell-escape the given string.  Append the result to a blob.
*/
static void shell_escape(Blob *pBlob, const char *zIn){
  int n = blob_size(pBlob);
  int k = strlen(zIn);
  int i, c;
  char *z;
  for(i=0; (c = zIn[i])!=0; i++){
    if( isspace(c) || c=='"' || (c=='\\' && zIn[i+1]!=0) ){
      blob_appendf(pBlob, "\"%s\"", zIn);
      z = blob_buffer(pBlob);
      for(i=n+1; i<=n+k; i++){
        if( z[i]=='"' ) z[i] = '_';
      }
      return;
    }
  }
  blob_append(pBlob, zIn, -1);
}

/*
** Run the fossil diff command separately for every file in the current
** checkout that has changed.
*/
static void diff_all(int internalDiff,  const char *zRevision){
  Stmt q;
  Blob cmd;
  int nCmdBase;
  int vid;
  
  vid = db_lget_int("checkout", 0);
  vfile_check_signature(vid);
  blob_zero(&cmd);
  shell_escape(&cmd, g.argv[0]);
  blob_append(&cmd, " diff ", -1);
  if( internalDiff ){
    blob_append(&cmd, "-i ", -1);
  }
  if( zRevision ){
    blob_append(&cmd, "-r ", -1);
    shell_escape(&cmd, zRevision);
    blob_append(&cmd, " ", 1);
  }
  nCmdBase = blob_size(&cmd);
  db_prepare(&q, 
    "SELECT pathname, deleted, chnged, rid FROM vfile "
    "WHERE chnged OR deleted OR rid=0 ORDER BY 1"
  );

  while( db_step(&q)==SQLITE_ROW ){
    const char *zPathname = db_column_text(&q,0);
    int isDeleted = db_column_int(&q, 1);
    int isChnged = db_column_int(&q,2);
    int isNew = db_column_int(&q,3)==0;
    char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
    cmd.nUsed = nCmdBase;
    if( isDeleted ){
      printf("DELETED  %s\n", zPathname);
    }else if( access(zFullName, 0) ){
      printf("MISSING  %s\n", zPathname);
    }else if( isNew ){
      printf("ADDED    %s\n", zPathname);
    }else if( isDeleted ){
      printf("DELETED  %s\n", zPathname);
    }else if( isChnged==3 ){
      printf("ADDED_BY_MERGE %s\n", zPathname);
    }else{
      shell_escape(&cmd, zFullName);
      printf("%s\n", blob_str(&cmd));
      fflush(stdout);
      system(blob_str(&cmd));
    }
    free(zFullName);
  }
  db_finalize(&q);
}

/*
** COMMAND: diff
** COMMAND: gdiff
**
** Usage: %fossil diff|gdiff ?-i? ?-r REVISION? FILE...
................................................................................
**   %fossil setting gdiff-command eskill22
**   %fossil setting gdiff-command tortoisemerge
**   %fossil setting gdiff-command meld
**   %fossil setting gdiff-command xxdiff
**   %fossil setting gdiff-command kdiff3
*/
void diff_cmd(void){
  int isGDiff = g.argv[1][0]=='g';
  const char *zFile, *zRevision;
  Blob cmd;
  Blob fname;
  Blob vname;
  Blob record;
  int cnt=0,internalDiff;

  internalDiff = find_option("internal","i",0)!=0;
  zRevision = find_option("revision", "r", 1);
  verify_all_options();
  db_must_be_within_tree();

  if( !isGDiff && g.argc==2 ){
    diff_all(internalDiff, zRevision);
    return;
  }
  if( g.argc<3 ){
    usage("?OPTIONS? FILE");
  }


  if( internalDiff==0 ){
    const char *zExternalCommand;
    if( !isGDiff ){
      zExternalCommand = db_get("diff-command", 0);
    }else{
      zExternalCommand = db_get("gdiff-command", 0);
    }
    if( zExternalCommand==0 ){
      internalDiff=1;
    }
................................................................................
  if( zRevision==0 ){
    int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
    if( rid==0 ){
      fossil_panic("no history for file: %b", &fname);
    }
    content_get(rid, &record);
  }else{
    historical_version_of_file(zRevision, blob_str(&fname), &record);
  }
  if( internalDiff ){
    Blob out;
    Blob current;
    blob_zero(&current);
    blob_read_from_file(&current, zFile);
    blob_zero(&out);
    text_diff(&record, &current, &out, 5);
    printf("%s\n", blob_str(&out));