7 |
7 |
8 from demandload import demandload |
8 from demandload import demandload |
9 from node import * |
9 from node import * |
10 from i18n import gettext as _ |
10 from i18n import gettext as _ |
11 demandload(globals(), "os re sys signal imp urllib pdb shlex") |
11 demandload(globals(), "os re sys signal imp urllib pdb shlex") |
12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") |
12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo") |
13 demandload(globals(), "difflib patch tempfile time") |
13 demandload(globals(), "difflib patch tempfile time") |
14 demandload(globals(), "traceback errno version atexit bz2") |
14 demandload(globals(), "traceback errno version atexit bz2") |
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver") |
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver") |
16 |
16 |
17 class UnknownCommand(Exception): |
17 class UnknownCommand(Exception): |
293 if fh is not None: |
293 if fh is not None: |
294 fh.close() |
294 fh.close() |
295 if cleanup is not None: |
295 if cleanup is not None: |
296 os.unlink(cleanup) |
296 os.unlink(cleanup) |
297 |
297 |
298 class changeset_printer(object): |
|
299 '''show changeset information when templating not requested.''' |
|
300 |
|
301 def __init__(self, ui, repo): |
|
302 self.ui = ui |
|
303 self.repo = repo |
|
304 |
|
305 def show(self, rev=0, changenode=None, brinfo=None, copies=None): |
|
306 '''show a single changeset or file revision''' |
|
307 log = self.repo.changelog |
|
308 if changenode is None: |
|
309 changenode = log.node(rev) |
|
310 elif not rev: |
|
311 rev = log.rev(changenode) |
|
312 |
|
313 if self.ui.quiet: |
|
314 self.ui.write("%d:%s\n" % (rev, short(changenode))) |
|
315 return |
|
316 |
|
317 changes = log.read(changenode) |
|
318 date = util.datestr(changes[2]) |
|
319 extra = changes[5] |
|
320 branch = extra.get("branch") |
|
321 |
|
322 hexfunc = self.ui.debugflag and hex or short |
|
323 |
|
324 parents = log.parentrevs(rev) |
|
325 if not self.ui.debugflag: |
|
326 if parents[1] == nullrev: |
|
327 if parents[0] >= rev - 1: |
|
328 parents = [] |
|
329 else: |
|
330 parents = [parents[0]] |
|
331 parents = [(p, hexfunc(log.node(p))) for p in parents] |
|
332 |
|
333 self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode))) |
|
334 |
|
335 if branch: |
|
336 self.ui.write(_("branch: %s\n") % branch) |
|
337 for tag in self.repo.nodetags(changenode): |
|
338 self.ui.write(_("tag: %s\n") % tag) |
|
339 for parent in parents: |
|
340 self.ui.write(_("parent: %d:%s\n") % parent) |
|
341 |
|
342 if brinfo and changenode in brinfo: |
|
343 br = brinfo[changenode] |
|
344 self.ui.write(_("branch: %s\n") % " ".join(br)) |
|
345 |
|
346 if self.ui.debugflag: |
|
347 self.ui.write(_("manifest: %d:%s\n") % |
|
348 (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
|
349 self.ui.write(_("user: %s\n") % changes[1]) |
|
350 self.ui.write(_("date: %s\n") % date) |
|
351 |
|
352 if self.ui.debugflag: |
|
353 files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
|
354 for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
355 files): |
|
356 if value: |
|
357 self.ui.write("%-12s %s\n" % (key, " ".join(value))) |
|
358 elif changes[3] and self.ui.verbose: |
|
359 self.ui.write(_("files: %s\n") % " ".join(changes[3])) |
|
360 if copies and self.ui.verbose: |
|
361 copies = ['%s (%s)' % c for c in copies] |
|
362 self.ui.write(_("copies: %s\n") % ' '.join(copies)) |
|
363 |
|
364 if extra and self.ui.debugflag: |
|
365 extraitems = extra.items() |
|
366 extraitems.sort() |
|
367 for key, value in extraitems: |
|
368 self.ui.write(_("extra: %s=%s\n") |
|
369 % (key, value.encode('string_escape'))) |
|
370 |
|
371 description = changes[4].strip() |
|
372 if description: |
|
373 if self.ui.verbose: |
|
374 self.ui.write(_("description:\n")) |
|
375 self.ui.write(description) |
|
376 self.ui.write("\n\n") |
|
377 else: |
|
378 self.ui.write(_("summary: %s\n") % |
|
379 description.splitlines()[0]) |
|
380 self.ui.write("\n") |
|
381 |
|
382 def show_changeset(ui, repo, opts): |
|
383 """show one changeset using template or regular display. |
|
384 |
|
385 Display format will be the first non-empty hit of: |
|
386 1. option 'template' |
|
387 2. option 'style' |
|
388 3. [ui] setting 'logtemplate' |
|
389 4. [ui] setting 'style' |
|
390 If all of these values are either the unset or the empty string, |
|
391 regular display via changeset_printer() is done. |
|
392 """ |
|
393 # options |
|
394 tmpl = opts.get('template') |
|
395 mapfile = None |
|
396 if tmpl: |
|
397 tmpl = templater.parsestring(tmpl, quoted=False) |
|
398 else: |
|
399 mapfile = opts.get('style') |
|
400 # ui settings |
|
401 if not mapfile: |
|
402 tmpl = ui.config('ui', 'logtemplate') |
|
403 if tmpl: |
|
404 tmpl = templater.parsestring(tmpl) |
|
405 else: |
|
406 mapfile = ui.config('ui', 'style') |
|
407 |
|
408 if tmpl or mapfile: |
|
409 if mapfile: |
|
410 if not os.path.split(mapfile)[0]: |
|
411 mapname = (templater.templatepath('map-cmdline.' + mapfile) |
|
412 or templater.templatepath(mapfile)) |
|
413 if mapname: mapfile = mapname |
|
414 try: |
|
415 t = templater.changeset_templater(ui, repo, mapfile) |
|
416 except SyntaxError, inst: |
|
417 raise util.Abort(inst.args[0]) |
|
418 if tmpl: t.use_template(tmpl) |
|
419 return t |
|
420 return changeset_printer(ui, repo) |
|
421 |
|
422 def setremoteconfig(ui, opts): |
298 def setremoteconfig(ui, opts): |
423 "copy remote options to ui tree" |
299 "copy remote options to ui tree" |
424 if opts.get('ssh'): |
300 if opts.get('ssh'): |
425 ui.setconfig("ui", "ssh", opts['ssh']) |
301 ui.setconfig("ui", "ssh", opts['ssh']) |
426 if opts.get('remotecmd'): |
302 if opts.get('remotecmd'): |
2681 br = None |
2557 br = None |
2682 if opts['branches']: |
2558 if opts['branches']: |
2683 ui.warn(_("the --branches option is deprecated, " |
2559 ui.warn(_("the --branches option is deprecated, " |
2684 "please use 'hg branches' instead\n")) |
2560 "please use 'hg branches' instead\n")) |
2685 br = repo.branchlookup([n]) |
2561 br = repo.branchlookup([n]) |
2686 show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
2562 cmdutil.show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
2687 if opts['patch']: |
2563 if opts['patch']: |
2688 patch.diff(repo, repo.changelog.parents(n)[0], n) |
2564 patch.diff(repo, repo.changelog.parents(n)[0], n) |
2689 |
2565 |
2690 def unbundle(ui, repo, fname, **opts): |
2566 def unbundle(ui, repo, fname, **opts): |
2691 """apply a changegroup file |
2567 """apply a changegroup file |