~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remotebranch.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-01 21:56:19 UTC
  • mto: (2255.7.84 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: john@arbash-meinel.com-20070301215619-wpt6kz8yem3ypu1b
Update to dirstate locking.
Move all of WT4.lock_* functions locally, so that they can
properly interact and cleanup around when we lock/unlock the
dirstate file.
Change all Lock objects to be non-blocking. So that if someone
grabs a lock on the DirState we find out immediately, rather
than blocking.
Change WT4.unlock() so that if the dirstate is dirty, it will
save the contents even if it only has a read lock.
It does this by trying to take a write lock, if it fails
we just ignore it. If it succeeds, then we can flush to disk.
This is more important now that DirState tracks file changes.
It allows 'bzr status' to update the cached stat and sha values.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
 
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
 
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
 
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
 
18
 
## XXX: This is pretty slow on high-latency connections because it
19
 
## doesn't keep the HTTP connection alive.  If you have a smart local
20
 
## proxy it may be much better.  Eventually I want to switch to
21
 
## urlgrabber which should use HTTP much more efficiently.
22
 
 
23
 
 
24
 
import urllib2, gzip, zlib
25
 
from sets import Set
26
 
from cStringIO import StringIO
27
 
 
28
 
from errors import BzrError
29
 
from revision import Revision
30
 
from inventory import Inventory
31
 
 
32
 
# h = HTTPConnection('localhost:8000')
33
 
# h = HTTPConnection('bazaar-ng.org')
34
 
 
35
 
# velocitynet.com.au transparently proxies connections and thereby
36
 
# breaks keep-alive -- sucks!
37
 
 
38
 
 
39
 
import urlgrabber.keepalive
40
 
urlgrabber.keepalive.DEBUG = 2
41
 
 
42
 
import urlgrabber
43
 
 
44
 
prefix = 'http://localhost:8000'
45
 
# prefix = 'http://bazaar-ng.org/bzr/main/'
46
 
 
47
 
def get_url(path, compressed=False):
48
 
    try:
49
 
        url = prefix + path
50
 
        if compressed:
51
 
            url += '.gz'
52
 
        url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
53
 
        if not compressed:
54
 
            return url_f
55
 
        else:
56
 
            return gzip.GzipFile(fileobj=StringIO(url_f.read()))
57
 
    except urllib2.URLError, e:
58
 
        raise BzrError("remote fetch failed: %r: %s" % (url, e))
59
 
 
60
 
 
61
 
got_invs = Set()
62
 
got_texts = Set()
63
 
 
64
 
print 'read history'
65
 
history = get_url('/.bzr/revision-history').readlines()
66
 
num_revs = len(history)
67
 
for i, rev_id in enumerate(history):
68
 
    rev_id = rev_id.rstrip()
69
 
    print 'read revision %d/%d' % (i, num_revs)
70
 
 
71
 
    # python gzip needs a seekable file (!!) but the HTTP response
72
 
    # isn't, so we need to buffer it
73
 
    
74
 
    rev_f = get_url('/.bzr/revision-store/%s' % rev_id,
75
 
                    compressed=True)
76
 
 
77
 
    rev = Revision.read_xml(rev_f)
78
 
    print rev.message
79
 
    inv_id = rev.inventory_id
80
 
    if inv_id not in got_invs:
81
 
        print 'get inventory %s' % inv_id
82
 
        inv_f = get_url('/.bzr/inventory-store/%s' % inv_id,
83
 
                        compressed=True)
84
 
        inv = Inventory.read_xml(inv_f)
85
 
        print '%4d inventory entries' % len(inv)
86
 
 
87
 
        for path, ie in inv.iter_entries():
88
 
            text_id = ie.text_id
89
 
            if text_id == None:
90
 
                continue
91
 
            if text_id in got_texts:
92
 
                continue
93
 
            print '  fetch %s text {%s}' % (path, text_id)
94
 
            text_f = get_url('/.bzr/text-store/%s' % text_id,
95
 
                             compressed=True)
96
 
            got_texts.add(text_id)
97
 
            
98
 
        got_invs.add(inv_id)
99
 
 
100
 
    print '----'