annotate mercurial/destutil.py @ 26610:f9f82c444ff7

filemerge: only copy to backup during premerge step The premerge might leave the original file in an unclean state. Therefore it's important to only copy the file in the beginning.
author Siddharth Agarwal <sid0@fb.com>
date Sun, 11 Oct 2015 20:04:40 -0700
parents 56b2bcea2529
children 45b86dbabbda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
1 # destutil.py - Mercurial utility function for command destination
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
2 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
3 # Copyright Matt Mackall <mpm@selenic.com> and other
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
4 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
7
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
8 from .i18n import _
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
9 from . import (
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
10 error,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
11 obsolete,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
12 )
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
13
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
14 def destupdate(repo):
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
15 """destination for bare update operation
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
16 """
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
17 # Here is where we should consider bookmarks, divergent bookmarks, and tip
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
18 # of current branch; but currently we are only checking the branch tips.
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
19 node = None
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
20 wc = repo[None]
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
21 p1 = wc.p1()
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
22 try:
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
23 node = repo.branchtip(wc.branch())
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
24 except error.RepoLookupError:
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
25 if wc.branch() == 'default': # no default branch!
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
26 node = repo.lookup('tip') # update to tip
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
27 else:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26569
diff changeset
28 raise error.Abort(_("branch %s not found") % wc.branch())
26569
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
29
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
30 if p1.obsolete() and not p1.children():
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
31 # allow updating to successors
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
32 successors = obsolete.successorssets(repo, p1.node())
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
33
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
34 # behavior of certain cases is as follows,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
35 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
36 # divergent changesets: update to highest rev, similar to what
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
37 # is currently done when there are more than one head
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
38 # (i.e. 'tip')
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
39 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
40 # replaced changesets: same as divergent except we know there
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
41 # is no conflict
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
42 #
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
43 # pruned changeset: no update is done; though, we could
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
44 # consider updating to the first non-obsolete parent,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
45 # similar to what is current done for 'hg prune'
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
46
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
47 if successors:
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
48 # flatten the list here handles both divergent (len > 1)
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
49 # and the usual case (len = 1)
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
50 successors = [n for sub in successors for n in sub]
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
51
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
52 # get the max revision for the given successors set,
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
53 # i.e. the 'tip' of a set
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
54 node = repo.revs('max(%ln)', successors).first()
2aeeef1dc9a5 update: move default destination computation to a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
55 return repo[node].rev()