source: valtobtest/subversion-1.6.2/notes/tree-conflicts/resolution.txt @ 3

Last change on this file since 3 was 3, checked in by valtob, 15 years ago

subversion source 1.6.2 as test

File size: 19.4 KB
Line 
1                           Resolving Tree Conflicts
2                           ========================
3
4############################################################################
5### NOTE: This file describes what I'd like, not what Subversion does.   ###
6###   - Julian Foad, 2008                                                ###
7############################################################################
8
9Resolution of tree conflicts includes:
10
11  (i)   A known state of the WC after the conflict is raised.
12
13  (ii)  Constructing the desired result from the conflicted state.
14
15  (iii) Marking as resolved (both "svn resolve" and interactive).
16
17
18I. STATE OF THE WC AFTER CONFLICT IS RAISED
19===========================================
20
21When a tree conflict is raised, the "old" and "theirs" and "mine" versions
22should be stored locally in the WC in such a way that
23
24  (a) Subversion can turn one of them into a final outcome when told
25        svn resolve --accept=theirs TARGET
26
27  (b) the user can examine them and combine them to create a final outcome,
28      using commands like
29        svn proplist TARGET.theirs
30        svn merge TARGET.theirs OTHERFILE TARGET
31
32WC State is defined in terms of what file content and what scheduling is
33stored for each of ".working" (the active WC file/dir during resolving),
34".mine" (the previous working file/dir, as preserved for reference), and
35".theirs" (the type and resulting content of the incoming change).
36
37The expected state for each case is defined in the "WC State" sections inside
38the "Resolution Recipes" section.
39
40Principles
41----------
42
43* When "svn update" or "svn switch" raises a tree conflict, it shall update
44  the victim's "base" version from OLD to THEIRS, and leave the "working"
45  version in a state that would be committable (but for the explicit check
46  that prevents committing an item marked as in conflict) and that, if
47  committed, would restore the item to how it looked in "mine". This may
48  involve changing the scheduling of the item, e.g. to be re-added if "update"
49  applied a delete.
50
51  When "svn merge" raises a tree conflict, it shall not change the working
52  content or scheduling of the victim.
53
54* An update from rX to rY followed by an update back to rX should have no
55  overall effect on the local modifications scheduled in the WC. Likewise a
56  switch to a different URL@REV and a switch back to the original one.
57  Likewise a merge followed by a merge of the reverse change.
58
59Q. How do we store the "theirs" tree in the WC, especially in the case where
60it's a tree and needs to be constructed anew because it comes (as an Add or
61Mod) onto a WC item that's Del or not present? What I mean is to persuade
62the normal "update" or "merge" code paths to construct a new WC directory
63named "TARGET.theirs" on the fly and then recurse into it applying the
64incoming mods.
65
66(Need to list the cases where constructing such a new WC tree will be
67necessary.)
68
69
70II. CONSTRUCTING THE DESIRED RESULT
71===================================
72
73For cases where the user needs to merge the two conflicting changes (as
74opposed to choosing just one and ignoring the other), we need:
75
76  * Recipes for the user to follow
77    - see the "Tree Conflict Resolution Recipes" section.
78
79  * Enhanced facilities for merging changes from conflicting partial results
80    into the desired result.
81    - see the "Arbitrary Merge Facility Required" section.
82
83
84Tree Conflict Resolution Recipes
85================================
86
87This section sets out, for each type of tree conflict, the resolutions that I
88expect would be commonly wanted, either giving a useful result directly or as
89building blocks for more complex resolutions.
90
91The aim is to provide in each of the selected cases a sufficiently clear
92recipe for a user to resolve most tree conflicts that they encounter. Such a
93user is expected to be fairly proficient in using Subversion but not to have
94any knowledge of the way tree conflicts are handled internally.
95
96Under each type of conflict are the following subsections:
97
98  "WC State" describes the state in which the WC should be left when the
99  conflict is raised, according to the principles set out in section I.
100
101  "Some use cases" lists some likely use cases by which a user might encounter
102  such a conflict, concentrating on cases that want a resolution other than
103  "THEIRS" or "MINE".
104
105  "Options" lists resolution options that ought to be available.  The
106  resolution options "THEIRS" and "MINE" should be available in every case (so
107  that a user can resolve a whole tree at once with one of those options) and
108  should be implemented internally. Any other options listed here may be
109  recipes for the user to apply manually. These recipes are starting from the
110  state in which the WC should be left by Subversion after raising a conflict.
111
112The "WC State" subsection is intended as design requirements, not for the end
113user. I have not yet attempted to implement this as part of tree-conflict
114detection, and have no idea to what extent this is currently achieved in the
115tree-conflicts branch.
116
117The other two subsections are intended as the basis of material for end users
118to read.
119
120Principles
121----------
122
123* We shall assume the ability to examine the source-left ("old") and source-
124  right ("theirs") and target ("mine") tree states as well as the source
125  diffs.
126
127  In a merge, we shall not assume or attempt to make use of any ancestral
128  relationship between the target and the source.
129
130Renames and Replacements
131------------------------
132
133Incoming rename:
134
135  An incoming rename is treated here as its two constituent actions - an
136  incoming delete and an incoming add - separately.
137
138Incoming replacement:
139
140  In an incoming replacement, the delete is assumed to come before the add.
141  (Currently, they may sometimes come the wrong way around. I have not
142  analyzed the cases in which this can happen, nor the consequences.)
143
144Scheduled rename:
145
146  With a scheduled rename, each of the names (the old and the new) will be
147  treated separately as a potential victim of a tree conflict.
148
149Scheduled replacement:
150
151  A scheduled replacement is treated mainly the same as a scheduled deletion,
152  because any incoming change is assumed to apply to the old object that was
153  deleted rather than to the new object that replaced it.
154
155  Where the ability to schedule a replacement of one node kind with another is
156  implied, this ability may not be supported (and currently is not supported)
157  by the working copy library. Such cases will therefore be unsupported. This
158  is not seen as a deficiency inherent in tree conflict handling, but as a
159  separate deficiency that restricts tree conflict handling in certain cases.
160
161Meaning of "Choose Theirs" and "Choose Mine"
162--------------------------------------------
163
164There is a subtle difference between the meanings of "Choose Theirs" and
165"Choose Mine" as applied to an update or switch compared with when
166the terms are applied to a merge.
167
168For update and switch, the final state resulting from the incoming change is
169already existing in the history of the branch we're working on, and is going
170to be our WC's new "base" version, so we can't choose to "ignore" this
171incoming change. The request to "Choose Mine" means "Schedule the item to be
172changed from its new base state back to how my version of it looked before
173this operation". This may involve changing the scheduling of the item. The
174request to "Choose Theirs" simply means "Discard my pending changes so as to
175keep their version of it".
176
177For a merge, however, the final state of the incoming change is not going to
178be the new base state of the branch we're working on, and so we _can_ choose
179to ignore it if we so wish. Also, "my" version is a combination of historical
180and working-copy changes, so we cannot in general choose to ignore this, we
181can only schedule changes that reverse it. In a merge, then, "Choose Mine"
182means "Leave my version of the item as it is" (which does not involve any
183change of scheduling), while "Choose Theirs" means "Overwrite my version with
184a copy of Their version of the item" (which may involve scheduling an add or
185delete). The potential alternative meaning, "Make Their change", is not
186viable: it is what Subversion already tried to do, and it resulted in the very
187conflict we're now trying to resolve.
188
189
190Recipes
191=======
192
193up/sw: Add onto Add
194-------------------
195
196WC State:
197  .working: sched=Normal/Replace, content=.mine
198  .mine:    sched=Add[w/hist], content=Something
199  .theirs:  action=Add[w/hist], content=Something
200
201Some use cases:
202  - I have already applied the patch - their item is identical to mine.
203    -> want to do it just once -> THEIRS.
204  - Two different new items happened to be given the same name.
205    -> accept theirs & rename mine -> RENAME-MINE.
206  - I was doing roughly the same thing but the item is a bit different.
207    -> merge the two items -> manual 2-way merge (or 3-way if both are w/hist
208      and it's the same copy-from source).
209
210Options:
211  THEIRS: As usual, like "svn revert TARGET".
212  MINE:   My content as a scheduled modification, or as a scheduled replace*
213          if "my" node-kind (or copy-from?) differs.
214  RENAME-MINE: Add "my" content under a different name, and then accept
215          "their" add:
216    - Choose a new name for mine.
217    - svn rename TARGET NEWNAME
218    - svn revert TARGET
219
220If identical (node-kind, content, props, copyfrom-info?):
221  Recommend choosing THEIRS.
222
223
224up/sw: Del onto Del
225-------------------
226
227WC State:
228  .working: sched=unversioned, content=None
229  .mine:    sched=Del, content=None
230  .theirs:  action=Del, content=None
231
232Some use cases:
233  - Already applied the patch
234    -> want to do it just once -> THEIRS.
235  - Renamed to two different names
236    -> want to undo Their renaming and make it like Mine, as if we had a
237    "Choose Mine" option that worked on whole rename operations. -> RENAME.
238
239Options:
240  THEIRS: As usual (but has no effect in this case)
241  MINE:   As usual (but has no effect in this case)
242  RENAME:
243    - svn rename THEIR-NEW-NAME MY-NEW-NAME
244    And take care to notice if there were any modifications made at the same
245    time as the renames; if so, these might need merging.
246
247Note: In an update or switch, THEIRS and MINE are from the same OLD base, so
248there is no possibility that the item we are deleting locally is different
249from the item the incoming change is deleting.
250
251
252up/sw: Mod onto Del
253-------------------
254
255WC State:
256  .working: sched=Del, content=None
257  .mine:    sched=Del, content=None
258  .theirs:  action=Mod, content=Something
259
260Some use cases:
261  - Locally renamed
262    -> want to apply the incoming mod to a different item -> ELSEWHERE.
263
264Options:
265  THEIRS: As usual.
266  MINE:   Leave it deleted.
267  ELSEWHERE1: Apply their mod onto my renamed item. (Mine is the master.)
268    - Determine a way to obtain the incoming diff and apply it to the new
269      name, e.g. one of these:
270      - svn merge -r OLDREV:NEWREV TARGET(URL?) NEWNAME
271        (should be possible for "up" always, "sw" never, "merge" sometimes)
272      - svn merge -r old:theirs TARGET NEWNAME  [*1]
273  ELSEWHERE2: Reapply my Rename [+mod] onto theirs. (Theirs is the master.)
274    - mv NEWNAME TMP
275    - svn revert NEWNAME / rm -rf NEWNAME
276    - Move TARGET.theirs to NEWNAME. Here's one way to do that:
277      - svn resolve --accept=theirs TARGET
278      - svn rename TARGET NEWNAME
279      - svn resolve --accept=mine TARGET
280    - svn merge TARGET@old TMP@working NEWNAME  [*1]
281
282
283up/sw: Del onto Mod
284-------------------
285
286WC State:
287  .working: sched=Add, content=.mine
288  .mine:    sched=Normal, content=Something
289  .theirs:  action=Del, content=None
290
291Some use cases:
292  - The incoming change is (part of) a rename
293    -> want to transfer my local mod to the renamed item -> MOVE-MY-MODS.
294
295Options:
296  THEIRS: As usual.
297  MINE:   Schedule for Add.
298  MOVE-MY-MODS: Reapply my mod onto their renamed item. (Theirs is the master.)
299    - Determine their new name.
300    - Wait till up/sw has processed the new-named item.
301    - svn merge -r OLD:MINE TARGET THEIRNEWNAME  [*1]
302    - svn revert TARGET
303  MOVE-MY-MODS2: Apply their rename[+mod] onto my item. (Mine is the master.)
304    - svn merge TARGET@old THEIRNEWNAME TARGET  [*1]
305    - svn revert THEIRNEWNAME
306    - svn rename TARGET THEIRNEWNAME
307
308
309merge: Add onto Something (Identical or Different-Content or Different-Kind)
310-------------------------
311
312WC State:
313  .working: =.mine
314  .mine:    sched=(not Del), content=Something
315  .theirs:  action=Add[w/hist?], content=Something
316
317Some use cases:
318  Same as for "up/sw: Add onto Add", plus one more:
319  - Two different new items happened to be given the same name.
320    -> keep mine & rename theirs -> RENAME-THEIRS.
321
322Options:
323  THEIRS: Schedule local mods (if any change needed) to replace mine
324    with theirs. (If copyfrom differs, should we schedule Replace or not?)
325  MINE:   (Nothing to do.)
326  RENAME-MINE: Add "my" content under a new name, and accept "their" add under
327    the original name. (Theirs is the master.)
328    - Choose a new name for mine.
329    - svn rename TARGET NEWNAME
330    - svn resolve --accept=theirs TARGET
331  RENAME-THEIRS: Add theirs under a new name. (Mine is the master.)
332    - Choose a new name for theirs.
333    - svn rename TARGET.theirs NEWNAME  [*1]
334    - svn resolve --accept=mine TARGET
335
336If identical (node-kind, content, props, copyfrom-info?):
337  Recommend choosing THEIRS.
338
339
340merge: Del onto Nothing Here
341----------------------------
342
343WC State:
344  .working: =.mine
345  .mine:    sched=(Del/unversioned), content=None
346  .theirs:  action=Del, content=None
347
348Some use cases:
349  - User's process is wrong: maybe something else needed to be merged first.
350    -> want to revert this whole merge.
351  - Already applied the patch or merged the change without recording the fact.
352    -> want to do it once -> MINE.
353  - The item being deleted (or renamed) in the source has been renamed in the
354    target branch.
355    -> want to delete/rename something else -> ELSEWHERE.
356
357Options:
358  THEIRS: Nothing to do - same result as MINE.
359  MINE:   (Nothing to do.)
360  ELSEWHERE: Leave TARGET as it is, and
361    - Find the new name(s).
362    - svn delete MYNEWNAME
363      or
364      svn rename MYNEWNAME THEIRNEWNAME
365
366
367merge: Del onto Not Same Kind
368-----------------------------
369
370WC State:
371  .working: =.mine
372  .mine:    sched=(not Del), content=TheOtherKind
373  .theirs:  action=Del, content=None
374
375Some use cases:
376  - User's process is wrong: maybe something else needed to be merged first.
377    -> want to revert this whole merge.
378
379Options:
380  THEIRS:
381    - svn delete TARGET
382  MINE:   (Nothing to do.)
383
384
385merge: Del onto Not Same Content
386--------------------------------
387
388WC State:
389  .working: =.mine
390  .mine:    sched=(not Del), content=SameKind
391  .theirs:  action=Del, content=None
392
393Some use cases:
394  - The content was intentionally divergent, and we still want to delete it.
395    -> THEIRS.
396  - The content was intentionally divergent, and the source node is being
397    renamed (and possibly modified at the same time).
398    -> Apply the incoming rename (possibly +mod) onto mine -> RENAME.
399
400Options:
401  THEIRS:
402    - svn delete TARGET
403  MINE:   (Nothing to do.)
404  RENAME1: Apply their rename [+mod] onto mine. (Mine is the master.)
405    - Find the incoming new name.
406    - Wait till the new name has been processed (added).
407    - svn merge TARGET.old THEIRNEWNAME TARGET  [*1]
408    - svn revert THEIRNEWNAME
409    - svn rename TARGET THEIRNEWNAME
410  RENAME2: Reapply my mods onto their renamed item. (Theirs is the master.)
411    - Find the incoming new name.
412    - Wait till the new name has been processed (added).
413    - svn merge -r old:mine TARGET THEIRNEWNAME  [*1]
414    - svn resolve --accept=theirs TARGET
415
416
417merge: Mod onto Nothing Here
418----------------------------
419
420WC State:
421  .working: =.mine
422  .mine:    sched=(Del/unversioned), content=None
423  .theirs:  action=Mod, content=Something
424
425Some use cases:
426  - The item was renamed locally
427    -> apply the incoming mod elsewhere -> ELSEWHERE.
428
429Options:
430  THEIRS: Re-schedule the target to come back.
431    - copy TARGET.theirs TARGET
432    - svn add TARGET
433  MINE:   (Nothing to do.)
434  ELSEWHERE1: Apply their mod onto mine. (Mine is the master.)
435    - Find the new name.
436    - Wait till the new name has been processed (added).
437    - svn merge -r OLD:THEIRS TARGET NEWNAME  [*1]
438  ELSEWHERE2: Apply my rename[+mod] onto Theirs. (Theirs is the master.)
439    - svn merge -r BASE:WC NEWNAME TARGET.theirs  [*1]
440    - mv TARGET.theirs NEWNAME
441
442
443merge: Mod onto Not Same Kind
444-----------------------------
445
446WC State:
447  .working: =.mine
448  .mine:    sched=(not Del), content=TheOtherKind
449  .theirs:  action=Mod, content=Something
450
451Options:
452  THEIRS: Not supported. Throw an error. (Want to schedule the target to
453    replace with theirs, but WC doesn't support this.)
454  MINE:   (Nothing to do.)
455
456
457Note [*1]: These commands are not yet supported.
458
459
460Arbitrary Merge Facility Required
461=================================
462
463To enable the user to resolve a "Rename onto Mod" or "Mod onto Rename"
464conflict efficiently and flexible, we need the ability to merge the difference
465between two arbitrary WC items into another WC item. The two source items:
466  - may have different names;
467  - may be related by copyfrom info in one that in some way refers to the
468    other;
469  - may be pre-resolution conflict results like TARGET.mine or TARGET@mine.
470
471Two ways this could be achieved:
472
4731. Make use of history-sensitive merging by referring to the two items through
474   special revision kinds "old" "theirs" "mine":
475
476     svn merge -r old:theirs TARGET NEWNAME
477
4782. Use non-history-sensitive merging on arbitrary files
479   "<TARGET>.old" "<TARGET>.theirs" "<TARGET>.mine":
480
481     svn merge TARGET.old TARGET.theirs NEWNAME
482
483Q. How can we most easily implement an extension of "svn merge" that achieves
484a copyfrom-history-sensitive diff (between WC items) rather than an unaware
485diff?
486
487
488III. MARKING AS RESOLVED
489========================
490
491Primary APIs:
492
493  libsvn_wc/adm_ops.c:resolve_conflict_on_entry()
494
495Pre-tree-conflicts, the "resolve" functions in client through to WC layers all
496end up calling resolve_conflict_on_entry() on each item. It marks all text
497conflicts and property conflicts on the item as resolved. It also can select
498and copy into place one of the available file-text choices, but doesn't appear
499to have any such support for property conflicts.
500
501On the tree conflicts branch, (till branch@{2008-05-29} at least) this
502function assumes it will be passed the path to the parent dir of some conflict
503victims, and it simply clears tree conflict data about all victims from the
504entries file.
505
506Plan
507----
508
509Separate the different functions that resolve_conflict_on_entry() performs,
510making it more modular and "orthogonal".
511
512Make the tree conflict functions operate on one victim rather than on a whole
513parent directory having conflicts on any number of victims.
514
515Make these new functions public so that the caller can compose the various
516actions (copying, marking as resolved, notifying, and recursing) in whatever
517order it wants.
518
519Create the following new functions:
520
521  * Copy one of the simple outcomes (old, mine, theirs) onto the target.
522
523    select_conflict_outcome(path, svn_wc_conflict_choice_t, ...);
524    select_tree_conflict_outcome(victim_path, svn_wc_conflict_choice_t, ...);
525
526    - Copies the user's choice onto the "working" version of the item.
527    - For tree conflicts, also includes changing the scheduling of the item.
528    - This operation, and certainly the choice part of it, is logically above
529      the WC layer, except for knowledge of where the files to choose from are
530      stored.
531
532
533  * Mark conflicts as resolved on a (victim) path.
534
535    svn_wc_mark_conflict_resolved(path, ...);
536
537    - Mark text and property conflicts on one item as resolved.
538
539    svn_wc_mark_tree_conflict_resolved(victim_path, ...);
540
541    - Mark the tree conflict on one victim as resolved.
542
543
544  * Support for resolver callback? - where/how?
545
546
Note: See TracBrowser for help on using the repository browser.