|
dbda8d6…
|
drh
|
1 |
/* |
|
c19f34c…
|
drh
|
2 |
** Copyright (c) 2007 D. Richard Hipp |
|
dbda8d6…
|
drh
|
3 |
** |
|
dbda8d6…
|
drh
|
4 |
** This program is free software; you can redistribute it and/or |
|
c06edd2…
|
drh
|
5 |
** modify it under the terms of the Simplified BSD License (also |
|
c06edd2…
|
drh
|
6 |
** known as the "2-Clause License" or "FreeBSD License".) |
|
c06edd2…
|
drh
|
7 |
|
|
dbda8d6…
|
drh
|
8 |
** This program is distributed in the hope that it will be useful, |
|
c06edd2…
|
drh
|
9 |
** but without any warranty; without even the implied warranty of |
|
c06edd2…
|
drh
|
10 |
** merchantability or fitness for a particular purpose. |
|
dbda8d6…
|
drh
|
11 |
** |
|
dbda8d6…
|
drh
|
12 |
** Author contact information: |
|
dbda8d6…
|
drh
|
13 |
** [email protected] |
|
dbda8d6…
|
drh
|
14 |
** http://www.hwaci.com/drh/ |
|
dbda8d6…
|
drh
|
15 |
** |
|
dbda8d6…
|
drh
|
16 |
******************************************************************************* |
|
dbda8d6…
|
drh
|
17 |
** |
|
dbda8d6…
|
drh
|
18 |
** This file contains code used to merge the changes in the current |
|
bc36fdc…
|
danield
|
19 |
** check-out into a different version and switch to that version. |
|
dbda8d6…
|
drh
|
20 |
*/ |
|
dbda8d6…
|
drh
|
21 |
#include "config.h" |
|
dbda8d6…
|
drh
|
22 |
#include "update.h" |
|
dbda8d6…
|
drh
|
23 |
#include <assert.h> |
|
dbda8d6…
|
drh
|
24 |
|
|
dbda8d6…
|
drh
|
25 |
/* |
|
d0305b3…
|
aku
|
26 |
** Return true if artifact rid is a version |
|
d0305b3…
|
aku
|
27 |
*/ |
|
d0305b3…
|
aku
|
28 |
int is_a_version(int rid){ |
|
4980b9a…
|
drh
|
29 |
return db_exists("SELECT 1 FROM event WHERE objid=%d AND type='ci'", rid); |
|
4980b9a…
|
drh
|
30 |
} |
|
4980b9a…
|
drh
|
31 |
|
|
12a2a5e…
|
drh
|
32 |
/* This variable is set if we are doing an internal update. It is clear |
|
12a2a5e…
|
drh
|
33 |
** when running the "update" command. |
|
12a2a5e…
|
drh
|
34 |
*/ |
|
12a2a5e…
|
drh
|
35 |
static int internalUpdate = 0; |
|
12a2a5e…
|
drh
|
36 |
static int internalConflictCnt = 0; |
|
12a2a5e…
|
drh
|
37 |
|
|
12a2a5e…
|
drh
|
38 |
/* |
|
080ab8c…
|
jan.nijtmans
|
39 |
** Do an update to version vid. |
|
12a2a5e…
|
drh
|
40 |
** |
|
12a2a5e…
|
drh
|
41 |
** Start an undo session but do not terminate it. Do not autosync. |
|
12a2a5e…
|
drh
|
42 |
*/ |
|
12a2a5e…
|
drh
|
43 |
int update_to(int vid){ |
|
12a2a5e…
|
drh
|
44 |
int savedArgc; |
|
12a2a5e…
|
drh
|
45 |
char **savedArgv; |
|
12a2a5e…
|
drh
|
46 |
char *newArgv[3]; |
|
12a2a5e…
|
drh
|
47 |
newArgv[0] = g.argv[0]; |
|
12a2a5e…
|
drh
|
48 |
newArgv[1] = "update"; |
|
12a2a5e…
|
drh
|
49 |
newArgv[2] = 0; |
|
12a2a5e…
|
drh
|
50 |
savedArgv = g.argv; |
|
12a2a5e…
|
drh
|
51 |
savedArgc = g.argc; |
|
12a2a5e…
|
drh
|
52 |
g.argc = 2; |
|
12a2a5e…
|
drh
|
53 |
g.argv = newArgv; |
|
12a2a5e…
|
drh
|
54 |
internalUpdate = vid; |
|
12a2a5e…
|
drh
|
55 |
internalConflictCnt = 0; |
|
12a2a5e…
|
drh
|
56 |
update_cmd(); |
|
12a2a5e…
|
drh
|
57 |
g.argc = savedArgc; |
|
12a2a5e…
|
drh
|
58 |
g.argv = savedArgv; |
|
12a2a5e…
|
drh
|
59 |
return internalConflictCnt; |
|
12a2a5e…
|
drh
|
60 |
} |
|
12a2a5e…
|
drh
|
61 |
|
|
d0305b3…
|
aku
|
62 |
/* |
|
dbda8d6…
|
drh
|
63 |
** COMMAND: update |
|
dbda8d6…
|
drh
|
64 |
** |
|
75ea5ac…
|
drh
|
65 |
** Usage: %fossil update ?OPTIONS? ?VERSION? ?FILES...? |
|
75ea5ac…
|
drh
|
66 |
** |
|
bc36fdc…
|
danield
|
67 |
** Change the version of the current check-out to VERSION. Any |
|
bc36fdc…
|
danield
|
68 |
** uncommitted changes are retained and applied to the new check-out. |
|
75ea5ac…
|
drh
|
69 |
** |
|
8ab520c…
|
stephan
|
70 |
** The VERSION argument can be a specific version or tag or branch |
|
8ab520c…
|
stephan
|
71 |
** name. If the VERSION argument is omitted, then the leaf of the |
|
8ab520c…
|
stephan
|
72 |
** subtree that begins at the current version is used, if there is |
|
8ab520c…
|
stephan
|
73 |
** only a single leaf. VERSION can also be "current" to select the |
|
8ab520c…
|
stephan
|
74 |
** leaf of the current version or "latest" to select the most recent |
|
8ab520c…
|
stephan
|
75 |
** check-in. |
|
2d996b0…
|
drh
|
76 |
** |
|
2d996b0…
|
drh
|
77 |
** If one or more FILES are listed after the VERSION then only the |
|
8ab520c…
|
stephan
|
78 |
** named files are candidates to be updated, and any updates to them |
|
8ab520c…
|
stephan
|
79 |
** will be treated as edits to the current version. Using a directory |
|
8ab520c…
|
stephan
|
80 |
** name for one of the FILES arguments is the same as using every |
|
8ab520c…
|
stephan
|
81 |
** subdirectory and file beneath that directory. |
|
8ab520c…
|
stephan
|
82 |
** |
|
bc36fdc…
|
danield
|
83 |
** If FILES is omitted, all files in the current check-out are subject |
|
bc36fdc…
|
danield
|
84 |
** to being updated and the version of the current check-out is changed |
|
8ab520c…
|
stephan
|
85 |
** to VERSION. Any uncommitted changes are retained and applied to the |
|
bc36fdc…
|
danield
|
86 |
** new check-out. |
|
8ab520c…
|
stephan
|
87 |
** |
|
8ab520c…
|
stephan
|
88 |
** The -n or --dry-run option causes this command to do a "dry run". |
|
8ab520c…
|
stephan
|
89 |
** It prints out what would have happened but does not actually make |
|
bc36fdc…
|
danield
|
90 |
** any changes to the current check-out or the repository. |
|
8ab520c…
|
stephan
|
91 |
** |
|
8ab520c…
|
stephan
|
92 |
** The -v or --verbose option prints status information about |
|
33d3bf3…
|
km
|
93 |
** unchanged files in addition to those files that actually do change. |
|
75ea5ac…
|
drh
|
94 |
** |
|
75ea5ac…
|
drh
|
95 |
** Options: |
|
4e4ae18…
|
danshearer
|
96 |
** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol, |
|
4e4ae18…
|
danshearer
|
97 |
** if required by the remote site |
|
dc97155…
|
drh
|
98 |
** --case-sensitive BOOL Override case-sensitive setting |
|
dc97155…
|
drh
|
99 |
** --debug Print debug information on stdout |
|
dc97155…
|
drh
|
100 |
** -n|--dry-run If given, display instead of run actions |
|
dc97155…
|
drh
|
101 |
** --force-missing Force update if missing content after sync |
|
dc97155…
|
drh
|
102 |
** -K|--keep-merge-files On merge conflict, retain the temporary files |
|
dc97155…
|
drh
|
103 |
** used for merging, named *-baseline, *-original, |
|
dc97155…
|
drh
|
104 |
** and *-merge. |
|
dc97155…
|
drh
|
105 |
** --latest Acceptable in place of VERSION, update to |
|
dc97155…
|
drh
|
106 |
** latest version |
|
dc97155…
|
drh
|
107 |
** --nosync Do not auto-sync prior to update |
|
6d4cd32…
|
mgagnon
|
108 |
** --proxy PROXY Use PROXY as http proxy during sync operation |
|
dc97155…
|
drh
|
109 |
** --setmtime Set timestamps of all files to match their |
|
dc97155…
|
drh
|
110 |
** SCM-side times (the timestamp of the last |
|
bc36fdc…
|
danield
|
111 |
** check-in which modified them). |
|
dc97155…
|
drh
|
112 |
** -v|--verbose Print status information about all files |
|
dc97155…
|
drh
|
113 |
** -W|--width WIDTH Width of lines (default is to auto-detect). |
|
dc97155…
|
drh
|
114 |
** Must be more than 20 or 0 (= no limit, |
|
dc97155…
|
drh
|
115 |
** resulting in a single line per entry). |
|
e58c76a…
|
drh
|
116 |
** |
|
c965636…
|
drh
|
117 |
** See also: [[revert]] |
|
dbda8d6…
|
drh
|
118 |
*/ |
|
dbda8d6…
|
drh
|
119 |
void update_cmd(void){ |
|
dbda8d6…
|
drh
|
120 |
int vid; /* Current version */ |
|
d0305b3…
|
aku
|
121 |
int tid=0; /* Target version - version we are changing to */ |
|
dbda8d6…
|
drh
|
122 |
Stmt q; |
|
1d9ebd9…
|
drh
|
123 |
int latestFlag; /* --latest. Pick the latest version if true */ |
|
0b86639…
|
jan.nijtmans
|
124 |
int dryRunFlag; /* -n or --dry-run. Do a dry run */ |
|
1d9ebd9…
|
drh
|
125 |
int verboseFlag; /* -v or --verbose. Output extra information */ |
|
16da1b6…
|
andybradford
|
126 |
int forceMissingFlag; /* --force-missing. Continue if missing content */ |
|
fd8698c…
|
drh
|
127 |
int debugFlag; /* --debug option */ |
|
ae092ec…
|
drh
|
128 |
int setmtimeFlag; /* --setmtime. Set mtimes on files */ |
|
d20ead1…
|
drh
|
129 |
int keepMergeFlag; /* True if --keep-merge-files is present */ |
|
fd8698c…
|
drh
|
130 |
int nChng; /* Number of file renames */ |
|
fd8698c…
|
drh
|
131 |
int *aChng; /* Array of file renames */ |
|
fd8698c…
|
drh
|
132 |
int i; /* Loop counter */ |
|
e331396…
|
drh
|
133 |
int nConflict = 0; /* Number of merge conflicts */ |
|
39f979b…
|
drh
|
134 |
int nOverwrite = 0; /* Number of unmanaged files overwritten */ |
|
db0c512…
|
drh
|
135 |
int nUpdate = 0; /* Number of changes of any kind */ |
|
dc97155…
|
drh
|
136 |
int bNosync = 0; /* --nosync. Omit the auto-sync */ |
|
e3df30f…
|
mistachkin
|
137 |
int width; /* Width of printed comment lines */ |
|
db0c512…
|
drh
|
138 |
Stmt mtimeXfer; /* Statement to transfer mtimes */ |
|
e3df30f…
|
mistachkin
|
139 |
const char *zWidth; /* Width option string value */ |
|
4e4ae18…
|
danshearer
|
140 |
const char *zHttpAuth; /* --httpauth USER:PASS for the autosync */ |
|
2453717…
|
drh
|
141 |
const char *zCurBrName; /* Current branch name */ |
|
2453717…
|
drh
|
142 |
const char *zNewBrName; /* New branch name */ |
|
2453717…
|
drh
|
143 |
const char *zBrChgMsg = ""; /* Message to display if branch changes */ |
|
dbda8d6…
|
drh
|
144 |
|
|
12a2a5e…
|
drh
|
145 |
if( !internalUpdate ){ |
|
12a2a5e…
|
drh
|
146 |
undo_capture_command_line(); |
|
12a2a5e…
|
drh
|
147 |
url_proxy_options(); |
|
e3df30f…
|
mistachkin
|
148 |
} |
|
e3df30f…
|
mistachkin
|
149 |
zWidth = find_option("width","W",1); |
|
e3df30f…
|
mistachkin
|
150 |
if( zWidth ){ |
|
e3df30f…
|
mistachkin
|
151 |
width = atoi(zWidth); |
|
e3df30f…
|
mistachkin
|
152 |
if( (width!=0) && (width<=20) ){ |
|
e3df30f…
|
mistachkin
|
153 |
fossil_fatal("-W|--width value must be >20 or 0"); |
|
e3df30f…
|
mistachkin
|
154 |
} |
|
e3df30f…
|
mistachkin
|
155 |
}else{ |
|
e3df30f…
|
mistachkin
|
156 |
width = -1; |
|
0b86639…
|
jan.nijtmans
|
157 |
} |
|
d0305b3…
|
aku
|
158 |
latestFlag = find_option("latest",0, 0)!=0; |
|
0b86639…
|
jan.nijtmans
|
159 |
dryRunFlag = find_option("dry-run","n",0)!=0; |
|
0b86639…
|
jan.nijtmans
|
160 |
if( !dryRunFlag ){ |
|
0b86639…
|
jan.nijtmans
|
161 |
dryRunFlag = find_option("nochange",0,0)!=0; /* deprecated */ |
|
0b86639…
|
jan.nijtmans
|
162 |
} |
|
1d9ebd9…
|
drh
|
163 |
verboseFlag = find_option("verbose","v",0)!=0; |
|
16da1b6…
|
andybradford
|
164 |
forceMissingFlag = find_option("force-missing",0,0)!=0; |
|
fd8698c…
|
drh
|
165 |
debugFlag = find_option("debug",0,0)!=0; |
|
ae092ec…
|
drh
|
166 |
setmtimeFlag = find_option("setmtime",0,0)!=0; |
|
d20ead1…
|
drh
|
167 |
keepMergeFlag = find_option("keep-merge-files", "K",0)!=0; |
|
dc97155…
|
drh
|
168 |
bNosync = find_option("nosync",0,0)!=0; |
|
4e4ae18…
|
danshearer
|
169 |
zHttpAuth = find_option("httpauth","B",1); |
|
4e4ae18…
|
danshearer
|
170 |
if( zHttpAuth && zHttpAuth[0] ) g.zHttpAuth = fossil_strdup(zHttpAuth); |
|
74ac0c9…
|
drh
|
171 |
|
|
74ac0c9…
|
drh
|
172 |
/* We should be done with options.. */ |
|
74ac0c9…
|
drh
|
173 |
verify_all_options(); |
|
74ac0c9…
|
drh
|
174 |
|
|
dbda8d6…
|
drh
|
175 |
db_must_be_within_tree(); |
|
dbda8d6…
|
drh
|
176 |
vid = db_lget_int("checkout", 0); |
|
2453717…
|
drh
|
177 |
zCurBrName = branch_of_rid(vid); |
|
8e50e2e…
|
drh
|
178 |
user_select(); |
|
dc97155…
|
drh
|
179 |
if( !dryRunFlag && !internalUpdate && !bNosync ){ |
|
346e457…
|
drh
|
180 |
if( autosync_loop(SYNC_PULL + SYNC_VERBOSE*verboseFlag, 1, "update") ){ |
|
d685096…
|
drh
|
181 |
fossil_fatal("update abandoned due to sync failure"); |
|
16da1b6…
|
andybradford
|
182 |
} |
|
195517a…
|
drh
|
183 |
} |
|
080ab8c…
|
jan.nijtmans
|
184 |
|
|
195517a…
|
drh
|
185 |
/* Create any empty directories now, as well as after the update, |
|
195517a…
|
drh
|
186 |
** so changes in settings are reflected now */ |
|
f132f86…
|
drh
|
187 |
if( !dryRunFlag ) ensure_empty_dirs_created(0); |
|
12a2a5e…
|
drh
|
188 |
|
|
12a2a5e…
|
drh
|
189 |
if( internalUpdate ){ |
|
12a2a5e…
|
drh
|
190 |
tid = internalUpdate; |
|
12a2a5e…
|
drh
|
191 |
}else if( g.argc>=3 ){ |
|
32ad9a1…
|
drh
|
192 |
if( fossil_strcmp(g.argv[2], "current")==0 ){ |
|
2d996b0…
|
drh
|
193 |
/* If VERSION is "current", then use the same algorithm to find the |
|
2d996b0…
|
drh
|
194 |
** target as if VERSION were omitted. */ |
|
32ad9a1…
|
drh
|
195 |
}else if( fossil_strcmp(g.argv[2], "latest")==0 ){ |
|
2d996b0…
|
drh
|
196 |
/* If VERSION is "latest", then use the same algorithm to find the |
|
2d996b0…
|
drh
|
197 |
** target as if VERSION were omitted and the --latest flag is present. |
|
2d996b0…
|
drh
|
198 |
*/ |
|
2d996b0…
|
drh
|
199 |
latestFlag = 1; |
|
2d996b0…
|
drh
|
200 |
}else{ |
|
2a013f0…
|
drh
|
201 |
tid = name_to_typed_rid(g.argv[2],"ci"); |
|
f78cba5…
|
drh
|
202 |
if( tid==0 || !is_a_version(tid) ){ |
|
f78cba5…
|
drh
|
203 |
fossil_fatal("no such check-in: %s", g.argv[2]); |
|
4beacb6…
|
drh
|
204 |
} |
|
4beacb6…
|
drh
|
205 |
} |
|
4beacb6…
|
drh
|
206 |
} |
|
080ab8c…
|
jan.nijtmans
|
207 |
|
|
fd8698c…
|
drh
|
208 |
/* If no VERSION is specified on the command-line, then look for a |
|
c9d3900…
|
danield
|
209 |
** descendant of the current version. If there are multiple descendants, |
|
fd8698c…
|
drh
|
210 |
** look for one from the same branch as the current version. If there |
|
db0c512…
|
drh
|
211 |
** are still multiple descendants, show them all and refuse to update |
|
fd8698c…
|
drh
|
212 |
** until the user selects one. |
|
fd8698c…
|
drh
|
213 |
*/ |
|
4beacb6…
|
drh
|
214 |
if( tid==0 ){ |
|
4beacb6…
|
drh
|
215 |
int closeCode = 1; |
|
4beacb6…
|
drh
|
216 |
compute_leaves(vid, closeCode); |
|
4beacb6…
|
drh
|
217 |
if( !db_exists("SELECT 1 FROM leaves") ){ |
|
4beacb6…
|
drh
|
218 |
closeCode = 0; |
|
4beacb6…
|
drh
|
219 |
compute_leaves(vid, closeCode); |
|
4beacb6…
|
drh
|
220 |
} |
|
4beacb6…
|
drh
|
221 |
if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){ |
|
4beacb6…
|
drh
|
222 |
db_multi_exec( |
|
4beacb6…
|
drh
|
223 |
"DELETE FROM leaves WHERE rid NOT IN" |
|
4beacb6…
|
drh
|
224 |
" (SELECT leaves.rid FROM leaves, tagxref" |
|
4beacb6…
|
drh
|
225 |
" WHERE leaves.rid=tagxref.rid AND tagxref.tagid=%d" |
|
4beacb6…
|
drh
|
226 |
" AND tagxref.value==(SELECT value FROM tagxref" |
|
4beacb6…
|
drh
|
227 |
" WHERE tagid=%d AND rid=%d))", |
|
4beacb6…
|
drh
|
228 |
TAG_BRANCH, TAG_BRANCH, vid |
|
4beacb6…
|
drh
|
229 |
); |
|
4beacb6…
|
drh
|
230 |
if( db_int(0, "SELECT count(*) FROM leaves")>1 ){ |
|
4beacb6…
|
drh
|
231 |
compute_leaves(vid, closeCode); |
|
080ab8c…
|
jan.nijtmans
|
232 |
db_prepare(&q, |
|
4beacb6…
|
drh
|
233 |
"%s " |
|
4beacb6…
|
drh
|
234 |
" AND event.objid IN leaves" |
|
4beacb6…
|
drh
|
235 |
" ORDER BY event.mtime DESC", |
|
4beacb6…
|
drh
|
236 |
timeline_query_for_tty() |
|
4beacb6…
|
drh
|
237 |
); |
|
e86aeb7…
|
drh
|
238 |
print_timeline(&q, -100, width, 0, 0); |
|
4beacb6…
|
drh
|
239 |
db_finalize(&q); |
|
4beacb6…
|
drh
|
240 |
fossil_fatal("Multiple descendants"); |
|
4beacb6…
|
drh
|
241 |
} |
|
f76192b…
|
aku
|
242 |
} |
|
d0305b3…
|
aku
|
243 |
tid = db_int(0, "SELECT rid FROM leaves, event" |
|
d0305b3…
|
aku
|
244 |
" WHERE event.objid=leaves.rid" |
|
080ab8c…
|
jan.nijtmans
|
245 |
" ORDER BY event.mtime DESC"); |
|
1343cfa…
|
drh
|
246 |
if( tid==0 ) tid = vid; |
|
3243e63…
|
drh
|
247 |
} |
|
3243e63…
|
drh
|
248 |
|
|
88e9f24…
|
drh
|
249 |
if( tid==0 ){ |
|
b725c1c…
|
jan.nijtmans
|
250 |
return; |
|
88e9f24…
|
drh
|
251 |
} |
|
88e9f24…
|
drh
|
252 |
|
|
e1962ef…
|
drh
|
253 |
db_begin_transaction(); |
|
f132f86…
|
drh
|
254 |
db_multi_exec( |
|
f132f86…
|
drh
|
255 |
"CREATE TEMP TABLE dir_to_delete(name TEXT %s PRIMARY KEY)WITHOUT ROWID", |
|
f132f86…
|
drh
|
256 |
filename_collation() |
|
f132f86…
|
drh
|
257 |
); |
|
ae092ec…
|
drh
|
258 |
vfile_check_signature(vid, CKSIG_ENOTFILE); |
|
0b86639…
|
jan.nijtmans
|
259 |
if( !dryRunFlag && !internalUpdate ) undo_begin(); |
|
16da1b6…
|
andybradford
|
260 |
if( load_vfile_from_rid(tid) && !forceMissingFlag ){ |
|
16da1b6…
|
andybradford
|
261 |
fossil_fatal("missing content, unable to update"); |
|
16da1b6…
|
andybradford
|
262 |
}; |
|
dbda8d6…
|
drh
|
263 |
|
|
dbda8d6…
|
drh
|
264 |
/* |
|
dbda8d6…
|
drh
|
265 |
** The record.fn field is used to match files against each other. The |
|
e2bdc10…
|
danield
|
266 |
** FV table contains one row for each unique filename in |
|
bc36fdc…
|
danield
|
267 |
** in the current check-out, the pivot, and the version being merged. |
|
dbda8d6…
|
drh
|
268 |
*/ |
|
dbda8d6…
|
drh
|
269 |
db_multi_exec( |
|
dbda8d6…
|
drh
|
270 |
"DROP TABLE IF EXISTS fv;" |
|
dbda8d6…
|
drh
|
271 |
"CREATE TEMP TABLE fv(" |
|
a5a8d04…
|
drh
|
272 |
" fn TEXT %s PRIMARY KEY," /* The filename relative to root */ |
|
dbda8d6…
|
drh
|
273 |
" idv INTEGER," /* VFILE entry for current version */ |
|
dbda8d6…
|
drh
|
274 |
" idt INTEGER," /* VFILE entry for target version */ |
|
dbda8d6…
|
drh
|
275 |
" chnged BOOLEAN," /* True if current version has been edited */ |
|
e4f1c1f…
|
drh
|
276 |
" islinkv BOOLEAN," /* True if current file is a link */ |
|
e4f1c1f…
|
drh
|
277 |
" islinkt BOOLEAN," /* True if target file is a link */ |
|
dbda8d6…
|
drh
|
278 |
" ridv INTEGER," /* Record ID for current version */ |
|
fd8698c…
|
drh
|
279 |
" ridt INTEGER," /* Record ID for target */ |
|
3ad119b…
|
drh
|
280 |
" isexe BOOLEAN," /* Does target have execute permission? */ |
|
5a1d13e…
|
drh
|
281 |
" deleted BOOLEAN DEFAULT 0,"/* File marked by "rm" to become unmanaged */ |
|
a5a8d04…
|
drh
|
282 |
" fnt TEXT %s" /* Filename of same file on target version */ |
|
a5a8d04…
|
drh
|
283 |
");", |
|
a5a8d04…
|
drh
|
284 |
filename_collation(), filename_collation() |
|
fd8698c…
|
drh
|
285 |
); |
|
fd8698c…
|
drh
|
286 |
|
|
fd8698c…
|
drh
|
287 |
/* Add files found in the current version |
|
fd8698c…
|
drh
|
288 |
*/ |
|
fd8698c…
|
drh
|
289 |
db_multi_exec( |
|
28272fa…
|
drh
|
290 |
"INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged,deleted)" |
|
28272fa…
|
drh
|
291 |
" SELECT pathname, pathname, id, 0, rid, 0, isexe, chnged, deleted" |
|
3ad119b…
|
drh
|
292 |
" FROM vfile WHERE vid=%d", |
|
fd8698c…
|
drh
|
293 |
vid |
|
fd8698c…
|
drh
|
294 |
); |
|
fd8698c…
|
drh
|
295 |
|
|
fd8698c…
|
drh
|
296 |
/* Compute file name changes on V->T. Record name changes in files that |
|
fd8698c…
|
drh
|
297 |
** have changed locally. |
|
fd8698c…
|
drh
|
298 |
*/ |
|
c6c05c8…
|
jan.nijtmans
|
299 |
if( vid ){ |
|
c6c05c8…
|
jan.nijtmans
|
300 |
find_filename_changes(vid, tid, 1, &nChng, &aChng, debugFlag ? "V->T": 0); |
|
c6c05c8…
|
jan.nijtmans
|
301 |
if( nChng ){ |
|
c6c05c8…
|
jan.nijtmans
|
302 |
for(i=0; i<nChng; i++){ |
|
c6c05c8…
|
jan.nijtmans
|
303 |
db_multi_exec( |
|
c6c05c8…
|
jan.nijtmans
|
304 |
"UPDATE fv" |
|
c6c05c8…
|
jan.nijtmans
|
305 |
" SET fnt=(SELECT name FROM filename WHERE fnid=%d)" |
|
c6c05c8…
|
jan.nijtmans
|
306 |
" WHERE fn=(SELECT name FROM filename WHERE fnid=%d) AND chnged", |
|
c6c05c8…
|
jan.nijtmans
|
307 |
aChng[i*2+1], aChng[i*2] |
|
c6c05c8…
|
jan.nijtmans
|
308 |
); |
|
c6c05c8…
|
jan.nijtmans
|
309 |
} |
|
c6c05c8…
|
jan.nijtmans
|
310 |
fossil_free(aChng); |
|
c6c05c8…
|
jan.nijtmans
|
311 |
} |
|
fd8698c…
|
drh
|
312 |
} |
|
fd8698c…
|
drh
|
313 |
|
|
fd8698c…
|
drh
|
314 |
/* Add files found in the target version T but missing from the current |
|
fd8698c…
|
drh
|
315 |
** version V. |
|
fd8698c…
|
drh
|
316 |
*/ |
|
fd8698c…
|
drh
|
317 |
db_multi_exec( |
|
3ad119b…
|
drh
|
318 |
"INSERT OR IGNORE INTO fv(fn,fnt,idv,idt,ridv,ridt,isexe,chnged)" |
|
3ad119b…
|
drh
|
319 |
" SELECT pathname, pathname, 0, 0, 0, 0, isexe, 0 FROM vfile" |
|
fd8698c…
|
drh
|
320 |
" WHERE vid=%d" |
|
a5a8d04…
|
drh
|
321 |
" AND pathname %s NOT IN (SELECT fnt FROM fv)", |
|
a5a8d04…
|
drh
|
322 |
tid, filename_collation() |
|
fd8698c…
|
drh
|
323 |
); |
|
fd8698c…
|
drh
|
324 |
|
|
fd8698c…
|
drh
|
325 |
/* |
|
fd8698c…
|
drh
|
326 |
** Compute the file version ids for T |
|
fd8698c…
|
drh
|
327 |
*/ |
|
fd8698c…
|
drh
|
328 |
db_multi_exec( |
|
fd8698c…
|
drh
|
329 |
"UPDATE fv SET" |
|
a5a8d04…
|
drh
|
330 |
" idt=coalesce((SELECT id FROM vfile WHERE vid=%d AND fnt=pathname),0)," |
|
a5a8d04…
|
drh
|
331 |
" ridt=coalesce((SELECT rid FROM vfile WHERE vid=%d AND fnt=pathname),0)", |
|
fd8698c…
|
drh
|
332 |
tid, tid |
|
fd8698c…
|
drh
|
333 |
); |
|
fd8698c…
|
drh
|
334 |
|
|
e4f1c1f…
|
drh
|
335 |
/* |
|
e4f1c1f…
|
drh
|
336 |
** Add islink information |
|
e4f1c1f…
|
drh
|
337 |
*/ |
|
e4f1c1f…
|
drh
|
338 |
db_multi_exec( |
|
e4f1c1f…
|
drh
|
339 |
"UPDATE fv SET" |
|
b18a178…
|
drh
|
340 |
" islinkv=coalesce((SELECT islink FROM vfile" |
|
a5a8d04…
|
drh
|
341 |
" WHERE vid=%d AND fnt=pathname),0)," |
|
b18a178…
|
drh
|
342 |
" islinkt=coalesce((SELECT islink FROM vfile" |
|
a5a8d04…
|
drh
|
343 |
" WHERE vid=%d AND fnt=pathname),0)", |
|
e4f1c1f…
|
drh
|
344 |
vid, tid |
|
e4f1c1f…
|
drh
|
345 |
); |
|
e4f1c1f…
|
drh
|
346 |
|
|
e4f1c1f…
|
drh
|
347 |
|
|
fd8698c…
|
drh
|
348 |
if( debugFlag ){ |
|
fd8698c…
|
drh
|
349 |
db_prepare(&q, |
|
b18a178…
|
drh
|
350 |
"SELECT rowid, fn, fnt, chnged, ridv, ridt, isexe," |
|
b18a178…
|
drh
|
351 |
" islinkv, islinkt FROM fv" |
|
fd8698c…
|
drh
|
352 |
); |
|
fd8698c…
|
drh
|
353 |
while( db_step(&q)==SQLITE_ROW ){ |
|
b18a178…
|
drh
|
354 |
fossil_print("%3d: ridv=%-4d ridt=%-4d chnged=%d isexe=%d" |
|
b18a178…
|
drh
|
355 |
" islinkv=%d islinkt=%d\n", |
|
fd8698c…
|
drh
|
356 |
db_column_int(&q, 0), |
|
fd8698c…
|
drh
|
357 |
db_column_int(&q, 4), |
|
fd8698c…
|
drh
|
358 |
db_column_int(&q, 5), |
|
3ad119b…
|
drh
|
359 |
db_column_int(&q, 3), |
|
e4f1c1f…
|
drh
|
360 |
db_column_int(&q, 6), |
|
e4f1c1f…
|
drh
|
361 |
db_column_int(&q, 7), |
|
e4f1c1f…
|
drh
|
362 |
db_column_int(&q, 8)); |
|
d8ec765…
|
drh
|
363 |
fossil_print(" fnv = [%s]\n", db_column_text(&q, 1)); |
|
d8ec765…
|
drh
|
364 |
fossil_print(" fnt = [%s]\n", db_column_text(&q, 2)); |
|
fd8698c…
|
drh
|
365 |
} |
|
fd8698c…
|
drh
|
366 |
db_finalize(&q); |
|
fd8698c…
|
drh
|
367 |
} |
|
2d996b0…
|
drh
|
368 |
|
|
2d996b0…
|
drh
|
369 |
/* If FILES appear on the command-line, remove from the "fv" table |
|
c01e3c1…
|
drh
|
370 |
** every entry that is not named on the command-line or which is not |
|
c01e3c1…
|
drh
|
371 |
** in a directory named on the command-line. |
|
2d996b0…
|
drh
|
372 |
*/ |
|
2d996b0…
|
drh
|
373 |
if( g.argc>=4 ){ |
|
2d996b0…
|
drh
|
374 |
Blob sql; /* SQL statement to purge unwanted entries */ |
|
2d996b0…
|
drh
|
375 |
Blob treename; /* Normalized filename */ |
|
2d996b0…
|
drh
|
376 |
int i; /* Loop counter */ |
|
c01e3c1…
|
drh
|
377 |
const char *zSep; /* Term separator */ |
|
2d996b0…
|
drh
|
378 |
|
|
2d996b0…
|
drh
|
379 |
blob_zero(&sql); |
|
c01e3c1…
|
drh
|
380 |
blob_append(&sql, "DELETE FROM fv WHERE ", -1); |
|
c01e3c1…
|
drh
|
381 |
zSep = ""; |
|
2d996b0…
|
drh
|
382 |
for(i=3; i<g.argc; i++){ |
|
c56a387…
|
mistachkin
|
383 |
file_tree_name(g.argv[i], &treename, 0, 1); |
|
1772357…
|
drh
|
384 |
if( file_isdir(g.argv[i], RepoFILE)==1 ){ |
|
c97535c…
|
dmitry
|
385 |
if( blob_size(&treename) != 1 || blob_str(&treename)[0] != '.' ){ |
|
080ab8c…
|
jan.nijtmans
|
386 |
blob_append_sql(&sql, "%sfn NOT GLOB '%q/*' ", |
|
49b0ff1…
|
drh
|
387 |
zSep /*safe-for-%s*/, blob_str(&treename)); |
|
c01e3c1…
|
drh
|
388 |
}else{ |
|
c01e3c1…
|
drh
|
389 |
blob_reset(&sql); |
|
c01e3c1…
|
drh
|
390 |
break; |
|
c01e3c1…
|
drh
|
391 |
} |
|
c01e3c1…
|
drh
|
392 |
}else{ |
|
49b0ff1…
|
drh
|
393 |
blob_append_sql(&sql, "%sfn<>%Q ", |
|
49b0ff1…
|
drh
|
394 |
zSep /*safe-for-%s*/, blob_str(&treename)); |
|
c01e3c1…
|
drh
|
395 |
} |
|
c01e3c1…
|
drh
|
396 |
zSep = "AND "; |
|
2d996b0…
|
drh
|
397 |
blob_reset(&treename); |
|
2d996b0…
|
drh
|
398 |
} |
|
49b0ff1…
|
drh
|
399 |
db_multi_exec("%s", blob_sql_text(&sql)); |
|
2d996b0…
|
drh
|
400 |
blob_reset(&sql); |
|
2d996b0…
|
drh
|
401 |
} |
|
2d996b0…
|
drh
|
402 |
|
|
fd8698c…
|
drh
|
403 |
/* |
|
bc36fdc…
|
danield
|
404 |
** Alter the content of the check-out so that it conforms with the |
|
fd8698c…
|
drh
|
405 |
** target |
|
fd8698c…
|
drh
|
406 |
*/ |
|
080ab8c…
|
jan.nijtmans
|
407 |
db_prepare(&q, |
|
b18a178…
|
drh
|
408 |
"SELECT fn, idv, ridv, idt, ridt, chnged, fnt," |
|
28272fa…
|
drh
|
409 |
" isexe, islinkv, islinkt, deleted FROM fv ORDER BY 1" |
|
ffe1b60…
|
drh
|
410 |
); |
|
ffe1b60…
|
drh
|
411 |
db_prepare(&mtimeXfer, |
|
ffe1b60…
|
drh
|
412 |
"UPDATE vfile SET mtime=(SELECT mtime FROM vfile WHERE id=:idv)" |
|
ffe1b60…
|
drh
|
413 |
" WHERE id=:idt" |
|
2d996b0…
|
drh
|
414 |
); |
|
dfb5fd6…
|
drh
|
415 |
assert( g.zLocalRoot!=0 ); |
|
af194db…
|
mgagnon
|
416 |
assert( strlen(g.zLocalRoot)>0 ); |
|
dfb5fd6…
|
drh
|
417 |
assert( g.zLocalRoot[strlen(g.zLocalRoot)-1]=='/' ); |
|
3a18c95…
|
drh
|
418 |
merge_info_init(); |
|
2d996b0…
|
drh
|
419 |
while( db_step(&q)==SQLITE_ROW ){ |
|
2d996b0…
|
drh
|
420 |
const char *zName = db_column_text(&q, 0); /* The filename from root */ |
|
d861fe7…
|
drh
|
421 |
int idv = db_column_int(&q, 1); /* VFILE entry for current */ |
|
d861fe7…
|
drh
|
422 |
int ridv = db_column_int(&q, 2); /* RecordID for current */ |
|
d861fe7…
|
drh
|
423 |
int idt = db_column_int(&q, 3); /* VFILE entry for target */ |
|
d861fe7…
|
drh
|
424 |
int ridt = db_column_int(&q, 4); /* RecordID for target */ |
|
d861fe7…
|
drh
|
425 |
int chnged = db_column_int(&q, 5); /* Current is edited */ |
|
fd8698c…
|
drh
|
426 |
const char *zNewName = db_column_text(&q,6);/* New filename */ |
|
37c231b…
|
drh
|
427 |
int isexe = db_column_int(&q, 7); /* EXE perm for new file */ |
|
e4f1c1f…
|
drh
|
428 |
int islinkv = db_column_int(&q, 8); /* Is current file is a link */ |
|
e4f1c1f…
|
drh
|
429 |
int islinkt = db_column_int(&q, 9); /* Is target file is a link */ |
|
28272fa…
|
drh
|
430 |
int deleted = db_column_int(&q, 10); /* Marked for deletion */ |
|
eaef1a7…
|
drh
|
431 |
char *zFullPath; /* Full pathname of the file */ |
|
fd8698c…
|
drh
|
432 |
char *zFullNewPath; /* Full pathname of dest */ |
|
fd8698c…
|
drh
|
433 |
char nameChng; /* True if the name changed */ |
|
565a490…
|
drh
|
434 |
const char *zOp = 0; /* Type of change. */ |
|
565a490…
|
drh
|
435 |
i64 sz = 0; /* Size of the file */ |
|
565a490…
|
drh
|
436 |
int nc = 0; /* Number of conflicts */ |
|
565a490…
|
drh
|
437 |
const char *zErrMsg = 0; /* Error message */ |
|
eaef1a7…
|
drh
|
438 |
|
|
dfb5fd6…
|
drh
|
439 |
zFullPath = mprintf("%s%s", g.zLocalRoot, zName); |
|
fd8698c…
|
drh
|
440 |
zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName); |
|
565a490…
|
drh
|
441 |
sz = file_size(zFullNewPath, ExtFILE); |
|
31c52c7…
|
drh
|
442 |
nameChng = fossil_strcmp(zName, zNewName); |
|
3db1cf6…
|
drh
|
443 |
nUpdate++; |
|
28272fa…
|
drh
|
444 |
if( deleted ){ |
|
28272fa…
|
drh
|
445 |
db_multi_exec("UPDATE vfile SET deleted=1 WHERE id=%d", idt); |
|
28272fa…
|
drh
|
446 |
} |
|
dfb5fd6…
|
drh
|
447 |
if( idv>0 && ridv==0 && idt>0 && ridt>0 ){ |
|
bc36fdc…
|
danield
|
448 |
/* Conflict. This file has been added to the current check-out |
|
bc36fdc…
|
danield
|
449 |
** but also exists in the target check-out. Use the current version. |
|
eaef1a7…
|
drh
|
450 |
*/ |
|
d8ec765…
|
drh
|
451 |
fossil_print("CONFLICT %s\n", zName); |
|
070ce24…
|
drh
|
452 |
nConflict++; |
|
565a490…
|
drh
|
453 |
zOp = "CONFLICT"; |
|
565a490…
|
drh
|
454 |
nc = 1; |
|
565a490…
|
drh
|
455 |
zErrMsg = "duplicate file"; |
|
eaef1a7…
|
drh
|
456 |
}else if( idt>0 && idv==0 ){ |
|
eaef1a7…
|
drh
|
457 |
/* File added in the target. */ |
|
1772357…
|
drh
|
458 |
if( file_isfile_or_link(zFullPath) ){ |
|
e99e58c…
|
mgagnon
|
459 |
/* Name of backup file with Original content */ |
|
e99e58c…
|
mgagnon
|
460 |
char *zOrig = file_newname(zFullPath, "original", 1); |
|
e2bdc10…
|
danield
|
461 |
/* Backup previously unmanaged file before being overwritten */ |
|
e99e58c…
|
mgagnon
|
462 |
file_copy(zFullPath, zOrig); |
|
e99e58c…
|
mgagnon
|
463 |
fossil_print("ADD %s - overwrites an unmanaged file", zName); |
|
adb6840…
|
drh
|
464 |
if( !dryRunFlag ){ |
|
adb6840…
|
drh
|
465 |
fossil_print(", original copy backed up as \"%s\"", zOrig); |
|
adb6840…
|
drh
|
466 |
file_delete(zFullPath); |
|
adb6840…
|
drh
|
467 |
} |
|
e99e58c…
|
mgagnon
|
468 |
fossil_print("\n"); |
|
adb6840…
|
drh
|
469 |
fossil_free(zOrig); |
|
39f979b…
|
drh
|
470 |
nOverwrite++; |
|
565a490…
|
drh
|
471 |
nc = 1; |
|
565a490…
|
drh
|
472 |
zOp = "CONFLICT"; |
|
565a490…
|
drh
|
473 |
zErrMsg = "new file overwrites unmanaged file"; |
|
39f979b…
|
drh
|
474 |
}else{ |
|
39f979b…
|
drh
|
475 |
fossil_print("ADD %s\n", zName); |
|
39f979b…
|
drh
|
476 |
} |
|
d795eb0…
|
mistachkin
|
477 |
if( !dryRunFlag && !internalUpdate ) undo_save(zName); |
|
0b86639…
|
jan.nijtmans
|
478 |
if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0); |
|
28272fa…
|
drh
|
479 |
}else if( idt>0 && idv>0 && ridt!=ridv && (chnged==0 || deleted) ){ |
|
eaef1a7…
|
drh
|
480 |
/* The file is unedited. Change it to the target version */ |
|
28272fa…
|
drh
|
481 |
if( deleted ){ |
|
5a1d13e…
|
drh
|
482 |
fossil_print("UPDATE %s - change to unmanaged file\n", zName); |
|
28272fa…
|
drh
|
483 |
}else{ |
|
28272fa…
|
drh
|
484 |
fossil_print("UPDATE %s\n", zName); |
|
28272fa…
|
drh
|
485 |
} |
|
d795eb0…
|
mistachkin
|
486 |
if( !dryRunFlag && !internalUpdate ) undo_save(zName); |
|
0b86639…
|
jan.nijtmans
|
487 |
if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0); |
|
565a490…
|
drh
|
488 |
zOp = "UPDATE"; |
|
1772357…
|
drh
|
489 |
}else if( idt>0 && idv>0 && !deleted && file_size(zFullPath, RepoFILE)<0 ){ |
|
eaef1a7…
|
drh
|
490 |
/* The file missing from the local check-out. Restore it to the |
|
eaef1a7…
|
drh
|
491 |
** version that appears in the target. */ |
|
2918eff…
|
drh
|
492 |
fossil_print("UPDATE %s\n", zName); |
|
d795eb0…
|
mistachkin
|
493 |
if( !dryRunFlag && !internalUpdate ) undo_save(zName); |
|
0b86639…
|
jan.nijtmans
|
494 |
if( !dryRunFlag ) vfile_to_disk(0, idt, 0, 0); |
|
565a490…
|
drh
|
495 |
zOp = "UPDATE"; |
|
eaef1a7…
|
drh
|
496 |
}else if( idt==0 && idv>0 ){ |
|
eaef1a7…
|
drh
|
497 |
if( ridv==0 ){ |
|
bc36fdc…
|
danield
|
498 |
/* Added in current check-out. Continue to hold the file as |
|
eaef1a7…
|
drh
|
499 |
** as an addition */ |
|
eaef1a7…
|
drh
|
500 |
db_multi_exec("UPDATE vfile SET vid=%d WHERE id=%d", tid, idv); |
|
eaef1a7…
|
drh
|
501 |
}else if( chnged ){ |
|
fd8698c…
|
drh
|
502 |
/* Edited locally but deleted from the target. Do not track the |
|
fd8698c…
|
drh
|
503 |
** file but keep the edited version around. */ |
|
d8ec765…
|
drh
|
504 |
fossil_print("CONFLICT %s - edited locally but deleted by update\n", |
|
d8ec765…
|
drh
|
505 |
zName); |
|
565a490…
|
drh
|
506 |
zOp = "CONFLICT"; |
|
565a490…
|
drh
|
507 |
zErrMsg = "edited locally but deleted by update"; |
|
565a490…
|
drh
|
508 |
nc = 1; |
|
070ce24…
|
drh
|
509 |
nConflict++; |
|
eaef1a7…
|
drh
|
510 |
}else{ |
|
d8ec765…
|
drh
|
511 |
fossil_print("REMOVE %s\n", zName); |
|
d795eb0…
|
mistachkin
|
512 |
if( !dryRunFlag && !internalUpdate ) undo_save(zName); |
|
f132f86…
|
drh
|
513 |
if( !dryRunFlag ){ |
|
f132f86…
|
drh
|
514 |
char *zDir; |
|
f132f86…
|
drh
|
515 |
file_delete(zFullPath); |
|
f132f86…
|
drh
|
516 |
zDir = file_dirname(zName); |
|
f132f86…
|
drh
|
517 |
while( zDir!=0 ){ |
|
f132f86…
|
drh
|
518 |
char *zNext; |
|
f132f86…
|
drh
|
519 |
db_multi_exec("INSERT OR IGNORE INTO dir_to_delete(name)" |
|
f132f86…
|
drh
|
520 |
"VALUES(%Q)", zDir); |
|
f132f86…
|
drh
|
521 |
zNext = db_changes() ? file_dirname(zDir) : 0; |
|
f132f86…
|
drh
|
522 |
fossil_free(zDir); |
|
f132f86…
|
drh
|
523 |
zDir = zNext; |
|
f132f86…
|
drh
|
524 |
} |
|
f132f86…
|
drh
|
525 |
} |
|
eaef1a7…
|
drh
|
526 |
} |
|
eaef1a7…
|
drh
|
527 |
}else if( idt>0 && idv>0 && ridt!=ridv && chnged ){ |
|
fd8698c…
|
drh
|
528 |
if( nameChng ){ |
|
d8ec765…
|
drh
|
529 |
fossil_print("MERGE %s -> %s\n", zName, zNewName); |
|
d8ec765…
|
drh
|
530 |
}else{ |
|
d8ec765…
|
drh
|
531 |
fossil_print("MERGE %s\n", zName); |
|
d8ec765…
|
drh
|
532 |
} |
|
1772357…
|
drh
|
533 |
if( islinkv || islinkt ){ |
|
e4f1c1f…
|
drh
|
534 |
fossil_print("***** Cannot merge symlink %s\n", zNewName); |
|
3a18c95…
|
drh
|
535 |
zOp = "CONFLICT"; |
|
080ab8c…
|
jan.nijtmans
|
536 |
nConflict++; |
|
c97535c…
|
dmitry
|
537 |
}else{ |
|
1611c97…
|
mgagnon
|
538 |
/* Merge the changes in the current tree into the target version */ |
|
1611c97…
|
mgagnon
|
539 |
Blob r, t, v; |
|
1611c97…
|
mgagnon
|
540 |
int rc; |
|
0b86639…
|
jan.nijtmans
|
541 |
unsigned mergeFlags = dryRunFlag ? MERGE_DRYRUN : 0; |
|
d20ead1…
|
drh
|
542 |
if(keepMergeFlag!=0) mergeFlags |= MERGE_KEEP_FILES; |
|
d795eb0…
|
mistachkin
|
543 |
if( !dryRunFlag && !internalUpdate ) undo_save(zName); |
|
c97535c…
|
dmitry
|
544 |
content_get(ridt, &t); |
|
c97535c…
|
dmitry
|
545 |
content_get(ridv, &v); |
|
cd2c0e4…
|
drh
|
546 |
rc = merge_3way(&v, zFullPath, &t, &r, mergeFlags); |
|
c97535c…
|
dmitry
|
547 |
if( rc>=0 ){ |
|
0b86639…
|
jan.nijtmans
|
548 |
if( !dryRunFlag ){ |
|
c97535c…
|
dmitry
|
549 |
blob_write_to_file(&r, zFullNewPath); |
|
1772357…
|
drh
|
550 |
file_setexe(zFullNewPath, isexe); |
|
c97535c…
|
dmitry
|
551 |
} |
|
c97535c…
|
dmitry
|
552 |
if( rc>0 ){ |
|
3a18c95…
|
drh
|
553 |
nc = rc; |
|
3a18c95…
|
drh
|
554 |
zOp = "CONFLICT"; |
|
3a18c95…
|
drh
|
555 |
zErrMsg = "merge conflicts"; |
|
c97535c…
|
dmitry
|
556 |
fossil_print("***** %d merge conflicts in %s\n", rc, zNewName); |
|
c97535c…
|
dmitry
|
557 |
nConflict++; |
|
565a490…
|
drh
|
558 |
}else{ |
|
565a490…
|
drh
|
559 |
zOp = "MERGE"; |
|
3db1cf6…
|
drh
|
560 |
} |
|
3db1cf6…
|
drh
|
561 |
}else{ |
|
0b86639…
|
jan.nijtmans
|
562 |
if( !dryRunFlag ){ |
|
52a389d…
|
drh
|
563 |
if( !keepMergeFlag ){ |
|
52a389d…
|
drh
|
564 |
/* Name of backup file with Original content */ |
|
52a389d…
|
drh
|
565 |
char *zOrig = file_newname(zFullPath, "original", 1); |
|
52a389d…
|
drh
|
566 |
/* Backup non-mergeable binary file when --keep-merge-files is |
|
52a389d…
|
drh
|
567 |
not specified */ |
|
52a389d…
|
drh
|
568 |
file_copy(zFullPath, zOrig); |
|
52a389d…
|
drh
|
569 |
fossil_free(zOrig); |
|
52a389d…
|
drh
|
570 |
} |
|
3db1cf6…
|
drh
|
571 |
blob_write_to_file(&t, zFullNewPath); |
|
1772357…
|
drh
|
572 |
file_setexe(zFullNewPath, isexe); |
|
1772357…
|
drh
|
573 |
} |
|
52a389d…
|
drh
|
574 |
fossil_print("***** Cannot merge binary file %s", zNewName); |
|
52a389d…
|
drh
|
575 |
if( !dryRunFlag ){ |
|
52a389d…
|
drh
|
576 |
fossil_print(", original copy backed up locally"); |
|
52a389d…
|
drh
|
577 |
} |
|
52a389d…
|
drh
|
578 |
fossil_print("\n"); |
|
3db1cf6…
|
drh
|
579 |
nConflict++; |
|
3a18c95…
|
drh
|
580 |
zOp = "ERROR"; |
|
3a18c95…
|
drh
|
581 |
zErrMsg = "cannot merge binary file"; |
|
3a18c95…
|
drh
|
582 |
nc = 1; |
|
3db1cf6…
|
drh
|
583 |
} |
|
1611c97…
|
mgagnon
|
584 |
blob_reset(&v); |
|
1611c97…
|
mgagnon
|
585 |
blob_reset(&t); |
|
1611c97…
|
mgagnon
|
586 |
blob_reset(&r); |
|
565a490…
|
drh
|
587 |
} |
|
565a490…
|
drh
|
588 |
if( nameChng && !dryRunFlag ) file_delete(zFullPath); |
|
565a490…
|
drh
|
589 |
}else{ |
|
565a490…
|
drh
|
590 |
nUpdate--; |
|
565a490…
|
drh
|
591 |
if( chnged ){ |
|
565a490…
|
drh
|
592 |
if( verboseFlag ) fossil_print("EDITED %s\n", zName); |
|
565a490…
|
drh
|
593 |
}else{ |
|
565a490…
|
drh
|
594 |
db_bind_int(&mtimeXfer, ":idv", idv); |
|
565a490…
|
drh
|
595 |
db_bind_int(&mtimeXfer, ":idt", idt); |
|
565a490…
|
drh
|
596 |
db_step(&mtimeXfer); |
|
565a490…
|
drh
|
597 |
db_reset(&mtimeXfer); |
|
565a490…
|
drh
|
598 |
if( verboseFlag ) fossil_print("UNCHANGED %s\n", zName); |
|
ffe1b60…
|
drh
|
599 |
} |
|
565a490…
|
drh
|
600 |
} |
|
565a490…
|
drh
|
601 |
if( zOp!=0 ){ |
|
3a18c95…
|
drh
|
602 |
db_multi_exec( |
|
3a18c95…
|
drh
|
603 |
"INSERT INTO mergestat(op,fnp,ridp,fn,ridv,sz,fnm,ridm,fnr,nc,msg)" |
|
3a18c95…
|
drh
|
604 |
"VALUES(%Q,%Q,%d,%Q,NULL,%lld,%Q,%d,%Q,%d,%Q)", |
|
3a18c95…
|
drh
|
605 |
/* op */ zOp, |
|
3a18c95…
|
drh
|
606 |
/* fnp */ zName, |
|
3a18c95…
|
drh
|
607 |
/* ridp */ ridv, |
|
3a18c95…
|
drh
|
608 |
/* fn */ zNewName, |
|
3a18c95…
|
drh
|
609 |
/* sz */ sz, |
|
3a18c95…
|
drh
|
610 |
/* fnm */ zName, |
|
3a18c95…
|
drh
|
611 |
/* ridm */ ridt, |
|
3a18c95…
|
drh
|
612 |
/* fnr */ zNewName, |
|
3a18c95…
|
drh
|
613 |
/* nc */ nc, |
|
3a18c95…
|
drh
|
614 |
/* msg */ zErrMsg |
|
3a18c95…
|
drh
|
615 |
); |
|
2453717…
|
drh
|
616 |
} |
|
eaef1a7…
|
drh
|
617 |
free(zFullPath); |
|
fd8698c…
|
drh
|
618 |
free(zFullNewPath); |
|
eaef1a7…
|
drh
|
619 |
} |
|
eaef1a7…
|
drh
|
620 |
db_finalize(&q); |
|
ffe1b60…
|
drh
|
621 |
db_finalize(&mtimeXfer); |
|
971dd23…
|
danield
|
622 |
fossil_print("%.79c\n",'-'); |
|
2453717…
|
drh
|
623 |
zNewBrName = branch_of_rid(tid); |
|
2453717…
|
drh
|
624 |
if( g.argc<3 && fossil_strcmp(zCurBrName, zNewBrName)!=0 ){ |
|
2453717…
|
drh
|
625 |
zBrChgMsg = mprintf(" Branch changed from %s to %s.", |
|
2453717…
|
drh
|
626 |
zCurBrName, zNewBrName); |
|
2453717…
|
drh
|
627 |
} |
|
3db1cf6…
|
drh
|
628 |
if( nUpdate==0 ){ |
|
f78cba5…
|
drh
|
629 |
show_common_info(tid, "checkout:", 1, 0); |
|
2453717…
|
drh
|
630 |
fossil_print("%-13s None. Already up-to-date.%s\n", "changes:", zBrChgMsg); |
|
3db1cf6…
|
drh
|
631 |
}else{ |
|
275da70…
|
danield
|
632 |
fossil_print("%-13s %.40s %s\n", "updated-from:", rid_to_uuid(vid), |
|
971dd23…
|
danield
|
633 |
db_text("", "SELECT datetime(mtime) || ' UTC' FROM event " |
|
971dd23…
|
danield
|
634 |
" WHERE objid=%d", vid)); |
|
f78cba5…
|
drh
|
635 |
show_common_info(tid, "updated-to:", 1, 0); |
|
2453717…
|
drh
|
636 |
fossil_print("%-13s %d file%s modified.%s\n", "changes:", |
|
2453717…
|
drh
|
637 |
nUpdate, nUpdate>1 ? "s" : "", zBrChgMsg); |
|
3db1cf6…
|
drh
|
638 |
} |
|
070ce24…
|
drh
|
639 |
|
|
070ce24…
|
drh
|
640 |
/* Report on conflicts |
|
070ce24…
|
drh
|
641 |
*/ |
|
0b86639…
|
jan.nijtmans
|
642 |
if( !dryRunFlag ){ |
|
195517a…
|
drh
|
643 |
Stmt q; |
|
195517a…
|
drh
|
644 |
int nMerge = 0; |
|
fff37e6…
|
drh
|
645 |
db_prepare(&q, "SELECT mhash, id FROM vmerge WHERE id<=0"); |
|
195517a…
|
drh
|
646 |
while( db_step(&q)==SQLITE_ROW ){ |
|
195517a…
|
drh
|
647 |
const char *zLabel = "merge"; |
|
195517a…
|
drh
|
648 |
switch( db_column_int(&q, 1) ){ |
|
195517a…
|
drh
|
649 |
case -1: zLabel = "cherrypick merge"; break; |
|
195517a…
|
drh
|
650 |
case -2: zLabel = "backout merge"; break; |
|
195517a…
|
drh
|
651 |
} |
|
195517a…
|
drh
|
652 |
fossil_warning("uncommitted %s against %S.", |
|
195517a…
|
drh
|
653 |
zLabel, db_column_text(&q, 0)); |
|
195517a…
|
drh
|
654 |
nMerge++; |
|
195517a…
|
drh
|
655 |
} |
|
195517a…
|
drh
|
656 |
db_finalize(&q); |
|
f78cba5…
|
drh
|
657 |
leaf_ambiguity_warning(tid, tid); |
|
080ab8c…
|
jan.nijtmans
|
658 |
|
|
39f979b…
|
drh
|
659 |
if( nConflict ){ |
|
39f979b…
|
drh
|
660 |
if( internalUpdate ){ |
|
39f979b…
|
drh
|
661 |
internalConflictCnt = nConflict; |
|
39f979b…
|
drh
|
662 |
nConflict = 0; |
|
39f979b…
|
drh
|
663 |
}else{ |
|
471044f…
|
drh
|
664 |
fossil_warning("WARNING: %d merge conflicts", nConflict); |
|
39f979b…
|
drh
|
665 |
} |
|
39f979b…
|
drh
|
666 |
} |
|
39f979b…
|
drh
|
667 |
if( nOverwrite ){ |
|
c80ee41…
|
drh
|
668 |
fossil_warning("WARNING: %d unmanaged files were overwritten", |
|
39f979b…
|
drh
|
669 |
nOverwrite); |
|
39f979b…
|
drh
|
670 |
} |
|
195517a…
|
drh
|
671 |
if( nMerge ){ |
|
195517a…
|
drh
|
672 |
fossil_warning("WARNING: %d uncommitted prior merges", nMerge); |
|
195517a…
|
drh
|
673 |
} |
|
070ce24…
|
drh
|
674 |
} |
|
080ab8c…
|
jan.nijtmans
|
675 |
|
|
eaef1a7…
|
drh
|
676 |
/* |
|
eaef1a7…
|
drh
|
677 |
** Clean up the mid and pid VFILE entries. Then commit the changes. |
|
eaef1a7…
|
drh
|
678 |
*/ |
|
0b86639…
|
jan.nijtmans
|
679 |
if( dryRunFlag ){ |
|
122b631…
|
jan.nijtmans
|
680 |
db_end_transaction(1); /* With --dry-run, rollback changes */ |
|
06a72ce…
|
danield
|
681 |
fossil_warning("\nREMINDER: this was a dry run -" |
|
06a72ce…
|
danield
|
682 |
" no files were actually changed " |
|
06a72ce…
|
danield
|
683 |
"(checkout is still %.10s).", rid_to_uuid(vid)); |
|
eaef1a7…
|
drh
|
684 |
}else{ |
|
f132f86…
|
drh
|
685 |
char *zPwd; |
|
f132f86…
|
drh
|
686 |
ensure_empty_dirs_created(1); |
|
994a7c7…
|
drh
|
687 |
sqlite3_create_function(g.db, "rmdir", 1, SQLITE_UTF8|SQLITE_DIRECTONLY, 0, |
|
f132f86…
|
drh
|
688 |
file_rmdir_sql_function, 0, 0); |
|
f132f86…
|
drh
|
689 |
zPwd = file_getcwd(0,0); |
|
f132f86…
|
drh
|
690 |
db_multi_exec( |
|
f132f86…
|
drh
|
691 |
"SELECT rmdir(%Q||name) FROM dir_to_delete" |
|
f132f86…
|
drh
|
692 |
" WHERE (%Q||name)<>%Q ORDER BY name DESC", |
|
f132f86…
|
drh
|
693 |
g.zLocalRoot, g.zLocalRoot, zPwd |
|
f132f86…
|
drh
|
694 |
); |
|
f132f86…
|
drh
|
695 |
fossil_free(zPwd); |
|
eaef1a7…
|
drh
|
696 |
if( g.argc<=3 ){ |
|
bc36fdc…
|
danield
|
697 |
/* All files updated. Shift the current check-out to the target. */ |
|
eaef1a7…
|
drh
|
698 |
db_multi_exec("DELETE FROM vfile WHERE vid!=%d", tid); |
|
37c231b…
|
drh
|
699 |
checkout_set_all_exe(tid); |
|
f72ef85…
|
andybradford
|
700 |
db_set_checkout(tid, 1); |
|
eaef1a7…
|
drh
|
701 |
}else{ |
|
eaef1a7…
|
drh
|
702 |
/* A subset of files have been checked out. Keep the current |
|
bc36fdc…
|
danield
|
703 |
** check-out unchanged. */ |
|
eaef1a7…
|
drh
|
704 |
db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid); |
|
eaef1a7…
|
drh
|
705 |
} |
|
12a2a5e…
|
drh
|
706 |
if( !internalUpdate ) undo_finish(); |
|
1d3256c…
|
drh
|
707 |
if( setmtimeFlag ) vfile_check_signature(tid, CKSIG_SETMTIME); |
|
eaef1a7…
|
drh
|
708 |
db_end_transaction(0); |
|
eaef1a7…
|
drh
|
709 |
} |
|
eaef1a7…
|
drh
|
710 |
} |
|
eaef1a7…
|
drh
|
711 |
|
|
9a0c995…
|
drh
|
712 |
/* |
|
702331e…
|
drh
|
713 |
** Create empty directories specified by the empty-dirs setting. |
|
9a0c995…
|
drh
|
714 |
*/ |
|
f132f86…
|
drh
|
715 |
void ensure_empty_dirs_created(int clearDirTable){ |
|
9a0c995…
|
drh
|
716 |
char *zEmptyDirs = db_get("empty-dirs", 0); |
|
9a0c995…
|
drh
|
717 |
if( zEmptyDirs!=0 ){ |
|
702331e…
|
drh
|
718 |
int i; |
|
f12609f…
|
wyoung
|
719 |
Glob *pGlob = glob_create(zEmptyDirs); |
|
f12609f…
|
wyoung
|
720 |
|
|
b1dc25e…
|
stephan
|
721 |
for(i=0; pGlob!=0 && i<pGlob->nPattern; i++){ |
|
f12609f…
|
wyoung
|
722 |
const char *zDir = pGlob->azPattern[i]; |
|
b51dcc3…
|
drh
|
723 |
char *zPath = mprintf("%s/%s", g.zLocalRoot, zDir); |
|
1772357…
|
drh
|
724 |
switch( file_isdir(zPath, RepoFILE) ){ |
|
9a0c995…
|
drh
|
725 |
case 0: { /* doesn't exist */ |
|
702331e…
|
drh
|
726 |
fossil_free(zPath); |
|
702331e…
|
drh
|
727 |
zPath = mprintf("%s/%s/x", g.zLocalRoot, zDir); |
|
1772357…
|
drh
|
728 |
if( file_mkfolder(zPath, RepoFILE, 0, 1)!=0 ) { |
|
9a0c995…
|
drh
|
729 |
fossil_warning("couldn't create directory %s as " |
|
9a0c995…
|
drh
|
730 |
"required by empty-dirs setting", zDir); |
|
080ab8c…
|
jan.nijtmans
|
731 |
} |
|
9a0c995…
|
drh
|
732 |
break; |
|
9a0c995…
|
drh
|
733 |
} |
|
9a0c995…
|
drh
|
734 |
case 1: { /* exists, and is a directory */ |
|
f132f86…
|
drh
|
735 |
/* make sure this directory is not on the delete list */ |
|
f132f86…
|
drh
|
736 |
if( clearDirTable ){ |
|
f132f86…
|
drh
|
737 |
db_multi_exec( |
|
f132f86…
|
drh
|
738 |
"DELETE FROM dir_to_delete WHERE name=%Q", zDir |
|
f132f86…
|
drh
|
739 |
); |
|
f132f86…
|
drh
|
740 |
} |
|
9a0c995…
|
drh
|
741 |
break; |
|
9a0c995…
|
drh
|
742 |
} |
|
9a0c995…
|
drh
|
743 |
case 2: { /* exists, but isn't a directory */ |
|
9a0c995…
|
drh
|
744 |
fossil_warning("file %s found, but a directory is required " |
|
080ab8c…
|
jan.nijtmans
|
745 |
"by empty-dirs setting", zDir); |
|
080ab8c…
|
jan.nijtmans
|
746 |
} |
|
080ab8c…
|
jan.nijtmans
|
747 |
} |
|
702331e…
|
drh
|
748 |
fossil_free(zPath); |
|
f908068…
|
andygoth
|
749 |
} |
|
f12609f…
|
wyoung
|
750 |
glob_free(pGlob); |
|
f908068…
|
andygoth
|
751 |
} |
|
f908068…
|
andygoth
|
752 |
} |
|
f908068…
|
andygoth
|
753 |
|
|
f908068…
|
andygoth
|
754 |
/* |
|
bc36fdc…
|
danield
|
755 |
** Get the manifest record for a given revision, or the current check-out if |
|
f908068…
|
andygoth
|
756 |
** zRevision is NULL. |
|
f908068…
|
andygoth
|
757 |
*/ |
|
f908068…
|
andygoth
|
758 |
Manifest *historical_manifest( |
|
f908068…
|
andygoth
|
759 |
const char *zRevision /* The check-in to query, or NULL for current */ |
|
f908068…
|
andygoth
|
760 |
){ |
|
f908068…
|
andygoth
|
761 |
int vid; |
|
f908068…
|
andygoth
|
762 |
Manifest *pManifest; |
|
f908068…
|
andygoth
|
763 |
|
|
f908068…
|
andygoth
|
764 |
/* Determine the check-in manifest artifact ID. Panic on failure. */ |
|
f908068…
|
andygoth
|
765 |
if( zRevision ){ |
|
f908068…
|
andygoth
|
766 |
vid = name_to_typed_rid(zRevision, "ci"); |
|
f908068…
|
andygoth
|
767 |
}else if( !g.localOpen ){ |
|
ca0d66b…
|
danield
|
768 |
vid = name_to_typed_rid(db_main_branch(), "ci"); |
|
f908068…
|
andygoth
|
769 |
}else{ |
|
f908068…
|
andygoth
|
770 |
vid = db_lget_int("checkout", 0); |
|
f908068…
|
andygoth
|
771 |
if( !is_a_version(vid) ){ |
|
9aca02b…
|
drh
|
772 |
if( vid==0 ) return 0; |
|
f908068…
|
andygoth
|
773 |
zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid); |
|
f908068…
|
andygoth
|
774 |
if( zRevision ){ |
|
bc36fdc…
|
danield
|
775 |
fossil_fatal("check-out artifact is not a check-in: %s", zRevision); |
|
f908068…
|
andygoth
|
776 |
}else{ |
|
bc36fdc…
|
danield
|
777 |
fossil_fatal("invalid check-out artifact ID: %d", vid); |
|
f908068…
|
andygoth
|
778 |
} |
|
f908068…
|
andygoth
|
779 |
} |
|
f908068…
|
andygoth
|
780 |
} |
|
f908068…
|
andygoth
|
781 |
|
|
f908068…
|
andygoth
|
782 |
/* Parse the manifest, given its artifact ID. Panic on failure. */ |
|
f908068…
|
andygoth
|
783 |
if( !(pManifest = manifest_get(vid, CFTYPE_MANIFEST, 0)) ){ |
|
f908068…
|
andygoth
|
784 |
if( zRevision ){ |
|
f908068…
|
andygoth
|
785 |
fossil_fatal("could not parse manifest for check-in: %s", zRevision); |
|
f908068…
|
andygoth
|
786 |
}else{ |
|
bc36fdc…
|
danield
|
787 |
fossil_fatal("could not parse manifest for current check-out"); |
|
f908068…
|
andygoth
|
788 |
} |
|
f908068…
|
andygoth
|
789 |
} |
|
f908068…
|
andygoth
|
790 |
|
|
f908068…
|
andygoth
|
791 |
/* Return the manifest pointer. The caller must use manifest_destroy() to |
|
f908068…
|
andygoth
|
792 |
* clean up when finished using the manifest. */ |
|
f908068…
|
andygoth
|
793 |
return pManifest; |
|
f908068…
|
andygoth
|
794 |
} |
|
f908068…
|
andygoth
|
795 |
|
|
f908068…
|
andygoth
|
796 |
/* |
|
f908068…
|
andygoth
|
797 |
** Get the contents of a file within the check-in "zRevision". If |
|
bc36fdc…
|
danield
|
798 |
** zRevision==NULL then get the file content for the current check-out. |
|
f908068…
|
andygoth
|
799 |
*/ |
|
f908068…
|
andygoth
|
800 |
int historical_blob( |
|
f908068…
|
andygoth
|
801 |
const char *zRevision, /* The check-in containing the file */ |
|
f908068…
|
andygoth
|
802 |
const char *zFile, /* Full treename of the file */ |
|
f908068…
|
andygoth
|
803 |
Blob *pBlob, /* Put the content here */ |
|
f908068…
|
andygoth
|
804 |
int fatal /* If nonzero, panic if file/artifact not found */ |
|
f908068…
|
andygoth
|
805 |
){ |
|
f908068…
|
andygoth
|
806 |
int result = 0; |
|
f908068…
|
andygoth
|
807 |
|
|
f908068…
|
andygoth
|
808 |
/* Get the manifest for the requested check-in version. This call unavoidably |
|
f908068…
|
andygoth
|
809 |
* panics on failure even if fatal is not set. */ |
|
f908068…
|
andygoth
|
810 |
Manifest *pManifest = historical_manifest(zRevision); |
|
f908068…
|
andygoth
|
811 |
|
|
f908068…
|
andygoth
|
812 |
/* Try to find the file record within the manifest. */ |
|
f908068…
|
andygoth
|
813 |
ManifestFile *pFile = manifest_file_find(pManifest, zFile); |
|
f908068…
|
andygoth
|
814 |
|
|
f908068…
|
andygoth
|
815 |
if( !pFile ){ |
|
f908068…
|
andygoth
|
816 |
/* Process file-not-found errors. */ |
|
f908068…
|
andygoth
|
817 |
if( fatal ){ |
|
f908068…
|
andygoth
|
818 |
if( zRevision ){ |
|
f908068…
|
andygoth
|
819 |
fossil_fatal("file %s does not exist in check-in %s", zFile, zRevision); |
|
f908068…
|
andygoth
|
820 |
}else{ |
|
f908068…
|
andygoth
|
821 |
fossil_fatal("no such file: %s", zFile); |
|
f908068…
|
andygoth
|
822 |
} |
|
f908068…
|
andygoth
|
823 |
} |
|
f908068…
|
andygoth
|
824 |
}else{ |
|
f908068…
|
andygoth
|
825 |
/* Get the file's contents. */ |
|
f908068…
|
andygoth
|
826 |
result = content_get(fast_uuid_to_rid(pFile->zUuid), pBlob); |
|
f908068…
|
andygoth
|
827 |
|
|
f908068…
|
andygoth
|
828 |
/* Process artifact-not-found errors. */ |
|
f908068…
|
andygoth
|
829 |
if( !result && fatal ){ |
|
f908068…
|
andygoth
|
830 |
if( zRevision ){ |
|
f908068…
|
andygoth
|
831 |
fossil_fatal("missing artifact %s for file %s in check-in %s", |
|
f908068…
|
andygoth
|
832 |
pFile->zUuid, zFile, zRevision); |
|
f908068…
|
andygoth
|
833 |
}else{ |
|
f908068…
|
andygoth
|
834 |
fossil_fatal("missing artifact %s for file %s", pFile->zUuid, zFile); |
|
f908068…
|
andygoth
|
835 |
} |
|
f908068…
|
andygoth
|
836 |
} |
|
f908068…
|
andygoth
|
837 |
} |
|
f908068…
|
andygoth
|
838 |
|
|
f908068…
|
andygoth
|
839 |
/* Deallocate the parsed manifest structure. */ |
|
f908068…
|
andygoth
|
840 |
manifest_destroy(pManifest); |
|
f908068…
|
andygoth
|
841 |
|
|
f908068…
|
andygoth
|
842 |
/* Return 1 on success and (assuming fatal is not set) 0 if not found. */ |
|
f908068…
|
andygoth
|
843 |
return result; |
|
f908068…
|
andygoth
|
844 |
} |
|
eaef1a7…
|
drh
|
845 |
|
|
eaef1a7…
|
drh
|
846 |
/* |
|
eaef1a7…
|
drh
|
847 |
** COMMAND: revert |
|
eaef1a7…
|
drh
|
848 |
** |
|
a8bb086…
|
ashepilko
|
849 |
** Usage: %fossil revert ?OPTIONS? ?FILE ...? |
|
eaef1a7…
|
drh
|
850 |
** |
|
eaef1a7…
|
drh
|
851 |
** Revert to the current repository version of FILE, or to |
|
a8bb086…
|
ashepilko
|
852 |
** the baseline VERSION specified with -r flag. |
|
eef3474…
|
joel
|
853 |
** |
|
eef3474…
|
joel
|
854 |
** If FILE was part of a rename operation, both the original file |
|
eef3474…
|
joel
|
855 |
** and the renamed file are reverted. |
|
a8bb086…
|
ashepilko
|
856 |
** |
|
a8bb086…
|
ashepilko
|
857 |
** Using a directory name for any of the FILE arguments is the same |
|
a8bb086…
|
ashepilko
|
858 |
** as using every subdirectory and file beneath that directory. |
|
4d1ac68…
|
drh
|
859 |
** |
|
44b02c3…
|
BMorgat
|
860 |
** Revert all files if no file name is provided. |
|
eaef1a7…
|
drh
|
861 |
** |
|
4d1ac68…
|
drh
|
862 |
** If a file is reverted accidentally, it can be restored using |
|
eaef1a7…
|
drh
|
863 |
** the "fossil undo" command. |
|
75ea5ac…
|
drh
|
864 |
** |
|
75ea5ac…
|
drh
|
865 |
** Options: |
|
3a39ae4…
|
drh
|
866 |
** --noundo Do not record changes in the undo/redo log. |
|
a8bb086…
|
ashepilko
|
867 |
** -r|--revision VERSION Revert given FILE(s) back to given |
|
a8bb086…
|
ashepilko
|
868 |
** VERSION |
|
75ea5ac…
|
drh
|
869 |
** |
|
c965636…
|
drh
|
870 |
** See also: [[redo]], [[undo]], [[checkout]], [[update]] |
|
eaef1a7…
|
drh
|
871 |
*/ |
|
eaef1a7…
|
drh
|
872 |
void revert_cmd(void){ |
|
bc36fdc…
|
danield
|
873 |
Manifest *pCoManifest; /* Manifest of current check-out */ |
|
f908068…
|
andygoth
|
874 |
Manifest *pRvManifest; /* Manifest of selected revert version */ |
|
bc36fdc…
|
danield
|
875 |
ManifestFile *pCoFile; /* File within current check-out manifest */ |
|
f908068…
|
andygoth
|
876 |
ManifestFile *pRvFile; /* File within revert version manifest */ |
|
bc36fdc…
|
danield
|
877 |
const char *zFile; /* Filename relative to check-out root */ |
|
f908068…
|
andygoth
|
878 |
const char *zRevision; /* Selected revert version, NULL if current */ |
|
f908068…
|
andygoth
|
879 |
Blob record = BLOB_INITIALIZER; /* Contents of each reverted file */ |
|
3a39ae4…
|
drh
|
880 |
int useUndo = 1; /* True to record changes in UNDO */ |
|
eaef1a7…
|
drh
|
881 |
int i; |
|
eaef1a7…
|
drh
|
882 |
Stmt q; |
|
a8bb086…
|
ashepilko
|
883 |
int revertAll = 0; |
|
a8bb086…
|
ashepilko
|
884 |
int revisionOptNotSupported = 0; |
|
30981b6…
|
drh
|
885 |
|
|
080ab8c…
|
jan.nijtmans
|
886 |
undo_capture_command_line(); |
|
eaef1a7…
|
drh
|
887 |
zRevision = find_option("revision", "r", 1); |
|
3a39ae4…
|
drh
|
888 |
useUndo = find_option("noundo", 0, 0)==0; |
|
eaef1a7…
|
drh
|
889 |
verify_all_options(); |
|
080ab8c…
|
jan.nijtmans
|
890 |
|
|
eaef1a7…
|
drh
|
891 |
if( g.argc<2 ){ |
|
eaef1a7…
|
drh
|
892 |
usage("?OPTIONS? [FILE] ..."); |
|
eaef1a7…
|
drh
|
893 |
} |
|
eaef1a7…
|
drh
|
894 |
if( zRevision && g.argc<3 ){ |
|
a8bb086…
|
ashepilko
|
895 |
fossil_fatal("directories or the entire tree can only be reverted" |
|
a8bb086…
|
ashepilko
|
896 |
" back to current version"); |
|
eaef1a7…
|
drh
|
897 |
} |
|
eaef1a7…
|
drh
|
898 |
db_must_be_within_tree(); |
|
f908068…
|
andygoth
|
899 |
|
|
bc36fdc…
|
danield
|
900 |
/* Get manifests of revert version and (if different) current check-out. */ |
|
f908068…
|
andygoth
|
901 |
pRvManifest = historical_manifest(zRevision); |
|
f908068…
|
andygoth
|
902 |
pCoManifest = zRevision ? historical_manifest(0) : 0; |
|
f908068…
|
andygoth
|
903 |
|
|
e1962ef…
|
drh
|
904 |
db_begin_transaction(); |
|
3a39ae4…
|
drh
|
905 |
if( useUndo ){ |
|
3a39ae4…
|
drh
|
906 |
undo_begin(); |
|
3a39ae4…
|
drh
|
907 |
}else{ |
|
3a39ae4…
|
drh
|
908 |
undo_reset(); |
|
3a39ae4…
|
drh
|
909 |
} |
|
eaef1a7…
|
drh
|
910 |
db_multi_exec("CREATE TEMP TABLE torevert(name UNIQUE);"); |
|
eaef1a7…
|
drh
|
911 |
|
|
eaef1a7…
|
drh
|
912 |
if( g.argc>2 ){ |
|
eaef1a7…
|
drh
|
913 |
for(i=2; i<g.argc; i++){ |
|
eaef1a7…
|
drh
|
914 |
Blob fname; |
|
eaef1a7…
|
drh
|
915 |
zFile = mprintf("%/", g.argv[i]); |
|
a50be7b…
|
mistachkin
|
916 |
blob_zero(&fname); |
|
c56a387…
|
mistachkin
|
917 |
file_tree_name(zFile, &fname, 0, 1); |
|
a8bb086…
|
ashepilko
|
918 |
if( blob_eq(&fname, ".") ){ |
|
a8bb086…
|
ashepilko
|
919 |
if( zRevision ){ |
|
a8bb086…
|
ashepilko
|
920 |
revisionOptNotSupported = 1; |
|
a8bb086…
|
ashepilko
|
921 |
break; |
|
a8bb086…
|
ashepilko
|
922 |
} |
|
a8bb086…
|
ashepilko
|
923 |
revertAll = 1; |
|
a8bb086…
|
ashepilko
|
924 |
break; |
|
a8bb086…
|
ashepilko
|
925 |
}else if( db_exists( |
|
a8bb086…
|
ashepilko
|
926 |
"SELECT pathname" |
|
a8bb086…
|
ashepilko
|
927 |
" FROM vfile" |
|
a8bb086…
|
ashepilko
|
928 |
" WHERE (substr(pathname,1,length('%q/'))='%q/'" |
|
a8bb086…
|
ashepilko
|
929 |
" OR substr(origname,1,length('%q/'))='%q/');", |
|
a8bb086…
|
ashepilko
|
930 |
blob_str(&fname), blob_str(&fname), |
|
a8bb086…
|
ashepilko
|
931 |
blob_str(&fname), blob_str(&fname)) ){ |
|
a8bb086…
|
ashepilko
|
932 |
int vid; |
|
a8bb086…
|
ashepilko
|
933 |
vid = db_lget_int("checkout", 0); |
|
a8bb086…
|
ashepilko
|
934 |
vfile_check_signature(vid, 0); |
|
a8bb086…
|
ashepilko
|
935 |
|
|
a8bb086…
|
ashepilko
|
936 |
if( zRevision ){ |
|
a8bb086…
|
ashepilko
|
937 |
revisionOptNotSupported = 1; |
|
a8bb086…
|
ashepilko
|
938 |
break; |
|
a8bb086…
|
ashepilko
|
939 |
} |
|
a8bb086…
|
ashepilko
|
940 |
db_multi_exec( |
|
a8bb086…
|
ashepilko
|
941 |
"INSERT OR IGNORE INTO torevert" |
|
a8bb086…
|
ashepilko
|
942 |
" SELECT pathname" |
|
a8bb086…
|
ashepilko
|
943 |
" FROM vfile" |
|
a8bb086…
|
ashepilko
|
944 |
" WHERE (substr(pathname,1,length('%q/'))='%q/'" |
|
a8bb086…
|
ashepilko
|
945 |
" OR substr(origname,1,length('%q/'))='%q/')" |
|
a8bb086…
|
ashepilko
|
946 |
" AND (chnged OR deleted OR rid=0 OR pathname!=origname);", |
|
a8bb086…
|
ashepilko
|
947 |
blob_str(&fname), blob_str(&fname), |
|
a8bb086…
|
ashepilko
|
948 |
blob_str(&fname), blob_str(&fname) |
|
a8bb086…
|
ashepilko
|
949 |
); |
|
a8bb086…
|
ashepilko
|
950 |
}else{ |
|
a8bb086…
|
ashepilko
|
951 |
db_multi_exec( |
|
a8bb086…
|
ashepilko
|
952 |
"REPLACE INTO torevert VALUES(%B);" |
|
a8bb086…
|
ashepilko
|
953 |
"INSERT OR IGNORE INTO torevert" |
|
a8bb086…
|
ashepilko
|
954 |
" SELECT pathname" |
|
a8bb086…
|
ashepilko
|
955 |
" FROM vfile" |
|
a8bb086…
|
ashepilko
|
956 |
" WHERE origname=%B;", |
|
a8bb086…
|
ashepilko
|
957 |
&fname, &fname |
|
a8bb086…
|
ashepilko
|
958 |
); |
|
a8bb086…
|
ashepilko
|
959 |
} |
|
eaef1a7…
|
drh
|
960 |
blob_reset(&fname); |
|
eaef1a7…
|
drh
|
961 |
} |
|
eaef1a7…
|
drh
|
962 |
}else{ |
|
a8bb086…
|
ashepilko
|
963 |
revertAll = 1; |
|
a8bb086…
|
ashepilko
|
964 |
} |
|
a8bb086…
|
ashepilko
|
965 |
|
|
a8bb086…
|
ashepilko
|
966 |
if( revisionOptNotSupported ){ |
|
a8bb086…
|
ashepilko
|
967 |
fossil_fatal("directories or the entire tree can only be reverted" |
|
a8bb086…
|
ashepilko
|
968 |
" back to current version"); |
|
a8bb086…
|
ashepilko
|
969 |
} |
|
a8bb086…
|
ashepilko
|
970 |
|
|
a8bb086…
|
ashepilko
|
971 |
if ( revertAll ){ |
|
3c39caa…
|
drh
|
972 |
int vid; |
|
3c39caa…
|
drh
|
973 |
vid = db_lget_int("checkout", 0); |
|
ae092ec…
|
drh
|
974 |
vfile_check_signature(vid, 0); |
|
3c39caa…
|
drh
|
975 |
db_multi_exec( |
|
3c39caa…
|
drh
|
976 |
"DELETE FROM vmerge;" |
|
48798b2…
|
drh
|
977 |
"INSERT OR IGNORE INTO torevert " |
|
48798b2…
|
drh
|
978 |
" SELECT pathname" |
|
48798b2…
|
drh
|
979 |
" FROM vfile " |
|
e66a12e…
|
joel
|
980 |
" WHERE chnged OR deleted OR rid=0 OR pathname!=origname;" |
|
3c39caa…
|
drh
|
981 |
); |
|
3c39caa…
|
drh
|
982 |
} |
|
a8bb086…
|
ashepilko
|
983 |
|
|
e66a12e…
|
joel
|
984 |
db_multi_exec( |
|
e66a12e…
|
joel
|
985 |
"INSERT OR IGNORE INTO torevert" |
|
e66a12e…
|
joel
|
986 |
" SELECT origname" |
|
e66a12e…
|
joel
|
987 |
" FROM vfile" |
|
e66a12e…
|
joel
|
988 |
" WHERE origname!=pathname AND pathname IN (SELECT name FROM torevert);" |
|
e66a12e…
|
joel
|
989 |
); |
|
3c39caa…
|
drh
|
990 |
blob_zero(&record); |
|
3c39caa…
|
drh
|
991 |
db_prepare(&q, "SELECT name FROM torevert"); |
|
3c39caa…
|
drh
|
992 |
if( zRevision==0 ){ |
|
3c39caa…
|
drh
|
993 |
int vid = db_lget_int("checkout", 0); |
|
3c39caa…
|
drh
|
994 |
zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid); |
|
3c39caa…
|
drh
|
995 |
} |
|
3c39caa…
|
drh
|
996 |
while( db_step(&q)==SQLITE_ROW ){ |
|
3ad119b…
|
drh
|
997 |
char *zFull; |
|
3c39caa…
|
drh
|
998 |
zFile = db_column_text(&q, 0); |
|
3ad119b…
|
drh
|
999 |
zFull = mprintf("%/%/", g.zLocalRoot, zFile); |
|
9aca02b…
|
drh
|
1000 |
pRvFile = pRvManifest? manifest_file_find(pRvManifest, zFile) : 0; |
|
f908068…
|
andygoth
|
1001 |
if( !pRvFile ){ |
|
48798b2…
|
drh
|
1002 |
if( db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q OR origname=%Q", |
|
48798b2…
|
drh
|
1003 |
zFile, zFile)==0 ){ |
|
0a2ebe5…
|
andygoth
|
1004 |
fossil_print("UNMANAGE %s\n", zFile); |
|
3ad119b…
|
drh
|
1005 |
}else{ |
|
3a39ae4…
|
drh
|
1006 |
if( useUndo ) undo_save(zFile); |
|
d8ec765…
|
drh
|
1007 |
file_delete(zFull); |
|
0a2ebe5…
|
andygoth
|
1008 |
fossil_print("DELETE %s\n", zFile); |
|
3ad119b…
|
drh
|
1009 |
} |
|
eef3474…
|
joel
|
1010 |
db_multi_exec( |
|
bd0b09e…
|
joel
|
1011 |
"UPDATE OR REPLACE vfile" |
|
eef3474…
|
joel
|
1012 |
" SET pathname=origname, origname=NULL" |
|
e66a12e…
|
joel
|
1013 |
" WHERE pathname=%Q AND origname!=pathname;" |
|
eef3474…
|
joel
|
1014 |
"DELETE FROM vfile WHERE pathname=%Q", |
|
eef3474…
|
joel
|
1015 |
zFile, zFile |
|
eef3474…
|
joel
|
1016 |
); |
|
f741baa…
|
drh
|
1017 |
}else if( file_unsafe_in_tree_path(zFull) ){ |
|
f741baa…
|
drh
|
1018 |
/* Ignore this file */ |
|
3c39caa…
|
drh
|
1019 |
}else{ |
|
3ad119b…
|
drh
|
1020 |
sqlite3_int64 mtime; |
|
f908068…
|
andygoth
|
1021 |
int rvChnged = 0; |
|
f908068…
|
andygoth
|
1022 |
int rvPerm = manifest_file_mperm(pRvFile); |
|
f908068…
|
andygoth
|
1023 |
|
|
bc36fdc…
|
danield
|
1024 |
/* Determine if reverted-to file is different than checked-out file. */ |
|
f908068…
|
andygoth
|
1025 |
if( pCoManifest && (pCoFile = manifest_file_find(pCoManifest, zFile)) ){ |
|
f908068…
|
andygoth
|
1026 |
rvChnged = manifest_file_mperm(pRvFile)!=rvPerm |
|
f908068…
|
andygoth
|
1027 |
|| fossil_strcmp(pRvFile->zUuid, pCoFile->zUuid)!=0; |
|
f908068…
|
andygoth
|
1028 |
} |
|
f908068…
|
andygoth
|
1029 |
|
|
f908068…
|
andygoth
|
1030 |
/* Get contents of reverted-to file. */ |
|
f908068…
|
andygoth
|
1031 |
content_get(fast_uuid_to_rid(pRvFile->zUuid), &record); |
|
f908068…
|
andygoth
|
1032 |
|
|
3a39ae4…
|
drh
|
1033 |
if( useUndo ) undo_save(zFile); |
|
1772357…
|
drh
|
1034 |
if( file_size(zFull, RepoFILE)>=0 |
|
1772357…
|
drh
|
1035 |
&& (rvPerm==PERM_LNK || file_islink(0)) |
|
1772357…
|
drh
|
1036 |
){ |
|
c97535c…
|
dmitry
|
1037 |
file_delete(zFull); |
|
e4f1c1f…
|
drh
|
1038 |
} |
|
f908068…
|
andygoth
|
1039 |
if( rvPerm==PERM_LNK ){ |
|
c05f6af…
|
dmitry
|
1040 |
symlink_create(blob_str(&record), zFull); |
|
e4f1c1f…
|
drh
|
1041 |
}else{ |
|
e4f1c1f…
|
drh
|
1042 |
blob_write_to_file(&record, zFull); |
|
e4f1c1f…
|
drh
|
1043 |
} |
|
1772357…
|
drh
|
1044 |
file_setexe(zFull, rvPerm==PERM_EXE); |
|
0a2ebe5…
|
andygoth
|
1045 |
fossil_print("REVERT %s\n", zFile); |
|
1772357…
|
drh
|
1046 |
mtime = file_mtime(zFull, RepoFILE); |
|
3ad119b…
|
drh
|
1047 |
db_multi_exec( |
|
3ad119b…
|
drh
|
1048 |
"UPDATE vfile" |
|
fff37e6…
|
drh
|
1049 |
" SET mtime=%lld, chnged=%d, deleted=0, isexe=%d, islink=%d," |
|
fff37e6…
|
drh
|
1050 |
" mrid=rid, mhash=NULL" |
|
eef3474…
|
joel
|
1051 |
" WHERE pathname=%Q OR origname=%Q", |
|
f908068…
|
andygoth
|
1052 |
mtime, rvChnged, rvPerm==PERM_EXE, rvPerm==PERM_LNK, zFile, zFile |
|
3ad119b…
|
drh
|
1053 |
); |
|
3c39caa…
|
drh
|
1054 |
} |
|
3c39caa…
|
drh
|
1055 |
blob_reset(&record); |
|
3ad119b…
|
drh
|
1056 |
free(zFull); |
|
3c39caa…
|
drh
|
1057 |
} |
|
3c39caa…
|
drh
|
1058 |
db_finalize(&q); |
|
3a39ae4…
|
drh
|
1059 |
if( useUndo) undo_finish(); |
|
3c39caa…
|
drh
|
1060 |
db_end_transaction(0); |
|
f908068…
|
andygoth
|
1061 |
|
|
f908068…
|
andygoth
|
1062 |
/* Deallocate parsed manifest structures. */ |
|
f908068…
|
andygoth
|
1063 |
manifest_destroy(pRvManifest); |
|
f908068…
|
andygoth
|
1064 |
manifest_destroy(pCoManifest); |
|
dbda8d6…
|
drh
|
1065 |
} |