summaryrefslogtreecommitdiff
path: root/mercurial/bookmarks.py
diff options
context:
space:
mode:
Diffstat (limited to 'mercurial/bookmarks.py')
-rw-r--r--mercurial/bookmarks.py92
1 files changed, 23 insertions, 69 deletions
diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
index a7cd854..a017678 100644
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -26,17 +26,11 @@ def read(repo):
bookmarks = {}
try:
for line in repo.opener('bookmarks'):
- line = line.strip()
- if not line:
- continue
- if ' ' not in line:
- repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n') % line)
- continue
- sha, refspec = line.split(' ', 1)
+ sha, refspec = line.strip().split(' ', 1)
refspec = encoding.tolocal(refspec)
try:
bookmarks[refspec] = repo.changelog.lookup(sha)
- except LookupError:
+ except error.RepoLookupError:
pass
except IOError, inst:
if inst.errno != errno.ENOENT:
@@ -90,7 +84,7 @@ def write(repo):
file = repo.opener('bookmarks', 'w', atomictemp=True)
for refspec, node in refs.iteritems():
file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec)))
- file.close()
+ file.rename()
# touch 00changelog.i so hgweb reloads bookmarks (no lock needed)
try:
@@ -121,63 +115,42 @@ def setcurrent(repo, mark):
try:
file = repo.opener('bookmarks.current', 'w', atomictemp=True)
file.write(encoding.fromlocal(mark))
- file.close()
+ file.rename()
finally:
wlock.release()
repo._bookmarkcurrent = mark
-def unsetcurrent(repo):
- wlock = repo.wlock()
- try:
- try:
- util.unlink(repo.join('bookmarks.current'))
- repo._bookmarkcurrent = None
- except OSError, inst:
- if inst.errno != errno.ENOENT:
- raise
- finally:
- wlock.release()
-
def updatecurrentbookmark(repo, oldnode, curbranch):
try:
- return update(repo, oldnode, repo.branchtip(curbranch))
- except error.RepoLookupError:
+ update(repo, oldnode, repo.branchtags()[curbranch])
+ except KeyError:
if curbranch == "default": # no default branch!
- return update(repo, oldnode, repo.lookup("tip"))
+ update(repo, oldnode, repo.lookup("tip"))
else:
raise util.Abort(_("branch %s not found") % curbranch)
def update(repo, parents, node):
marks = repo._bookmarks
update = False
- cur = repo._bookmarkcurrent
- if not cur:
- return False
-
- toupdate = [b for b in marks if b.split('@', 1)[0] == cur.split('@', 1)[0]]
- for mark in toupdate:
- if mark and marks[mark] in parents:
- old = repo[marks[mark]]
- new = repo[node]
- if new in old.descendants() and mark == cur:
- marks[cur] = new.node()
- update = True
- if mark != cur:
- del marks[mark]
+ mark = repo._bookmarkcurrent
+ if mark and marks[mark] in parents:
+ old = repo[marks[mark]]
+ new = repo[node]
+ if new in old.descendants():
+ marks[mark] = new.node()
+ update = True
if update:
- repo._writebookmarks(marks)
- return update
+ write(repo)
def listbookmarks(repo):
# We may try to list bookmarks on a repo type that does not
# support it (e.g., statichttprepository).
- marks = getattr(repo, '_bookmarks', {})
+ if not hasattr(repo, '_bookmarks'):
+ return {}
d = {}
- for k, v in marks.iteritems():
- # don't expose local divergent bookmarks
- if '@' not in k or k.endswith('@'):
- d[k] = hex(v)
+ for k, v in repo._bookmarks.iteritems():
+ d[k] = hex(v)
return d
def pushbookmark(repo, key, old, new):
@@ -197,7 +170,7 @@ def pushbookmark(repo, key, old, new):
finally:
w.release()
-def updatefromremote(ui, repo, remote, path):
+def updatefromremote(ui, repo, remote):
ui.debug("checking for updated bookmarks\n")
rb = remote.listkeys('bookmarks')
changed = False
@@ -214,26 +187,8 @@ def updatefromremote(ui, repo, remote, path):
changed = True
ui.status(_("updating bookmark %s\n") % k)
else:
- # find a unique @ suffix
- for x in range(1, 100):
- n = '%s@%d' % (k, x)
- if n not in repo._bookmarks:
- break
- # try to use an @pathalias suffix
- # if an @pathalias already exists, we overwrite (update) it
- for p, u in ui.configitems("paths"):
- if path == u:
- n = '%s@%s' % (k, p)
-
- repo._bookmarks[n] = cr.node()
- changed = True
- ui.warn(_("divergent bookmark %s stored as %s\n") % (k, n))
- elif rb[k] in repo:
- # add remote bookmarks for changes we already have
- repo._bookmarks[k] = repo[rb[k]].node()
- changed = True
- ui.status(_("adding remote bookmark %s\n") % k)
-
+ ui.warn(_("not updating divergent"
+ " bookmark %s\n") % k)
if changed:
write(repo)
@@ -245,8 +200,7 @@ def diff(ui, repo, remote):
diff = sorted(set(rmarks) - set(lmarks))
for k in diff:
- mark = ui.debugflag and rmarks[k] or rmarks[k][:12]
- ui.write(" %-25s %s\n" % (k, mark))
+ ui.write(" %-25s %s\n" % (k, rmarks[k][:12]))
if len(diff) <= 0:
ui.status(_("no changed bookmarks found\n"))