Changeset 35d64ba16cb6…
Parent bf74641d43fb…
by Benjamin Pollack <benjamin@fogcreek.com>
Changes to 12 files · Browse files at 35d64ba16cb6 Showing diff from parent bf74641d43fb Diff from another changeset...
@@ -21,8 +21,11 @@ '''
from mercurial import commands
+from mercurial import wireproto
+
import bfsetup
import bfcommands
+import bfproto
reposetup = bfsetup.reposetup
uisetup = bfsetup.uisetup
@@ -30,3 +33,14 @@commands.norepo += " kbfconvert"
cmdtable = bfcommands.cmdtable
+
+def extsetup(ui):
+ wireproto.commands['putbfile'] = (bfproto.putbfile, 'sha')
+ wireproto.commands['getbfile'] = (bfproto.getbfile, 'sha')
+ wireproto.commands['statbfile'] = (bfproto.statbfile, 'sha')
+ wireproto.commands['capabilities'] = (bfproto.capabilities, '')
+ wireproto.dispatch = bfproto.dispatch
+
+ wireproto.wirerepository.putbfile = bfproto.wirerepo_putbfile
+ wireproto.wirerepository.getbfile = bfproto.wirerepo_getbfile
+ wireproto.wirerepository.statbfile = bfproto.wirerepo_statbfile
|
@@ -20,9 +20,14 @@ self.detail = detail
def longmessage(self):
- return ("%s: %s\n"
- "(failed URL: %s)\n"
- % (self.filename, self.detail, self.url))
+ if self.url:
+ return ('%s: %s\n'
+ '(failed URL: %s)\n'
+ % (self.filename, self.detail, self.url))
+ else:
+ return ('%s: %s\n'
+ '(no default or default-push path set in hgrc)\n'
+ % (self.filename, self.detail))
def __str__(self):
return "%s: %s" % (self.url, self.detail)
@@ -74,6 +79,7 @@ try:
bhash = self._getfile(tmpfile, filename, hash)
except StoreError, err:
+ tmpfile.close()
ui.warn(err.longmessage())
os.remove(tmpfilename)
missing.append(filename)
@@ -157,12 +163,14 @@def _openstore(repo, path=None, put=False):
ui = repo.ui
if not path:
- path = ui.expandpath('default-push', 'default')
- # If 'default-push' and 'default' can't be expanded
- # they are just returned. In that case use the empty string which
- # use the filescheme.
- if path is 'default-push' or path is 'default':
- path = ''
+ path = getattr(repo, 'bfpullsource', None)
+ if not path:
+ path = ui.expandpath('default-push', 'default')
+ # If 'default-push' and 'default' can't be expanded
+ # they are just returned. In that case fail with an informative
+ # error message
+ if path in ('default-push', 'default'):
+ path = ''
# The path could be a scheme so use Mercurial's normal functionality
# to resolve the scheme to a repository and use its path
@@ -176,7 +184,7 @@ scheme = match.group(1)
try:
- (mod, klass) = _storeprovider[scheme]
+ mod, klass = _storeprovider[scheme]
except KeyError:
raise util.Abort(_('unsupported URL scheme %r') % scheme)
|
@@ -421,7 +421,7 @@
removed = 0
for bfile in bfdirstate:
- if filelist == None or bfile in filelist:
+ if filelist is None or bfile in filelist:
if not os.path.exists(repo.wjoin(bfutil.standin(bfile))):
if os.path.exists(repo.wjoin(bfile)):
os.unlink(repo.wjoin(bfile))
|
|
@@ -0,0 +1,57 @@ + import tempfile, shutil, os
+
+from mercurial.i18n import _
+from mercurial import wireproto, error, util
+
+import bfutil, bfsetup
+
+def putbfile(repo, proto, sha):
+ fd, tempname = tempfile.mkstemp(prefix='hg-putbfile-')
+ with os.fdopen(fd, 'wb+') as fp:
+ proto.getfile(fp)
+ bfutil.copytocacheabsolute(repo, tempname, sha)
+ return ''
+
+def getbfile(repo, proto, sha):
+ filename = bfutil.findfile(repo, sha)
+ if not filename:
+ raise util.Abort(_('requested bfile %s not present in cache') % sha)
+ f = open(filename, 'rb')
+ return wireproto.streamres(f)
+
+# '0' for OK, '1' for invalid checksum, '2' for missing
+def statbfile(repo, proto, sha):
+ filename = bfutil.findfile(repo, sha)
+ if not filename:
+ return '2\n'
+ with open(filename, 'rb') as f:
+ return '0\n' if bfutil.hexsha1(f) == sha else '1\n'
+
+def wirerepo_putbfile(self, sha, fd):
+ return self._callstream("putbfile", data=fd, sha=sha, headers={'content-type':'application/mercurial-0.1'})
+
+def wirerepo_getbfile(self, sha):
+ return self._callstream("getbfile", sha=sha)
+
+def wirerepo_statbfile(self, sha):
+ try:
+ return int(self._call("statbfile", sha=sha))
+ except:
+ return 2
+ # if the server returns something that's not an integer followed by a
+ # newline, it's not kbfiles-capable, so obviously it doesn't have the
+ # bfile; any other exception means _something_ went wrong, so tell the
+ # caller the bfile is missing
+
+def dispatch(repo, proto, command):
+ func, spec = wireproto.commands[command]
+ args = proto.getargs(spec)
+ if len(args) > 0 and isinstance(args[-1], dict):
+ if bfutil.listbfiles(repo) and command in affectedcommands and not args[-1].pop('kbfiles'):
+ return '0\n'
+ return func(repo, proto, *args)
+
+def capabilities(repo, proto):
+ return wireproto.capabilities(repo, proto) + ' bfilestore=serve'
+
+affectedcommands = [ 'changegroup', 'changegroupsubset', 'getbundle', 'unbundle', 'stream_out', 'pushkey' ]
|
@@ -88,7 +88,7 @@ return result
ctx.__class__ = bfiles_ctx
return ctx
-
+
# Figure out the status of big files and insert them into the
# appropriate list in the result. Also removes standin files from
# the listing. This function reverts to the original status if
@@ -233,7 +233,7 @@ try:
if getattr(repo, "_isrebasing", False):
# We have to take the time to pull down the new bfiles now. Otherwise
- # if we are rebasing, any bfiles that were modified in the changesets we
+ # if we are rebasing, any bfiles that were modified in the changesets we
# are rebasing on top of get overwritten either by the rebase or in the
# first commit after the rebase.
bfcommands.updatebfiles(repo.ui, repo)
@@ -942,7 +942,7 @@# When we rebase a repository with remotely changed bfiles, we need
# to take some extra care so that the bfiles are correctly updated
# in the working copy
-def override_pull(orig, ui, repo, source="default", **opts):
+def override_pull(orig, ui, repo, source=None, **opts):
if opts.get('rebase', False):
repo._isrebasing = True
try:
@@ -962,6 +962,9 @@ def _dummy(*args, **kwargs):
pass
commands.postincoming = _dummy
+ repo.bfpullsource = source
+ if not source:
+ source = 'default'
try:
result = commands.pull(ui, repo, source, **opts)
finally:
@@ -974,6 +977,9 @@ finally:
repo._isrebasing = False
else:
+ repo.bfpullsource = source
+ if not source:
+ source = 'default'
result = orig(ui, repo, source, **opts)
return result
@@ -1267,7 +1273,7 @@ bfdirstate.add(file)
bfdirstate.write()
return result
-
+
def uisetup(ui):
# Disable auto-status for some commands which assume that all
# files in the result are under Mercurial's control
|
@@ -1,10 +1,6 @@ '''bfiles utility code: must not import other modules in this package.'''
-import os
-import errno
-import inspect
-import shutil
-import stat
+import os, errno, inspect, shutil, stat, hashlib
from mercurial import \
util, dirstate, cmdutil, match as match_
@@ -63,7 +59,7 @@ repo[None].forget(list)
finally:
wlock.release()
-
+
return remove(list, unlink=unlink)
def repo_forget(repo, list):
@@ -247,12 +243,15 @@ hash = readstandin(repo, standin(file))
if incache(repo, hash):
return
+ copytocacheabsolute(repo, repo.wjoin(file), hash)
+
+def copytocacheabsolute(repo, file, hash):
createdir(os.path.dirname(cachepath(repo, hash)))
if insystemcache(repo.ui, hash):
link(systemcachepath(repo.ui, hash), cachepath(repo, hash))
else:
- shutil.copyfile(repo.wjoin(file), cachepath(repo, hash))
- os.chmod(cachepath(repo, hash), os.stat(repo.wjoin(file)).st_mode)
+ shutil.copyfile(file, cachepath(repo, hash))
+ os.chmod(cachepath(repo, hash), os.stat(file).st_mode)
createdir(os.path.dirname(systemcachepath(repo.ui, hash)))
link(cachepath(repo, hash), systemcachepath(repo.ui, hash))
@@ -287,7 +286,7 @@ except ImportError:
# Mercurial <= 1.8
match = cmdutil.match(repo, pats, opts)
-
+
if not showbad:
match.bad = lambda f, msg: None
return match
@@ -435,6 +434,12 @@ url = join(url, a)
return url
+def hexsha1(data):
+ h = hashlib.sha1()
+ for chunk in util.filechunkiter(data):
+ h.update(chunk)
+ return h.hexdigest()
+
# Convert a path to a unix style path. This is used to give a
# canonical path to the bfdirstate.
def unixpath(path):
|
@@ -32,7 +32,7 @@ stdout, stderr = child.communicate()
versions = re.findall(r'\d+\.\d+(?:\.\d+)?', stdout)
parts = [re.match(r'\d+', v).group(0) for v in versions[0].split('.')]
-
+
version = [0, 0, 0]
for i, part in enumerate(map(int, parts)):
version[i] = part
|
@@ -5,6 +5,6 @@ # write access to that repo group.
KILNEXTPATH = '~/kiln/extensions'
-KILNURL = 'http://localhost/FogBugz/kiln'
+KILNURL = 'http://localhost/kiln'
USER = 'test'
PASSWORD = 'tester'
|
@@ -350,3 +350,41 @@ ''')
os.chdir('..')
common.checkrepos(hgt, 'repo1', 'repo2', [0, 3, 4, 5, 8, 11, 14, 17])
+
+hgt.announce('no default path error')
+os.mkdir('repo3')
+os.chdir('repo3')
+hgt.hg(['init'])
+hgt.hg(['pull', '../repo1'],
+ stdout='''pulling from ../repo1
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 18 changesets with 33 changes to 16 files
+(run 'hg update' to get a working copy)
+''')
+hgt.writefile('.hg/hgrc', '''[kilnbfiles]
+systemcache = .
+''')
+hgt.hg(['up'],
+ stdout='''13 files updated, 0 files merged, 0 files removed, 0 files unresolved
+getting changed bfiles
+0 big files updated, 0 removed
+''', stderr='''b1: Can't get file locally
+(no default or default-push path set in hgrc)
+dir/b1.foo: Can't get file locally
+(no default or default-push path set in hgrc)
+dir/b2: Can't get file locally
+(no default or default-push path set in hgrc)
+dir/b2222.foo: Can't get file locally
+(no default or default-push path set in hgrc)
+dir/b3.foo: Can't get file locally
+(no default or default-push path set in hgrc)
+dir/b3333.foo: Can't get file locally
+(no default or default-push path set in hgrc)
+dir/b4: Can't get file locally
+(no default or default-push path set in hgrc)
+dir/b4.foo: Can't get file locally
+(no default or default-push path set in hgrc)
+''')
|
@@ -68,3 +68,8 @@ hg commit -m merge
hg push ../repo1
hg up
+
+% no default path error
+hg init
+hg pull ../repo1
+hg up
|
@@ -84,7 +84,9 @@ if before != after:
try:
os.rename(self.__temporary_path, self.__original_path)
- except (IOError, WindowsError, OSError):
+ except WindowsError:
+ shutil.copyfile(self.__temporary_path, self.__original_path)
+ except (IOError, OSError):
pass
def get_cookiejar(ui):
|
Loading...