Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 110:c37c7f784ee3
Move hg from storing files in data with base64 encoding to full
pathnames with .i and .d extensions. This means we naturally get good
FS layout, and cp and tar fix things up nicely rather than pessimizing
layout.
author | mpm@selenic.com |
---|---|
date | Fri, 20 May 2005 17:27:21 -0800 |
parents | 95699294f580 |
children | 1918852a67a8 |
comparison
equal
deleted
inserted
replaced
109:95699294f580 | 110:c37c7f784ee3 |
---|---|
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> | 3 # Copyright 2005 Matt Mackall <mpm@selenic.com> |
4 # | 4 # |
5 # This software may be used and distributed according to the terms | 5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. | 6 # of the GNU General Public License, incorporated herein by reference. |
7 | 7 |
8 import sys, struct, sha, socket, os, time, base64, re, urllib2 | 8 import sys, struct, sha, socket, os, time, re, urllib2 |
9 import urllib | 9 import urllib |
10 from mercurial import byterange | 10 from mercurial import byterange |
11 from mercurial.transaction import * | 11 from mercurial.transaction import * |
12 from mercurial.revlog import * | 12 from mercurial.revlog import * |
13 from difflib import SequenceMatcher | 13 from difflib import SequenceMatcher |
14 | 14 |
15 class filelog(revlog): | 15 class filelog(revlog): |
16 def __init__(self, opener, path): | 16 def __init__(self, opener, path): |
17 s = self.encodepath(path) | 17 revlog.__init__(self, opener, path + ".i", path + ".d") |
18 revlog.__init__(self, opener, os.path.join("data", s + "i"), | |
19 os.path.join("data", s)) | |
20 | |
21 def encodepath(self, path): | |
22 s = sha.sha(path).digest() | |
23 s = base64.encodestring(s)[:-3] | |
24 s = re.sub("\+", "%", s) | |
25 s = re.sub("/", "_", s) | |
26 return s | |
27 | 18 |
28 def read(self, node): | 19 def read(self, node): |
29 return self.revision(node) | 20 return self.revision(node) |
30 def add(self, text, transaction, link, p1=None, p2=None): | 21 def add(self, text, transaction, link, p1=None, p2=None): |
31 return self.addrevision(text, transaction, link, p1, p2) | 22 return self.addrevision(text, transaction, link, p1, p2) |
208 f = os.path.join(p, urllib.quote(path)) | 199 f = os.path.join(p, urllib.quote(path)) |
209 return httprangereader(f) | 200 return httprangereader(f) |
210 | 201 |
211 f = os.path.join(p, path) | 202 f = os.path.join(p, path) |
212 | 203 |
213 if mode != "r" and os.path.isfile(f): | 204 if mode != "r": |
214 s = os.stat(f) | 205 try: |
215 if s.st_nlink > 1: | 206 s = os.stat(f) |
216 file(f + ".tmp", "w").write(file(f).read()) | 207 except OSError: |
217 os.rename(f+".tmp", f) | 208 d = os.path.dirname(f) |
209 if not os.path.isdir(d): | |
210 os.makedirs(d) | |
211 else: | |
212 if s.st_nlink > 1: | |
213 file(f + ".tmp", "w").write(file(f).read()) | |
214 os.rename(f+".tmp", f) | |
218 | 215 |
219 return file(f, mode) | 216 return file(f, mode) |
220 | 217 |
221 return o | 218 return o |
222 | 219 |