##// END OF EJS Templates
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek -
r979:87d40e08 default
parent child Browse files
Show More
@@ -1,828 +1,840
1 1 # hgweb.py - web interface to a mercurial repository
2 2 #
3 3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
4 4 # Copyright 2005 Matt Mackall <mpm@selenic.com>
5 5 #
6 6 # This software may be used and distributed according to the terms
7 7 # of the GNU General Public License, incorporated herein by reference.
8 8
9 9 import os, cgi, time, re, difflib, socket, sys, zlib
10 10 from mercurial.hg import *
11 11 from mercurial.ui import *
12 12
13 13 def templatepath():
14 14 for f in "templates", "../templates":
15 15 p = os.path.join(os.path.dirname(__file__), f)
16 16 if os.path.isdir(p): return p
17 17
18 18 def age(t):
19 19 def plural(t, c):
20 20 if c == 1: return t
21 21 return t + "s"
22 22 def fmt(t, c):
23 23 return "%d %s" % (c, plural(t, c))
24 24
25 25 now = time.time()
26 26 delta = max(1, int(now - t))
27 27
28 28 scales = [["second", 1],
29 29 ["minute", 60],
30 30 ["hour", 3600],
31 31 ["day", 3600 * 24],
32 32 ["week", 3600 * 24 * 7],
33 33 ["month", 3600 * 24 * 30],
34 34 ["year", 3600 * 24 * 365]]
35 35
36 36 scales.reverse()
37 37
38 38 for t, s in scales:
39 39 n = delta / s
40 40 if n >= 2 or s == 1: return fmt(t, n)
41 41
42 42 def nl2br(text):
43 43 return text.replace('\n', '<br/>\n')
44 44
45 45 def obfuscate(text):
46 46 return ''.join([ '&#%d;' % ord(c) for c in text ])
47 47
48 48 def up(p):
49 49 if p[0] != "/": p = "/" + p
50 50 if p[-1] == "/": p = p[:-1]
51 51 up = os.path.dirname(p)
52 52 if up == "/":
53 53 return "/"
54 54 return up + "/"
55 55
56 56 def httphdr(type):
57 57 sys.stdout.write('Content-type: %s\n\n' % type)
58 58
59 59 def write(*things):
60 60 for thing in things:
61 61 if hasattr(thing, "__iter__"):
62 62 for part in thing:
63 63 write(part)
64 64 else:
65 65 sys.stdout.write(str(thing))
66 66
67 67 class templater:
68 68 def __init__(self, mapfile, filters = {}, defaults = {}):
69 69 self.cache = {}
70 70 self.map = {}
71 71 self.base = os.path.dirname(mapfile)
72 72 self.filters = filters
73 73 self.defaults = defaults
74 74
75 75 for l in file(mapfile):
76 76 m = re.match(r'(\S+)\s*=\s*"(.*)"$', l)
77 77 if m:
78 78 self.cache[m.group(1)] = m.group(2)
79 79 else:
80 80 m = re.match(r'(\S+)\s*=\s*(\S+)', l)
81 81 if m:
82 82 self.map[m.group(1)] = os.path.join(self.base, m.group(2))
83 83 else:
84 84 raise "unknown map entry '%s'" % l
85 85
86 86 def __call__(self, t, **map):
87 87 m = self.defaults.copy()
88 88 m.update(map)
89 89 try:
90 90 tmpl = self.cache[t]
91 91 except KeyError:
92 92 tmpl = self.cache[t] = file(self.map[t]).read()
93 93 return self.template(tmpl, self.filters, **m)
94 94
95 95 def template(self, tmpl, filters = {}, **map):
96 96 while tmpl:
97 97 m = re.search(r"#([a-zA-Z0-9]+)((%[a-zA-Z0-9]+)*)((\|[a-zA-Z0-9]+)*)#", tmpl)
98 98 if m:
99 99 yield tmpl[:m.start(0)]
100 100 v = map.get(m.group(1), "")
101 101 v = callable(v) and v(**map) or v
102 102
103 103 format = m.group(2)
104 104 fl = m.group(4)
105 105
106 106 if format:
107 107 q = v.__iter__
108 108 for i in q():
109 109 lm = map.copy()
110 110 lm.update(i)
111 111 yield self(format[1:], **lm)
112 112
113 113 v = ""
114 114
115 115 elif fl:
116 116 for f in fl.split("|")[1:]:
117 117 v = filters[f](v)
118 118
119 119 yield v
120 120 tmpl = tmpl[m.end(0):]
121 121 else:
122 122 yield tmpl
123 123 return
124 124
125 125 def rfc822date(x):
126 126 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x))
127 127
128 128 class hgweb:
129 129 maxchanges = 10
130 130 maxfiles = 10
131 131
132 132 def __init__(self, path, name, templates = ""):
133 133 self.templates = templates
134 134 self.reponame = name
135 135 self.path = path
136 136 self.mtime = -1
137 137 self.viewonly = 0
138 138
139 139 self.filters = {
140 140 "escape": cgi.escape,
141 141 "age": age,
142 142 "date": (lambda x: time.asctime(time.gmtime(x))),
143 143 "addbreaks": nl2br,
144 144 "obfuscate": obfuscate,
145 145 "short": (lambda x: x[:12]),
146 146 "firstline": (lambda x: x.splitlines(1)[0]),
147 147 "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"),
148 148 "rfc822date": rfc822date,
149 149 }
150 150
151 151 def refresh(self):
152 152 s = os.stat(os.path.join(self.path, ".hg", "00changelog.i"))
153 153 if s.st_mtime != self.mtime:
154 154 self.mtime = s.st_mtime
155 155 self.repo = repository(ui(), self.path)
156 156
157 157 def date(self, cs):
158 158 return time.asctime(time.gmtime(float(cs[2].split(' ')[0])))
159 159
160 160 def listfiles(self, files, mf):
161 161 for f in files[:self.maxfiles]:
162 162 yield self.t("filenodelink", node = hex(mf[f]), file = f)
163 163 if len(files) > self.maxfiles:
164 164 yield self.t("fileellipses")
165 165
166 166 def listfilediffs(self, files, changeset):
167 167 for f in files[:self.maxfiles]:
168 168 yield self.t("filedifflink", node = hex(changeset), file = f)
169 169 if len(files) > self.maxfiles:
170 170 yield self.t("fileellipses")
171 171
172 172 def parents(self, t1, nodes=[], rev=None,**args):
173 173 if not rev: rev = lambda x: ""
174 174 for node in nodes:
175 175 if node != nullid:
176 176 yield self.t(t1, node = hex(node), rev = rev(node), **args)
177 177
178 178 def showtag(self, t1, node=nullid, **args):
179 179 for t in self.repo.nodetags(node):
180 180 yield self.t(t1, tag = t, **args)
181 181
182 182 def diff(self, node1, node2, files):
183 183 def filterfiles(list, files):
184 184 l = [ x for x in list if x in files ]
185 185
186 186 for f in files:
187 187 if f[-1] != os.sep: f += os.sep
188 188 l += [ x for x in list if x.startswith(f) ]
189 189 return l
190 190
191 191 parity = [0]
192 192 def diffblock(diff, f, fn):
193 193 yield self.t("diffblock",
194 194 lines = prettyprintlines(diff),
195 195 parity = parity[0],
196 196 file = f,
197 197 filenode = hex(fn or nullid))
198 198 parity[0] = 1 - parity[0]
199 199
200 200 def prettyprintlines(diff):
201 201 for l in diff.splitlines(1):
202 202 if l.startswith('+'):
203 203 yield self.t("difflineplus", line = l)
204 204 elif l.startswith('-'):
205 205 yield self.t("difflineminus", line = l)
206 206 elif l.startswith('@'):
207 207 yield self.t("difflineat", line = l)
208 208 else:
209 209 yield self.t("diffline", line = l)
210 210
211 211 r = self.repo
212 212 cl = r.changelog
213 213 mf = r.manifest
214 214 change1 = cl.read(node1)
215 215 change2 = cl.read(node2)
216 216 mmap1 = mf.read(change1[0])
217 217 mmap2 = mf.read(change2[0])
218 218 date1 = self.date(change1)
219 219 date2 = self.date(change2)
220 220
221 221 c, a, d, u = r.changes(node1, node2)
222 222 if files:
223 223 c, a, d = map(lambda x: filterfiles(x, files), (c, a, d))
224 224
225 225 for f in c:
226 226 to = r.file(f).read(mmap1[f])
227 227 tn = r.file(f).read(mmap2[f])
228 228 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
229 229 for f in a:
230 230 to = None
231 231 tn = r.file(f).read(mmap2[f])
232 232 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
233 233 for f in d:
234 234 to = r.file(f).read(mmap1[f])
235 235 tn = None
236 236 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
237 237
238 238 def changelog(self, pos):
239 239 def changenav(**map):
240 240 def seq(factor = 1):
241 241 yield 1 * factor
242 242 yield 3 * factor
243 243 #yield 5 * factor
244 244 for f in seq(factor * 10):
245 245 yield f
246 246
247 247 l = []
248 248 for f in seq():
249 249 if f < self.maxchanges / 2: continue
250 250 if f > count: break
251 251 r = "%d" % f
252 252 if pos + f < count: l.append(("+" + r, pos + f))
253 253 if pos - f >= 0: l.insert(0, ("-" + r, pos - f))
254 254
255 255 yield {"rev": 0, "label": "(0)"}
256 256
257 257 for label, rev in l:
258 258 yield {"label": label, "rev": rev}
259 259
260 260 yield {"label": "tip", "rev": ""}
261 261
262 262 def changelist(**map):
263 263 parity = (start - end) & 1
264 264 cl = self.repo.changelog
265 265 l = [] # build a list in forward order for efficiency
266 266 for i in range(start, end):
267 267 n = cl.node(i)
268 268 changes = cl.read(n)
269 269 hn = hex(n)
270 270 t = float(changes[2].split(' ')[0])
271 271
272 272 l.insert(0, {
273 273 "parity": parity,
274 274 "author": changes[1],
275 275 "parent": self.parents("changelogparent",
276 276 cl.parents(n), cl.rev),
277 277 "changelogtag": self.showtag("changelogtag",n),
278 278 "manifest": hex(changes[0]),
279 279 "desc": changes[4],
280 280 "date": t,
281 281 "files": self.listfilediffs(changes[3], n),
282 282 "rev": i,
283 283 "node": hn})
284 284 parity = 1 - parity
285 285
286 286 for e in l: yield e
287 287
288 288 cl = self.repo.changelog
289 289 mf = cl.read(cl.tip())[0]
290 290 count = cl.count()
291 291 start = max(0, pos - self.maxchanges + 1)
292 292 end = min(count, start + self.maxchanges)
293 293 pos = end - 1
294 294
295 295 yield self.t('changelog',
296 296 changenav = changenav,
297 297 manifest = hex(mf),
298 298 rev = pos, changesets = count, entries = changelist)
299 299
300 300 def search(self, query):
301 301
302 302 def changelist(**map):
303 303 cl = self.repo.changelog
304 304 count = 0
305 305 qw = query.lower().split()
306 306
307 307 def revgen():
308 308 for i in range(cl.count() - 1, 0, -100):
309 309 l = []
310 310 for j in range(max(0, i - 100), i):
311 311 n = cl.node(j)
312 312 changes = cl.read(n)
313 313 l.insert(0, (n, j, changes))
314 314 for e in l:
315 315 yield e
316 316
317 317 for n, i, changes in revgen():
318 318 miss = 0
319 319 for q in qw:
320 320 if not (q in changes[1].lower() or
321 321 q in changes[4].lower() or
322 322 q in " ".join(changes[3][:20]).lower()):
323 323 miss = 1
324 324 break
325 325 if miss: continue
326 326
327 327 count += 1
328 328 hn = hex(n)
329 329 t = float(changes[2].split(' ')[0])
330 330
331 331 yield self.t(
332 332 'searchentry',
333 333 parity = count & 1,
334 334 author = changes[1],
335 335 parent = self.parents("changelogparent",
336 336 cl.parents(n), cl.rev),
337 337 changelogtag = self.showtag("changelogtag",n),
338 338 manifest = hex(changes[0]),
339 339 desc = changes[4],
340 340 date = t,
341 341 files = self.listfilediffs(changes[3], n),
342 342 rev = i,
343 343 node = hn)
344 344
345 345 if count >= self.maxchanges: break
346 346
347 347 cl = self.repo.changelog
348 348 mf = cl.read(cl.tip())[0]
349 349
350 350 yield self.t('search',
351 351 query = query,
352 352 manifest = hex(mf),
353 353 entries = changelist)
354 354
355 355 def changeset(self, nodeid):
356 356 n = bin(nodeid)
357 357 cl = self.repo.changelog
358 358 changes = cl.read(n)
359 359 p1 = cl.parents(n)[0]
360 360 t = float(changes[2].split(' ')[0])
361 361
362 362 files = []
363 363 mf = self.repo.manifest.read(changes[0])
364 364 for f in changes[3]:
365 365 files.append(self.t("filenodelink",
366 366 filenode = hex(mf.get(f, nullid)), file = f))
367 367
368 368 def diff(**map):
369 369 yield self.diff(p1, n, None)
370 370
371 371 yield self.t('changeset',
372 372 diff = diff,
373 373 rev = cl.rev(n),
374 374 node = nodeid,
375 375 parent = self.parents("changesetparent",
376 376 cl.parents(n), cl.rev),
377 377 changesettag = self.showtag("changesettag",n),
378 378 manifest = hex(changes[0]),
379 379 author = changes[1],
380 380 desc = changes[4],
381 381 date = t,
382 382 files = files)
383 383
384 384 def filelog(self, f, filenode):
385 385 cl = self.repo.changelog
386 386 fl = self.repo.file(f)
387 387 count = fl.count()
388 388
389 389 def entries(**map):
390 390 l = []
391 391 parity = (count - 1) & 1
392 392
393 393 for i in range(count):
394 394
395 395 n = fl.node(i)
396 396 lr = fl.linkrev(n)
397 397 cn = cl.node(lr)
398 398 cs = cl.read(cl.node(lr))
399 399 t = float(cs[2].split(' ')[0])
400 400
401 401 l.insert(0, {"parity": parity,
402 402 "filenode": hex(n),
403 403 "filerev": i,
404 404 "file": f,
405 405 "node": hex(cn),
406 406 "author": cs[1],
407 407 "date": t,
408 408 "parent": self.parents("filelogparent",
409 409 fl.parents(n), fl.rev, file=f),
410 410 "desc": cs[4]})
411 411 parity = 1 - parity
412 412
413 413 for e in l: yield e
414 414
415 415 yield self.t("filelog",
416 416 file = f,
417 417 filenode = filenode,
418 418 entries = entries)
419 419
420 420 def filerevision(self, f, node):
421 421 fl = self.repo.file(f)
422 422 n = bin(node)
423 423 text = fl.read(n)
424 424 changerev = fl.linkrev(n)
425 425 cl = self.repo.changelog
426 426 cn = cl.node(changerev)
427 427 cs = cl.read(cn)
428 428 t = float(cs[2].split(' ')[0])
429 429 mfn = cs[0]
430 430
431 431 def lines():
432 432 for l, t in enumerate(text.splitlines(1)):
433 433 yield {"line": t,
434 434 "linenumber": "% 6d" % (l + 1),
435 435 "parity": l & 1}
436 436
437 437 yield self.t("filerevision", file = f,
438 438 filenode = node,
439 439 path = up(f),
440 440 text = lines(),
441 441 rev = changerev,
442 442 node = hex(cn),
443 443 manifest = hex(mfn),
444 444 author = cs[1],
445 445 date = t,
446 446 parent = self.parents("filerevparent",
447 447 fl.parents(n), fl.rev, file=f),
448 448 permissions = self.repo.manifest.readflags(mfn)[f])
449 449
450 450 def fileannotate(self, f, node):
451 451 bcache = {}
452 452 ncache = {}
453 453 fl = self.repo.file(f)
454 454 n = bin(node)
455 455 changerev = fl.linkrev(n)
456 456
457 457 cl = self.repo.changelog
458 458 cn = cl.node(changerev)
459 459 cs = cl.read(cn)
460 460 t = float(cs[2].split(' ')[0])
461 461 mfn = cs[0]
462 462
463 463 def annotate(**map):
464 464 parity = 1
465 465 last = None
466 466 for r, l in fl.annotate(n):
467 467 try:
468 468 cnode = ncache[r]
469 469 except KeyError:
470 470 cnode = ncache[r] = self.repo.changelog.node(r)
471 471
472 472 try:
473 473 name = bcache[r]
474 474 except KeyError:
475 475 cl = self.repo.changelog.read(cnode)
476 476 name = cl[1]
477 477 f = name.find('@')
478 478 if f >= 0:
479 479 name = name[:f]
480 480 f = name.find('<')
481 481 if f >= 0:
482 482 name = name[f+1:]
483 483 bcache[r] = name
484 484
485 485 if last != cnode:
486 486 parity = 1 - parity
487 487 last = cnode
488 488
489 489 yield {"parity": parity,
490 490 "node": hex(cnode),
491 491 "rev": r,
492 492 "author": name,
493 493 "file": f,
494 494 "line": l}
495 495
496 496 yield self.t("fileannotate",
497 497 file = f,
498 498 filenode = node,
499 499 annotate = annotate,
500 500 path = up(f),
501 501 rev = changerev,
502 502 node = hex(cn),
503 503 manifest = hex(mfn),
504 504 author = cs[1],
505 505 date = t,
506 506 parent = self.parents("fileannotateparent",
507 507 fl.parents(n), fl.rev, file=f),
508 508 permissions = self.repo.manifest.readflags(mfn)[f])
509 509
510 510 def manifest(self, mnode, path):
511 511 mf = self.repo.manifest.read(bin(mnode))
512 512 rev = self.repo.manifest.rev(bin(mnode))
513 513 node = self.repo.changelog.node(rev)
514 514 mff=self.repo.manifest.readflags(bin(mnode))
515 515
516 516 files = {}
517 517
518 518 p = path[1:]
519 519 l = len(p)
520 520
521 521 for f,n in mf.items():
522 522 if f[:l] != p:
523 523 continue
524 524 remain = f[l:]
525 525 if "/" in remain:
526 526 short = remain[:remain.find("/") + 1] # bleah
527 527 files[short] = (f, None)
528 528 else:
529 529 short = os.path.basename(remain)
530 530 files[short] = (f, n)
531 531
532 532 def filelist(**map):
533 533 parity = 0
534 534 fl = files.keys()
535 535 fl.sort()
536 536 for f in fl:
537 537 full, fnode = files[f]
538 if not fnode:
539 continue
540
541 yield {"file": full,
542 "manifest": mnode,
543 "filenode": hex(fnode),
544 "parity": parity,
545 "basename": f,
546 "permissions": mff[full]}
547 parity = 1 - parity
548
549 def dirlist(**map):
550 parity = 0
551 fl = files.keys()
552 fl.sort()
553 for f in fl:
554 full, fnode = files[f]
538 555 if fnode:
539 yield self.t("manifestfileentry",
540 file = full,
541 manifest = mnode,
542 filenode = hex(fnode),
543 parity = parity,
544 basename = f,
545 permissions = mff[full])
546 else:
547 yield self.t("manifestdirentry",
548 parity = parity,
549 path = os.path.join(path, f),
550 manifest = mnode, basename = f[:-1])
556 continue
557
558 yield {"parity": parity,
559 "path": os.path.join(path, f),
560 "manifest": mnode,
561 "basename": f[:-1]}
551 562 parity = 1 - parity
552 563
553 564 yield self.t("manifest",
554 565 manifest = mnode,
555 566 rev = rev,
556 567 node = hex(node),
557 568 path = path,
558 569 up = up(path),
559 entries = filelist)
570 fentries = filelist,
571 dentries = dirlist)
560 572
561 573 def tags(self):
562 574 cl = self.repo.changelog
563 575 mf = cl.read(cl.tip())[0]
564 576
565 577 i = self.repo.tagslist()
566 578 i.reverse()
567 579
568 580 def entries(**map):
569 581 parity = 0
570 582 for k,n in i:
571 583 yield {"parity": parity,
572 584 "tag": k,
573 585 "node": hex(n)}
574 586 parity = 1 - parity
575 587
576 588 yield self.t("tags",
577 589 manifest = hex(mf),
578 590 entries = entries)
579 591
580 592 def filediff(self, file, changeset):
581 593 n = bin(changeset)
582 594 cl = self.repo.changelog
583 595 p1 = cl.parents(n)[0]
584 596 cs = cl.read(n)
585 597 mf = self.repo.manifest.read(cs[0])
586 598
587 599 def diff(**map):
588 600 yield self.diff(p1, n, file)
589 601
590 602 yield self.t("filediff",
591 603 file = file,
592 604 filenode = hex(mf.get(file, nullid)),
593 605 node = changeset,
594 606 rev = self.repo.changelog.rev(n),
595 607 parent = self.parents("filediffparent",
596 608 cl.parents(n), cl.rev),
597 609 diff = diff)
598 610
599 611 # add tags to things
600 612 # tags -> list of changesets corresponding to tags
601 613 # find tag, changeset, file
602 614
603 615 def run(self):
604 616 def header(**map):
605 617 yield self.t("header", **map)
606 618
607 619 def footer(**map):
608 620 yield self.t("footer", **map)
609 621
610 622 self.refresh()
611 623 args = cgi.parse()
612 624
613 625 t = self.templates or self.repo.ui.config("web", "templates",
614 626 templatepath())
615 627 m = os.path.join(t, "map")
616 628 if args.has_key('style'):
617 629 b = os.path.basename("map-" + args['style'][0])
618 630 p = os.path.join(self.templates, b)
619 631 if os.path.isfile(p): m = p
620 632
621 633 port = os.environ["SERVER_PORT"]
622 634 port = port != "80" and (":" + port) or ""
623 635 uri = os.environ["REQUEST_URI"]
624 636 if "?" in uri: uri = uri.split("?")[0]
625 637 url = "http://%s%s%s" % (os.environ["SERVER_NAME"], port, uri)
626 638
627 639 name = self.reponame or self.repo.ui.config("web", "name", os.getcwd())
628 640
629 641 self.t = templater(m, self.filters,
630 642 {"url":url,
631 643 "repo":name,
632 644 "header":header,
633 645 "footer":footer,
634 646 })
635 647
636 648 if not args.has_key('cmd'):
637 649 args['cmd'] = [self.t.cache['default'],]
638 650
639 651 if args['cmd'][0] == 'changelog':
640 652 c = self.repo.changelog.count() - 1
641 653 hi = c
642 654 if args.has_key('rev'):
643 655 hi = args['rev'][0]
644 656 try:
645 657 hi = self.repo.changelog.rev(self.repo.lookup(hi))
646 658 except RepoError:
647 659 write(self.search(hi))
648 660 return
649 661
650 662 write(self.changelog(hi))
651 663
652 664 elif args['cmd'][0] == 'changeset':
653 665 write(self.changeset(args['node'][0]))
654 666
655 667 elif args['cmd'][0] == 'manifest':
656 668 write(self.manifest(args['manifest'][0], args['path'][0]))
657 669
658 670 elif args['cmd'][0] == 'tags':
659 671 write(self.tags())
660 672
661 673 elif args['cmd'][0] == 'filediff':
662 674 write(self.filediff(args['file'][0], args['node'][0]))
663 675
664 676 elif args['cmd'][0] == 'file':
665 677 write(self.filerevision(args['file'][0], args['filenode'][0]))
666 678
667 679 elif args['cmd'][0] == 'annotate':
668 680 write(self.fileannotate(args['file'][0], args['filenode'][0]))
669 681
670 682 elif args['cmd'][0] == 'filelog':
671 683 write(self.filelog(args['file'][0], args['filenode'][0]))
672 684
673 685 elif args['cmd'][0] == 'heads':
674 686 httphdr("application/mercurial-0.1")
675 687 h = self.repo.heads()
676 688 sys.stdout.write(" ".join(map(hex, h)) + "\n")
677 689
678 690 elif args['cmd'][0] == 'branches':
679 691 httphdr("application/mercurial-0.1")
680 692 nodes = []
681 693 if args.has_key('nodes'):
682 694 nodes = map(bin, args['nodes'][0].split(" "))
683 695 for b in self.repo.branches(nodes):
684 696 sys.stdout.write(" ".join(map(hex, b)) + "\n")
685 697
686 698 elif args['cmd'][0] == 'between':
687 699 httphdr("application/mercurial-0.1")
688 700 nodes = []
689 701 if args.has_key('pairs'):
690 702 pairs = [ map(bin, p.split("-"))
691 703 for p in args['pairs'][0].split(" ") ]
692 704 for b in self.repo.between(pairs):
693 705 sys.stdout.write(" ".join(map(hex, b)) + "\n")
694 706
695 707 elif args['cmd'][0] == 'changegroup':
696 708 httphdr("application/mercurial-0.1")
697 709 nodes = []
698 710 if self.viewonly:
699 711 return
700 712
701 713 if args.has_key('roots'):
702 714 nodes = map(bin, args['roots'][0].split(" "))
703 715
704 716 z = zlib.compressobj()
705 717 f = self.repo.changegroup(nodes)
706 718 while 1:
707 719 chunk = f.read(4096)
708 720 if not chunk: break
709 721 sys.stdout.write(z.compress(chunk))
710 722
711 723 sys.stdout.write(z.flush())
712 724
713 725 else:
714 726 write(self.t("error"))
715 727
716 728 def create_server(path, name, templates, address, port, use_ipv6 = False,
717 729 accesslog = sys.stdout, errorlog = sys.stderr):
718 730
719 731 def openlog(opt, default):
720 732 if opt and opt != '-':
721 733 return open(opt, 'w')
722 734 return default
723 735
724 736 u = ui()
725 737 repo = repository(u, path)
726 738 if not address:
727 739 address = u.config("web", "address", "")
728 740 if not port:
729 741 print port
730 742 port = int(u.config("web", "port", 8000))
731 743 if not use_ipv6:
732 744 use_ipv6 = u.configbool("web", "ipv6")
733 745
734 746 accesslog = openlog(accesslog or u.config("web", "accesslog", "-"),
735 747 sys.stdout)
736 748 errorlog = openlog(errorlog or u.config("web", "errorlog", "-"),
737 749 sys.stderr)
738 750
739 751 import BaseHTTPServer
740 752
741 753 class IPv6HTTPServer(BaseHTTPServer.HTTPServer):
742 754 address_family = getattr(socket, 'AF_INET6', None)
743 755
744 756 def __init__(self, *args, **kwargs):
745 757 if self.address_family is None:
746 758 raise RepoError('IPv6 not available on this system')
747 759 BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs)
748 760
749 761 class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler):
750 762 def log_error(self, format, *args):
751 763 errorlog.write("%s - - [%s] %s\n" % (self.address_string(),
752 764 self.log_date_time_string(),
753 765 format % args))
754 766
755 767 def log_message(self, format, *args):
756 768 accesslog.write("%s - - [%s] %s\n" % (self.address_string(),
757 769 self.log_date_time_string(),
758 770 format % args))
759 771
760 772 def do_POST(self):
761 773 try:
762 774 self.do_hgweb()
763 775 except socket.error, inst:
764 776 if inst.args[0] != 32: raise
765 777
766 778 def do_GET(self):
767 779 self.do_POST()
768 780
769 781 def do_hgweb(self):
770 782 query = ""
771 783 p = self.path.find("?")
772 784 if p:
773 785 query = self.path[p + 1:]
774 786 query = query.replace('+', ' ')
775 787
776 788 env = {}
777 789 env['GATEWAY_INTERFACE'] = 'CGI/1.1'
778 790 env['REQUEST_METHOD'] = self.command
779 791 env['SERVER_NAME'] = self.server.server_name
780 792 env['SERVER_PORT'] = str(self.server.server_port)
781 793 env['REQUEST_URI'] = "/"
782 794 if query:
783 795 env['QUERY_STRING'] = query
784 796 host = self.address_string()
785 797 if host != self.client_address[0]:
786 798 env['REMOTE_HOST'] = host
787 799 env['REMOTE_ADDR'] = self.client_address[0]
788 800
789 801 if self.headers.typeheader is None:
790 802 env['CONTENT_TYPE'] = self.headers.type
791 803 else:
792 804 env['CONTENT_TYPE'] = self.headers.typeheader
793 805 length = self.headers.getheader('content-length')
794 806 if length:
795 807 env['CONTENT_LENGTH'] = length
796 808 accept = []
797 809 for line in self.headers.getallmatchingheaders('accept'):
798 810 if line[:1] in "\t\n\r ":
799 811 accept.append(line.strip())
800 812 else:
801 813 accept = accept + line[7:].split(',')
802 814 env['HTTP_ACCEPT'] = ','.join(accept)
803 815
804 816 os.environ.update(env)
805 817
806 818 save = sys.argv, sys.stdin, sys.stdout, sys.stderr
807 819 try:
808 820 sys.stdin = self.rfile
809 821 sys.stdout = self.wfile
810 822 sys.argv = ["hgweb.py"]
811 823 if '=' not in query:
812 824 sys.argv.append(query)
813 825 self.send_response(200, "Script output follows")
814 826 hg.run()
815 827 finally:
816 828 sys.argv, sys.stdin, sys.stdout, sys.stderr = save
817 829
818 830 hg = hgweb(path, name, templates)
819 831 if use_ipv6:
820 832 return IPv6HTTPServer((address, port), hgwebhandler)
821 833 else:
822 834 return BaseHTTPServer.HTTPServer((address, port), hgwebhandler)
823 835
824 836 def server(path, name, templates, address, port, use_ipv6 = False,
825 837 accesslog = sys.stdout, errorlog = sys.stderr):
826 838 httpd = create_server(path, name, templates, address, port, use_ipv6,
827 839 accesslog, errorlog)
828 840 httpd.serve_forever()
@@ -1,20 +1,21
1 1 #header#
2 2 <title>#repo|escape#: manifest #manifest|short#</title>
3 3 </head>
4 4 <body>
5 5
6 6 <div class="buttons">
7 7 <a href="?cmd=changelog;rev=#rev#">changelog</a>
8 8 <a href="?cmd=tags">tags</a>
9 9 <a href="?cmd=changeset;node=#node#">changeset</a>
10 10 </div>
11 11
12 12 <h2>manifest #manifest|short#: #path#</h2>
13 13
14 14 <table cellpadding="0" cellspacing="0">
15 15 <tr class="parity1">
16 16 <td><tt>drwxr-xr-x</tt>&nbsp;
17 17 <td><a href="?cmd=manifest;manifest=#manifest#;path=#up#">[up]</a>
18 #entries#
18 #dentries%manifestdirentry#
19 #fentries%manifestfileentry#
19 20 </table>
20 21 #footer#
General Comments 0
You need to be logged in to leave comments. Login now