Mercurial > hg > mercurial-crew-with-dirclash
comparison hgext/fetch.py @ 2816:2a0c599f7bb0
fetch: hold lock and wlock across all operations
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Tue, 08 Aug 2006 17:08:59 -0700 |
parents | 0496cfb05243 |
children | 49988d9f0758 |
comparison
equal
deleted
inserted
replaced
2815:bce6918b0474 | 2816:2a0c599f7bb0 |
---|---|
22 | 22 |
23 def postincoming(other, modheads): | 23 def postincoming(other, modheads): |
24 if modheads == 0: | 24 if modheads == 0: |
25 return 0 | 25 return 0 |
26 if modheads == 1: | 26 if modheads == 1: |
27 return hg.update(repo, repo.changelog.tip()) | 27 return hg.update(repo, repo.changelog.tip(), wlock=wlock) |
28 newheads = repo.heads(parent) | 28 newheads = repo.heads(parent) |
29 newchildren = [n for n in repo.heads(parent) if n != parent] | 29 newchildren = [n for n in repo.heads(parent) if n != parent] |
30 newparent = parent | 30 newparent = parent |
31 if newchildren: | 31 if newchildren: |
32 newparent = newchildren[0] | 32 newparent = newchildren[0] |
33 hg.update(repo, newparent) | 33 hg.update(repo, newparent, wlock=wlock) |
34 newheads = [n for n in repo.heads() if n != newparent] | 34 newheads = [n for n in repo.heads() if n != newparent] |
35 err = False | 35 err = False |
36 if newheads: | 36 if newheads: |
37 ui.status(_('merging with new head %d:%s\n') % | 37 ui.status(_('merging with new head %d:%s\n') % |
38 (repo.changelog.rev(newheads[0]), short(newheads[0]))) | 38 (repo.changelog.rev(newheads[0]), short(newheads[0]))) |
39 err = hg.update(repo, newheads[0], allow=True, remind=False) | 39 err = hg.update(repo, newheads[0], allow=True, remind=False, |
40 wlock=wlock) | |
40 if not err and len(newheads) > 1: | 41 if not err and len(newheads) > 1: |
41 ui.status(_('not merging with %d other new heads ' | 42 ui.status(_('not merging with %d other new heads ' |
42 '(use "hg heads" and "hg merge" to merge them)') % | 43 '(use "hg heads" and "hg merge" to merge them)') % |
43 (len(newheads) - 1)) | 44 (len(newheads) - 1)) |
44 if not err: | 45 if not err: |
45 mod, add, rem = repo.status()[:3] | 46 mod, add, rem = repo.status(wlock=wlock)[:3] |
46 message = (commands.logmessage(opts) or | 47 message = (commands.logmessage(opts) or |
47 (_('Automated merge with %s') % other.url())) | 48 (_('Automated merge with %s') % other.url())) |
48 n = repo.commit(mod + add + rem, message, | 49 n = repo.commit(mod + add + rem, message, |
49 opts['user'], opts['date'], lock=lock, | 50 opts['user'], opts['date'], lock=lock, wlock=wlock, |
50 force_editor=opts.get('force_editor')) | 51 force_editor=opts.get('force_editor')) |
51 ui.status(_('new changeset %d:%s merges remote changes ' | 52 ui.status(_('new changeset %d:%s merges remote changes ' |
52 'with local\n') % (repo.changelog.rev(n), | 53 'with local\n') % (repo.changelog.rev(n), |
53 short(n))) | 54 short(n))) |
54 def pull(): | 55 def pull(): |
55 commands.setremoteconfig(ui, opts) | 56 commands.setremoteconfig(ui, opts) |
56 | 57 |
57 other = hg.repository(ui, ui.expandpath(source)) | 58 other = hg.repository(ui, ui.expandpath(source)) |
58 ui.status(_('pulling from %s\n') % source) | 59 ui.status(_('pulling from %s\n') % ui.expandpath(source)) |
59 revs = None | 60 revs = None |
60 if opts['rev'] and not other.local(): | 61 if opts['rev'] and not other.local(): |
61 raise util.Abort(_("fetch -r doesn't work for remote repositories yet")) | 62 raise util.Abort(_("fetch -r doesn't work for remote repositories yet")) |
62 elif opts['rev']: | 63 elif opts['rev']: |
63 revs = [other.lookup(rev) for rev in opts['rev']] | 64 revs = [other.lookup(rev) for rev in opts['rev']] |
68 if parent != repo.changelog.tip(): | 69 if parent != repo.changelog.tip(): |
69 raise util.Abort(_('working dir not at tip ' | 70 raise util.Abort(_('working dir not at tip ' |
70 '(use "hg update" to check out tip)')) | 71 '(use "hg update" to check out tip)')) |
71 if p2 != nullid: | 72 if p2 != nullid: |
72 raise util.Abort(_('outstanding uncommitted merge')) | 73 raise util.Abort(_('outstanding uncommitted merge')) |
73 mod, add, rem = repo.status()[:3] | 74 wlock = repo.wlock() |
74 if mod or add or rem: | |
75 raise util.Abort(_('outstanding uncommitted changes')) | |
76 if len(repo.heads()) > 1: | |
77 raise util.Abort(_('multiple heads in this repository ' | |
78 '(use "hg heads" and "hg merge" to merge them)')) | |
79 lock = repo.lock() | 75 lock = repo.lock() |
80 try: | 76 try: |
77 mod, add, rem = repo.status(wlock=wlock)[:3] | |
78 if mod or add or rem: | |
79 raise util.Abort(_('outstanding uncommitted changes')) | |
80 if len(repo.heads()) > 1: | |
81 raise util.Abort(_('multiple heads in this repository ' | |
82 '(use "hg heads" and "hg merge" to merge)')) | |
81 return pull() | 83 return pull() |
82 finally: | 84 finally: |
83 lock.release() | 85 lock.release() |
86 wlock.release() | |
84 | 87 |
85 cmdtable = { | 88 cmdtable = { |
86 'fetch': | 89 'fetch': |
87 (fetch, | 90 (fetch, |
88 [('e', 'ssh', '', _('specify ssh command to use')), | 91 [('e', 'ssh', '', _('specify ssh command to use')), |