comparison hgext/largefiles/lfutil.py @ 16247:d87d9d8a8e03

largefiles: remove use of underscores that breaks coding convention
author Na'Tosha Bard <natosha@unity3d.com>
date Fri, 09 Mar 2012 16:11:52 +0100
parents a18ad914aa21
children 73b9286e667c
comparison
equal deleted inserted replaced
16246:169525f8ffbb 16247:d87d9d8a8e03
21 longname = 'largefiles' 21 longname = 'largefiles'
22 22
23 23
24 # -- Portability wrappers ---------------------------------------------- 24 # -- Portability wrappers ----------------------------------------------
25 25
26 def dirstate_walk(dirstate, matcher, unknown=False, ignored=False): 26 def dirstatewalk(dirstate, matcher, unknown=False, ignored=False):
27 return dirstate.walk(matcher, [], unknown, ignored) 27 return dirstate.walk(matcher, [], unknown, ignored)
28 28
29 def repo_add(repo, list): 29 def repoadd(repo, list):
30 add = repo[None].add 30 add = repo[None].add
31 return add(list) 31 return add(list)
32 32
33 def repo_remove(repo, list, unlink=False): 33 def reporemove(repo, list, unlink=False):
34 def remove(list, unlink): 34 def remove(list, unlink):
35 wlock = repo.wlock() 35 wlock = repo.wlock()
36 try: 36 try:
37 if unlink: 37 if unlink:
38 for f in list: 38 for f in list:
44 repo[None].forget(list) 44 repo[None].forget(list)
45 finally: 45 finally:
46 wlock.release() 46 wlock.release()
47 return remove(list, unlink=unlink) 47 return remove(list, unlink=unlink)
48 48
49 def repo_forget(repo, list): 49 def repoforget(repo, list):
50 forget = repo[None].forget 50 forget = repo[None].forget
51 return forget(list) 51 return forget(list)
52 52
53 def findoutgoing(repo, remote, force): 53 def findoutgoing(repo, remote, force):
54 from mercurial import discovery 54 from mercurial import discovery
123 util.makedirs(os.path.dirname(path)) 123 util.makedirs(os.path.dirname(path))
124 link(usercachepath(repo.ui, hash), path) 124 link(usercachepath(repo.ui, hash), path)
125 return path 125 return path
126 return None 126 return None
127 127
128 class largefiles_dirstate(dirstate.dirstate): 128 class largefilesdirstate(dirstate.dirstate):
129 def __getitem__(self, key): 129 def __getitem__(self, key):
130 return super(largefiles_dirstate, self).__getitem__(unixpath(key)) 130 return super(largefilesdirstate, self).__getitem__(unixpath(key))
131 def normal(self, f): 131 def normal(self, f):
132 return super(largefiles_dirstate, self).normal(unixpath(f)) 132 return super(largefilesdirstate, self).normal(unixpath(f))
133 def remove(self, f): 133 def remove(self, f):
134 return super(largefiles_dirstate, self).remove(unixpath(f)) 134 return super(largefilesdirstate, self).remove(unixpath(f))
135 def add(self, f): 135 def add(self, f):
136 return super(largefiles_dirstate, self).add(unixpath(f)) 136 return super(largefilesdirstate, self).add(unixpath(f))
137 def drop(self, f): 137 def drop(self, f):
138 return super(largefiles_dirstate, self).drop(unixpath(f)) 138 return super(largefilesdirstate, self).drop(unixpath(f))
139 def forget(self, f): 139 def forget(self, f):
140 return super(largefiles_dirstate, self).forget(unixpath(f)) 140 return super(largefilesdirstate, self).forget(unixpath(f))
141 def normallookup(self, f): 141 def normallookup(self, f):
142 return super(largefiles_dirstate, self).normallookup(unixpath(f)) 142 return super(largefilesdirstate, self).normallookup(unixpath(f))
143 143
144 def openlfdirstate(ui, repo): 144 def openlfdirstate(ui, repo):
145 ''' 145 '''
146 Return a dirstate object that tracks largefiles: i.e. its root is 146 Return a dirstate object that tracks largefiles: i.e. its root is
147 the repo root, but it is saved in .hg/largefiles/dirstate. 147 the repo root, but it is saved in .hg/largefiles/dirstate.
148 ''' 148 '''
149 admin = repo.join(longname) 149 admin = repo.join(longname)
150 opener = scmutil.opener(admin) 150 opener = scmutil.opener(admin)
151 lfdirstate = largefiles_dirstate(opener, ui, repo.root, 151 lfdirstate = largefilesdirstate(opener, ui, repo.root,
152 repo.dirstate._validate) 152 repo.dirstate._validate)
153 153
154 # If the largefiles dirstate does not exist, populate and create 154 # If the largefiles dirstate does not exist, populate and create
155 # it. This ensures that we create it on the first meaningful 155 # it. This ensures that we create it on the first meaningful
156 # largefiles operation in a new clone. 156 # largefiles operation in a new clone.
157 if not os.path.exists(os.path.join(admin, 'dirstate')): 157 if not os.path.exists(os.path.join(admin, 'dirstate')):
158 util.makedirs(admin) 158 util.makedirs(admin)
159 matcher = getstandinmatcher(repo) 159 matcher = getstandinmatcher(repo)
160 for standin in dirstate_walk(repo.dirstate, matcher): 160 for standin in dirstatewalk(repo.dirstate, matcher):
161 lfile = splitstandin(standin) 161 lfile = splitstandin(standin)
162 hash = readstandin(repo, lfile) 162 hash = readstandin(repo, lfile)
163 lfdirstate.normallookup(lfile) 163 lfdirstate.normallookup(lfile)
164 try: 164 try:
165 if hash == hashfile(repo.wjoin(lfile)): 165 if hash == hashfile(repo.wjoin(lfile)):
167 except OSError, err: 167 except OSError, err:
168 if err.errno != errno.ENOENT: 168 if err.errno != errno.ENOENT:
169 raise 169 raise
170 return lfdirstate 170 return lfdirstate
171 171
172 def lfdirstate_status(lfdirstate, repo, rev): 172 def lfdirstatestatus(lfdirstate, repo, rev):
173 match = match_.always(repo.root, repo.getcwd()) 173 match = match_.always(repo.root, repo.getcwd())
174 s = lfdirstate.status(match, [], False, False, False) 174 s = lfdirstate.status(match, [], False, False, False)
175 unsure, modified, added, removed, missing, unknown, ignored, clean = s 175 unsure, modified, added, removed, missing, unknown, ignored, clean = s
176 for lfile in unsure: 176 for lfile in unsure:
177 if repo[rev][standin(lfile)].data().strip() != \ 177 if repo[rev][standin(lfile)].data().strip() != \
284 '''Return a matcher that accepts standins corresponding to the 284 '''Return a matcher that accepts standins corresponding to the
285 files accepted by rmatcher. Pass the list of files in the matcher 285 files accepted by rmatcher. Pass the list of files in the matcher
286 as the paths specified by the user.''' 286 as the paths specified by the user.'''
287 smatcher = getstandinmatcher(repo, rmatcher.files()) 287 smatcher = getstandinmatcher(repo, rmatcher.files())
288 isstandin = smatcher.matchfn 288 isstandin = smatcher.matchfn
289 def composed_matchfn(f): 289 def composedmatchfn(f):
290 return isstandin(f) and rmatcher.matchfn(splitstandin(f)) 290 return isstandin(f) and rmatcher.matchfn(splitstandin(f))
291 smatcher.matchfn = composed_matchfn 291 smatcher.matchfn = composedmatchfn
292 292
293 return smatcher 293 return smatcher
294 294
295 def standin(filename): 295 def standin(filename):
296 '''Return the repo-relative path to the standin for the specified big 296 '''Return the repo-relative path to the standin for the specified big
297 file.''' 297 file.'''
298 # Notes: 298 # Notes:
299 # 1) Most callers want an absolute path, but _create_standin() needs 299 # 1) Most callers want an absolute path, but _createstandin() needs
300 # it repo-relative so lfadd() can pass it to repo_add(). So leave 300 # it repo-relative so lfadd() can pass it to repoadd(). So leave
301 # it up to the caller to use repo.wjoin() to get an absolute path. 301 # it up to the caller to use repo.wjoin() to get an absolute path.
302 # 2) Join with '/' because that's what dirstate always uses, even on 302 # 2) Join with '/' because that's what dirstate always uses, even on
303 # Windows. Change existing separator to '/' first in case we are 303 # Windows. Change existing separator to '/' first in case we are
304 # passed filenames from an external source (like the command line). 304 # passed filenames from an external source (like the command line).
305 return shortname + '/' + util.pconvert(filename) 305 return shortname + '/' + util.pconvert(filename)
451 return heads 451 return heads
452 452
453 def getstandinsstate(repo): 453 def getstandinsstate(repo):
454 standins = [] 454 standins = []
455 matcher = getstandinmatcher(repo) 455 matcher = getstandinmatcher(repo)
456 for standin in dirstate_walk(repo.dirstate, matcher): 456 for standin in dirstatewalk(repo.dirstate, matcher):
457 lfile = splitstandin(standin) 457 lfile = splitstandin(standin)
458 standins.append((lfile, readstandin(repo, lfile))) 458 standins.append((lfile, readstandin(repo, lfile)))
459 return standins 459 return standins
460 460
461 def getlfilestoupdate(oldstandins, newstandins): 461 def getlfilestoupdate(oldstandins, newstandins):