Print this page
5025 import and use mandoc
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Albert Lee <trisk@nexenta.com>
Approved by: TBD
   1 #
   2 #  This program is free software; you can redistribute it and/or modify
   3 #  it under the terms of the GNU General Public License version 2
   4 #  as published by the Free Software Foundation.
   5 #
   6 #  This program is distributed in the hope that it will be useful,
   7 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
   8 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   9 #  GNU General Public License for more details.
  10 #
  11 #  You should have received a copy of the GNU General Public License
  12 #  along with this program; if not, write to the Free Software
  13 #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14 #
  15 
  16 #
  17 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  18 # Copyright 2008, 2011 Richard Lowe

  19 #
  20 
  21 '''OpenSolaris extensions to Mercurial
  22 
  23     This extension contains a number of commands to help you work with
  24 the OpenSolaris consolidations.  It provides commands to check your
  25 changes against the various style rules used for OpenSolaris, to
  26 backup and restore your changes, to generate code reviews, and to
  27 prepare your changes for integration.
  28 
  29 
  30 The Parent
  31 
  32     To provide a uniform notion of parent workspace regardless of
  33 filesystem-based access, Cadmium uses the highest numbered changeset
  34 on the current branch that is also in the parent workspace to
  35 represent the parent workspace.
  36 
  37 
  38 The Active List


  87 #
  88 # Add the relative path from cdm.py to usr/src/tools to the load path,
  89 # such that a cdm.py loaded from the source tree uses the modules also
  90 # within the source tree.
  91 #
  92 sys.path.insert(2, os.path.join(os.path.dirname(__file__), "..", ".."))
  93 
  94 from onbld.Scm import Version
  95 from mercurial import util
  96 
  97 try:
  98     Version.check_version()
  99 except Version.VersionMismatch, badversion:
 100     raise util.Abort("Version Mismatch:\n %s\n" % badversion)
 101 
 102 from mercurial import cmdutil, ignore, node, patch
 103 
 104 from onbld.Scm.WorkSpace import WorkSpace, WorkList
 105 from onbld.Scm.Backup import CdmBackup
 106 from onbld.Checks import Cddl, Comments, Copyright, CStyle, HdrChk
 107 from onbld.Checks import JStyle, Keywords, Mapfile
 108 
 109 
 110 def yes_no(ui, msg, default):
 111     if default:
 112         prompt = ' [Y/n]:'
 113         defanswer = 'y'
 114     else:
 115         prompt = ' [y/N]:'
 116         defanswer = 'n'
 117 
 118     if Version.at_least("1.4"):
 119         index = ui.promptchoice(msg + prompt, ['&yes', '&no'],
 120                                 default=['y', 'n'].index(defanswer))
 121         resp = ('y', 'n')[index]
 122     else:
 123         resp = ui.prompt(msg + prompt, ['&yes', '&no'], default=defanswer)
 124 
 125     return resp[0] in ('Y', 'y')
 126 
 127 


 373 
 374     ui.write('CDDL block check:\n')
 375 
 376     for f, e in filelist:
 377         if e and e.is_removed():
 378             continue
 379         elif (e or opts.get('honour_nots')) and exclude(f):
 380             ui.status('Skipping %s...\n' % f)
 381             continue
 382         elif e and e.is_added():
 383             lenient = False
 384         else:
 385             lenient = True
 386 
 387         fh = open(f, 'r')
 388         ret |= Cddl.cddlchk(fh, lenient=lenient, output=ui)
 389         fh.close()
 390     return ret
 391 
 392 


































 393 def cdm_mapfilechk(ui, repo, *args, **opts):
 394     '''check for a valid mapfile header block in active files
 395 
 396     Check that all link-editor mapfiles contain the standard mapfile
 397     header comment directing the reader to the document containing
 398     Solaris object versioning rules (README.mapfile).
 399 
 400     Files can be excluded from this check using the mapfilechk.NOT
 401     file.  See NOT Files in the extension documentation ('hg help
 402     cdm').
 403     '''
 404 
 405     filelist = buildfilelist(wslist[repo], opts.get('parent'), args)
 406     exclude = not_check(repo, 'mapfilechk')
 407     ret = 0
 408 
 409     # We are interested in examining any file that has the following
 410     # in its final path segment:
 411     #    - Contains the word 'mapfile'
 412     #    - Begins with 'map.'


 777 
 778             ret |= result
 779 
 780             if not ws.ui.quiet or result != 0:
 781                 ws.ui.write(output, '\n')
 782     return ret
 783 
 784 
 785 def cdm_nits(ui, repo, *args, **opts):
 786     '''check for stylistic nits in active files
 787 
 788     Check each active file for basic stylistic errors.
 789 
 790     The following checks are run over each active file (see 'hg help
 791     <check>' for more information about each):
 792 
 793       - copyright  (copyright statements)
 794       - cstyle     (C source style)
 795       - hdrchk     (C header style)
 796       - jstyle     (java source style)

 797       - mapfilechk (link-editor mapfiles)
 798       - permchk    (file permissions)
 799       - keywords   (SCCS keywords)
 800 
 801     With the global -q/--quiet option, only provide output for those
 802     checks which fail.
 803     '''
 804 
 805     cmds = [cdm_copyright,
 806         cdm_cstyle,
 807         cdm_hdrchk,
 808         cdm_jstyle,

 809         cdm_mapfilechk,
 810         cdm_permchk,
 811         cdm_keywords]
 812 
 813     return run_checks(wslist[repo], cmds, *args, **opts)
 814 
 815 
 816 def cdm_pbchk(ui, repo, **opts):
 817     '''run pre-integration checks on this workspace
 818 
 819     Check this workspace for common errors prior to integration.
 820 
 821     The following checks are run over the active list (see 'hg help
 822     <check>' for more information about each):
 823 
 824       - branchchk  (addition/modification of branches)
 825       - comchk     (changeset descriptions)
 826       - copyright  (copyright statements)
 827       - cstyle     (C source style)
 828       - hdrchk     (C header style)
 829       - jstyle     (java source style)
 830       - keywords   (SCCS keywords)

 831       - mapfilechk (link-editor mapfiles)
 832       - permchk    (file permissions)
 833       - tagchk     (addition/modification of tags)
 834 
 835     Additionally, the workspace is checked for outgoing merges (which
 836     should be removed with 'hg recommit'), and uncommitted changes.
 837 
 838     With the global -q/--quiet option, only provide output for those
 839     checks which fail.
 840     '''
 841 
 842     #
 843     # The current ordering of these is that the commands from cdm_nits
 844     # run first in the same order as they would in cdm_nits, then the
 845     # pbchk specifics are run.
 846     #
 847     cmds = [cdm_copyright,
 848         cdm_cstyle,
 849         cdm_hdrchk,
 850         cdm_jstyle,

 851         cdm_mapfilechk,
 852         cdm_permchk,
 853         cdm_keywords,
 854         cdm_comchk,
 855         cdm_tagchk,
 856         cdm_branchchk,
 857         cdm_outchk,
 858         cdm_mergechk]
 859 
 860     return run_checks(wslist[repo], cmds, **opts)
 861 
 862 
 863 def cdm_recommit(ui, repo, **opts):
 864     '''replace outgoing changesets with a single equivalent changeset
 865 
 866     Replace all outgoing changesets with a single changeset containing
 867     equivalent changes.  This removes uninteresting changesets created
 868     during development that would only serve as noise in the gate.
 869 
 870     Any changed file that is now identical in content to that in the


1414     'copyright': (cdm_copyright, [('p', 'parent', '', 'parent workspace')],
1415                   'hg copyright [-p PARENT]'),
1416     'cstyle': (cdm_cstyle, [('p', 'parent', '', 'parent workspace')],
1417                'hg cstyle [-p PARENT]'),
1418     'debugcdmal': (cdm_debugcdmal, [('p', 'parent', '', 'parent workspace')],
1419                    'hg debugcdmal [-p PARENT] [FILE...]'),
1420     'eval': (cdm_eval, [('p', 'parent', '', 'parent workspace'),
1421                         ('r', 'remain', None, 'do not change directory')],
1422              'hg eval [-p PARENT] [-r] command...'),
1423     'hdrchk': (cdm_hdrchk, [('p', 'parent', '', 'parent workspace')],
1424                'hg hdrchk [-p PARENT]'),
1425     'jstyle': (cdm_jstyle, [('p', 'parent', '', 'parent workspace')],
1426                'hg jstyle [-p PARENT]'),
1427     'keywords': (cdm_keywords, [('p', 'parent', '', 'parent workspace')],
1428                  'hg keywords [-p PARENT]'),
1429     '^list|active': (cdm_list, [('p', 'parent', '', 'parent workspace'),
1430                                 ('a', 'added', None, 'show added files'),
1431                                 ('m', 'modified', None, 'show modified files'),
1432                                 ('r', 'removed', None, 'show removed files')],
1433                     'hg list [-amrRu] [-p PARENT]'),


1434     'mapfilechk': (cdm_mapfilechk, [('p', 'parent', '', 'parent workspace')],
1435                 'hg mapfilechk [-p PARENT]'),
1436     '^nits': (cdm_nits, [('p', 'parent', '', 'parent workspace')],
1437              'hg nits [-p PARENT]'),
1438     '^pbchk': (cdm_pbchk, [('p', 'parent', '', 'parent workspace'),
1439                            ('N', 'nocheck', None, 'skip database checks')],
1440               'hg pbchk [-N] [-p PARENT]'),
1441     'permchk': (cdm_permchk, [('p', 'parent', '', 'parent workspace')],
1442                 'hg permchk [-p PARENT]'),
1443     '^pdiffs': (cdm_pdiffs, [('p', 'parent', '', 'parent workspace'),
1444                              ('a', 'text', None, 'treat all files as text'),
1445                              ('g', 'git', None, 'use extended git diff format'),
1446                              ('w', 'ignore-all-space', None,
1447                               'ignore white space when comparing lines'),
1448                              ('b', 'ignore-space-change', None,
1449                               'ignore changes in the amount of white space'),
1450                              ('B', 'ignore-blank-lines', None,
1451                               'ignore changes whose lines are all blank'),
1452                              ('U', 'unified', 3,
1453                               'number of lines of context to show'),


   1 #
   2 #  This program is free software; you can redistribute it and/or modify
   3 #  it under the terms of the GNU General Public License version 2
   4 #  as published by the Free Software Foundation.
   5 #
   6 #  This program is distributed in the hope that it will be useful,
   7 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
   8 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   9 #  GNU General Public License for more details.
  10 #
  11 #  You should have received a copy of the GNU General Public License
  12 #  along with this program; if not, write to the Free Software
  13 #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14 #
  15 
  16 #
  17 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  18 # Copyright 2008, 2011 Richard Lowe
  19 # Copyright 2014 Garrett D'Amore <garrett@damore.org>
  20 #
  21 
  22 '''OpenSolaris extensions to Mercurial
  23 
  24     This extension contains a number of commands to help you work with
  25 the OpenSolaris consolidations.  It provides commands to check your
  26 changes against the various style rules used for OpenSolaris, to
  27 backup and restore your changes, to generate code reviews, and to
  28 prepare your changes for integration.
  29 
  30 
  31 The Parent
  32 
  33     To provide a uniform notion of parent workspace regardless of
  34 filesystem-based access, Cadmium uses the highest numbered changeset
  35 on the current branch that is also in the parent workspace to
  36 represent the parent workspace.
  37 
  38 
  39 The Active List


  88 #
  89 # Add the relative path from cdm.py to usr/src/tools to the load path,
  90 # such that a cdm.py loaded from the source tree uses the modules also
  91 # within the source tree.
  92 #
  93 sys.path.insert(2, os.path.join(os.path.dirname(__file__), "..", ".."))
  94 
  95 from onbld.Scm import Version
  96 from mercurial import util
  97 
  98 try:
  99     Version.check_version()
 100 except Version.VersionMismatch, badversion:
 101     raise util.Abort("Version Mismatch:\n %s\n" % badversion)
 102 
 103 from mercurial import cmdutil, ignore, node, patch
 104 
 105 from onbld.Scm.WorkSpace import WorkSpace, WorkList
 106 from onbld.Scm.Backup import CdmBackup
 107 from onbld.Checks import Cddl, Comments, Copyright, CStyle, HdrChk
 108 from onbld.Checks import JStyle, Keywords, ManLint, Mapfile
 109 
 110 
 111 def yes_no(ui, msg, default):
 112     if default:
 113         prompt = ' [Y/n]:'
 114         defanswer = 'y'
 115     else:
 116         prompt = ' [y/N]:'
 117         defanswer = 'n'
 118 
 119     if Version.at_least("1.4"):
 120         index = ui.promptchoice(msg + prompt, ['&yes', '&no'],
 121                                 default=['y', 'n'].index(defanswer))
 122         resp = ('y', 'n')[index]
 123     else:
 124         resp = ui.prompt(msg + prompt, ['&yes', '&no'], default=defanswer)
 125 
 126     return resp[0] in ('Y', 'y')
 127 
 128 


 374 
 375     ui.write('CDDL block check:\n')
 376 
 377     for f, e in filelist:
 378         if e and e.is_removed():
 379             continue
 380         elif (e or opts.get('honour_nots')) and exclude(f):
 381             ui.status('Skipping %s...\n' % f)
 382             continue
 383         elif e and e.is_added():
 384             lenient = False
 385         else:
 386             lenient = True
 387 
 388         fh = open(f, 'r')
 389         ret |= Cddl.cddlchk(fh, lenient=lenient, output=ui)
 390         fh.close()
 391     return ret
 392 
 393 
 394 def cdm_manlintchk(ui, repo, *args, **opts):
 395     '''check for mandoc lint
 396 
 397     Check for man page formatting errors.
 398 
 399     Files can be excluded from this check using the manlint.NOT
 400     file.  See NOT Files in the extension documentation ('hg help
 401     cdm').
 402     '''
 403 
 404     filelist = buildfilelist(wslist[repo], opts.get('parent'), args)
 405     exclude = not_check(repo, 'manlint')
 406     ret = 0
 407 
 408     # Man pages are identified as having a suffix starting with a digit.
 409     ManfileRE = re.compile(r'.*\.[0-9][a-z]*$', re.IGNORECASE)
 410 
 411     ui.write('Man format check:\n')
 412 
 413     for f, e in filelist:
 414         if e and e.is_removed():
 415             continue
 416         elif (not ManfileRE.match(f)):
 417             continue
 418         elif (e or opts.get('honour_nots')) and exclude(f):
 419             ui.status('Skipping %s...\n' % f)
 420             continue
 421 
 422         fh = open(f, 'r')
 423         ret |= ManLint.manlint(fh, output=ui, picky=True)
 424         fh.close()
 425     return ret
 426 
 427 
 428 def cdm_mapfilechk(ui, repo, *args, **opts):
 429     '''check for a valid mapfile header block in active files
 430 
 431     Check that all link-editor mapfiles contain the standard mapfile
 432     header comment directing the reader to the document containing
 433     Solaris object versioning rules (README.mapfile).
 434 
 435     Files can be excluded from this check using the mapfilechk.NOT
 436     file.  See NOT Files in the extension documentation ('hg help
 437     cdm').
 438     '''
 439 
 440     filelist = buildfilelist(wslist[repo], opts.get('parent'), args)
 441     exclude = not_check(repo, 'mapfilechk')
 442     ret = 0
 443 
 444     # We are interested in examining any file that has the following
 445     # in its final path segment:
 446     #    - Contains the word 'mapfile'
 447     #    - Begins with 'map.'


 812 
 813             ret |= result
 814 
 815             if not ws.ui.quiet or result != 0:
 816                 ws.ui.write(output, '\n')
 817     return ret
 818 
 819 
 820 def cdm_nits(ui, repo, *args, **opts):
 821     '''check for stylistic nits in active files
 822 
 823     Check each active file for basic stylistic errors.
 824 
 825     The following checks are run over each active file (see 'hg help
 826     <check>' for more information about each):
 827 
 828       - copyright  (copyright statements)
 829       - cstyle     (C source style)
 830       - hdrchk     (C header style)
 831       - jstyle     (java source style)
 832       - manlint    (man page formatting)
 833       - mapfilechk (link-editor mapfiles)
 834       - permchk    (file permissions)
 835       - keywords   (SCCS keywords)
 836 
 837     With the global -q/--quiet option, only provide output for those
 838     checks which fail.
 839     '''
 840 
 841     cmds = [cdm_copyright,
 842         cdm_cstyle,
 843         cdm_hdrchk,
 844         cdm_jstyle,
 845         cmd_manlintchk,
 846         cdm_mapfilechk,
 847         cdm_permchk,
 848         cdm_keywords]
 849 
 850     return run_checks(wslist[repo], cmds, *args, **opts)
 851 
 852 
 853 def cdm_pbchk(ui, repo, **opts):
 854     '''run pre-integration checks on this workspace
 855 
 856     Check this workspace for common errors prior to integration.
 857 
 858     The following checks are run over the active list (see 'hg help
 859     <check>' for more information about each):
 860 
 861       - branchchk  (addition/modification of branches)
 862       - comchk     (changeset descriptions)
 863       - copyright  (copyright statements)
 864       - cstyle     (C source style)
 865       - hdrchk     (C header style)
 866       - jstyle     (java source style)
 867       - keywords   (SCCS keywords)
 868       - manlint    (man page formatting)
 869       - mapfilechk (link-editor mapfiles)
 870       - permchk    (file permissions)
 871       - tagchk     (addition/modification of tags)
 872 
 873     Additionally, the workspace is checked for outgoing merges (which
 874     should be removed with 'hg recommit'), and uncommitted changes.
 875 
 876     With the global -q/--quiet option, only provide output for those
 877     checks which fail.
 878     '''
 879 
 880     #
 881     # The current ordering of these is that the commands from cdm_nits
 882     # run first in the same order as they would in cdm_nits, then the
 883     # pbchk specifics are run.
 884     #
 885     cmds = [cdm_copyright,
 886         cdm_cstyle,
 887         cdm_hdrchk,
 888         cdm_jstyle,
 889         cdm_manlintchk,
 890         cdm_mapfilechk,
 891         cdm_permchk,
 892         cdm_keywords,
 893         cdm_comchk,
 894         cdm_tagchk,
 895         cdm_branchchk,
 896         cdm_outchk,
 897         cdm_mergechk]
 898 
 899     return run_checks(wslist[repo], cmds, **opts)
 900 
 901 
 902 def cdm_recommit(ui, repo, **opts):
 903     '''replace outgoing changesets with a single equivalent changeset
 904 
 905     Replace all outgoing changesets with a single changeset containing
 906     equivalent changes.  This removes uninteresting changesets created
 907     during development that would only serve as noise in the gate.
 908 
 909     Any changed file that is now identical in content to that in the


1453     'copyright': (cdm_copyright, [('p', 'parent', '', 'parent workspace')],
1454                   'hg copyright [-p PARENT]'),
1455     'cstyle': (cdm_cstyle, [('p', 'parent', '', 'parent workspace')],
1456                'hg cstyle [-p PARENT]'),
1457     'debugcdmal': (cdm_debugcdmal, [('p', 'parent', '', 'parent workspace')],
1458                    'hg debugcdmal [-p PARENT] [FILE...]'),
1459     'eval': (cdm_eval, [('p', 'parent', '', 'parent workspace'),
1460                         ('r', 'remain', None, 'do not change directory')],
1461              'hg eval [-p PARENT] [-r] command...'),
1462     'hdrchk': (cdm_hdrchk, [('p', 'parent', '', 'parent workspace')],
1463                'hg hdrchk [-p PARENT]'),
1464     'jstyle': (cdm_jstyle, [('p', 'parent', '', 'parent workspace')],
1465                'hg jstyle [-p PARENT]'),
1466     'keywords': (cdm_keywords, [('p', 'parent', '', 'parent workspace')],
1467                  'hg keywords [-p PARENT]'),
1468     '^list|active': (cdm_list, [('p', 'parent', '', 'parent workspace'),
1469                                 ('a', 'added', None, 'show added files'),
1470                                 ('m', 'modified', None, 'show modified files'),
1471                                 ('r', 'removed', None, 'show removed files')],
1472                     'hg list [-amrRu] [-p PARENT]'),
1473     'manlint': (cdm_manlintchk, [('p', 'parent', '', 'parent workspace')],
1474                 'hg manlint [-p PARENT]'),
1475     'mapfilechk': (cdm_mapfilechk, [('p', 'parent', '', 'parent workspace')],
1476                 'hg mapfilechk [-p PARENT]'),
1477     '^nits': (cdm_nits, [('p', 'parent', '', 'parent workspace')],
1478              'hg nits [-p PARENT]'),
1479     '^pbchk': (cdm_pbchk, [('p', 'parent', '', 'parent workspace'),
1480                            ('N', 'nocheck', None, 'skip database checks')],
1481               'hg pbchk [-N] [-p PARENT]'),
1482     'permchk': (cdm_permchk, [('p', 'parent', '', 'parent workspace')],
1483                 'hg permchk [-p PARENT]'),
1484     '^pdiffs': (cdm_pdiffs, [('p', 'parent', '', 'parent workspace'),
1485                              ('a', 'text', None, 'treat all files as text'),
1486                              ('g', 'git', None, 'use extended git diff format'),
1487                              ('w', 'ignore-all-space', None,
1488                               'ignore white space when comparing lines'),
1489                              ('b', 'ignore-space-change', None,
1490                               'ignore changes in the amount of white space'),
1491                              ('B', 'ignore-blank-lines', None,
1492                               'ignore changes whose lines are all blank'),
1493                              ('U', 'unified', 3,
1494                               'number of lines of context to show'),