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
|
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: tkdiff
**
** Usage: %fossil diff|tkdiff FILE...
** Show the difference between the current version of a file (as it
** exists on disk) and that same file as it was checked out. Use
** either "diff -u" or "tkdiff".
*/
void diff_cmd(void){
const char *zFile;
Blob cmd;
Blob fname;
int i;
char *zV1 = 0;
char *zV2 = 0;
if( g.argc<3 ){
usage("?OPTIONS? FILE");
}
db_must_be_within_tree();
blob_zero(&cmd);
blob_appendf(&cmd, "%s ", g.argv[1]);
for(i=2; i<g.argc-1; i++){
const char *z = g.argv[i];
if( (strcmp(z,"-v")==0 || strcmp(z,"--version")==0) && i<g.argc-2 ){
if( zV1==0 ){
zV1 = g.argv[i+1];
}else if( zV2==0 ){
zV2 = g.argv[i+1];
}else{
fossil_panic("too many versions");
}
}else{
blob_appendf(&cmd, "%s ", z);
}
}
zFile = g.argv[g.argc-1];
if( !file_tree_name(zFile, &fname) ){
fossil_panic("unknown file: %s", zFile);
}
if( zV1==0 ){
|
<
<
<
|
>
|
>
>
>
>
>
|
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
|
|
>
>
|
>
|
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
|
blob_appendf(pBlob, "\"%s\"", zIn);
z = blob_buffer(pBlob);
for(i=n+1; i<=n+k; i++){
if( z[i]=='"' ) z[i] = '_';
}
}
/*
** COMMAND: diff
**
** Usage: %fossil diff ?-i FILE...
**
** Show the difference between the current version of a file (as it
** exists on disk) and that same file as it was checked out.
** If -i is supplied, the internal diff command will be executed
** otherwise, fossil attempts to use the user configured diff-command.
**
** Here are a few external diff command settings, for example:
**
** %fossil config diff-command=tkdiff
** %fossil config diff-command=eskill22
** %fossil config diff-command=tortoisemerge
** %fossil config diff-command=meld
** %fossil config diff-command=xxdiff
** %fossil config diff-command=kdiff3
*/
void diff_cmd(void){
const char *zFile;
Blob cmd;
Blob fname;
int i, internalDiff;
char *zV1 = 0;
char *zV2 = 0;
internalDiff = find_option("intertal","i",0)!=0;
if( g.argc<3 ){
usage("?OPTIONS? FILE");
}
db_must_be_within_tree();
if( internalDiff==0 ){
const char *zExternalCommand = db_global_get("diff-command", 0);
if( zExternalCommand==0 ){
internalDiff=1;
}
blob_zero(&cmd);
blob_appendf(&cmd, "%s ", zExternalCommand);
}
for(i=2; i<g.argc-1; i++){
const char *z = g.argv[i];
if( (strcmp(z,"-v")==0 || strcmp(z,"--version")==0) && i<g.argc-2 ){
if( zV1==0 ){
zV1 = g.argv[i+1];
}else if( zV2==0 ){
zV2 = g.argv[i+1];
}else{
fossil_panic("too many versions");
}
}else{
if( internalDiff==0 ){
blob_appendf(&cmd, "%s ", z);
}
}
}
zFile = g.argv[g.argc-1];
if( !file_tree_name(zFile, &fname) ){
fossil_panic("unknown file: %s", zFile);
}
if( zV1==0 ){
|
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
}
blob_zero(&vname);
do{
blob_reset(&vname);
blob_appendf(&vname, "%s~%d", zFile, cnt++);
}while( access(blob_str(&vname),0)==0 );
content_get(rid, &record);
blob_write_to_file(&record, blob_str(&vname));
blob_reset(&record);
shell_escape(&cmd, blob_str(&vname));
blob_appendf(&cmd, " ");
shell_escape(&cmd, zFile);
system(blob_str(&cmd));
unlink(blob_str(&vname));
blob_reset(&vname);
blob_reset(&cmd);
}else{
fossil_panic("not yet implemented");
}
blob_reset(&fname);
}
|
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
>
|
115
116
117
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
145
146
147
|
}
blob_zero(&vname);
do{
blob_reset(&vname);
blob_appendf(&vname, "%s~%d", zFile, cnt++);
}while( access(blob_str(&vname),0)==0 );
content_get(rid, &record);
if( internalDiff==1 ){
Blob current;
Blob out;
blob_zero(¤t);
blob_read_from_file(¤t, zFile);
blob_zero(&out);
unified_diff(¤t, &record, 5, &out);
printf("%s\n", blob_str(&out));
blob_reset(¤t);
blob_reset(&out);
}else{
blob_write_to_file(&record, blob_str(&vname));
blob_reset(&record);
shell_escape(&cmd, blob_str(&vname));
blob_appendf(&cmd, " ");
shell_escape(&cmd, zFile);
system(blob_str(&cmd));
unlink(blob_str(&vname));
blob_reset(&vname);
blob_reset(&cmd);
}
}else{
fossil_panic("not yet implemented");
}
blob_reset(&fname);
}
|