Changeset 92

Show
Ignore:
Timestamp:
2009年08月23日 12时15分25秒 (2 years ago)
Author:
jiangx
Message:

Fixed #26: EolStyleCheck? plugin enhancement : in loose mode, svn:eol-style no need for unix files.

Location:
trunk/pysvnmanager/hooks
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/pysvnmanager/hooks/init/hook1.4/pre-commit

    r47 r92  
    7373if [ "$eol_style_check" = "yes" ]; then 
    7474    # New file must set svn:mime-type and svn:eol-style 
    75     $TOOLS_DIR/check-mime-type.py "$REPOS" "$TXN" || exit 1 
     75    $TOOLS_DIR/check-mime-type.py "$REPOS" "$TXN" $eol_style_check_force || exit 1 
    7676fi 
    7777 
  • trunk/pysvnmanager/hooks/init/hook1.4/scripts/check-mime-type.py

    r90 r92  
    2727MIN_LENGTH = 5 
    2828 
    29 def main(repos, txn): 
     29def main(repos, txn, force=""): 
    3030    """main entry point""" 
     31     
     32    if force == "no": 
     33        force = False  
     34    else: 
     35        force = True 
    3136 
    3237    files_added = [] 
     
    6267         
    6368        if check_mime: 
    64             if mime_type == "" and eol_style == '': 
    65                 errmsg.append( "%s : 属性 svn:mime-type 或者 svn:eol-style 没有设置" % path.decode('utf-8','replace').encode('utf-8','replace') ) 
    66             elif ptext.match(mime_type) and eol_style == '': 
    67                 errmsg.append( "%s : svn:mime-type=%s 但是 svn:eol-style 没有设置" % (path.decode('utf-8','replace').encode('utf-8','replace'), mime_type) ) 
     69            if mime_type == "" or ptext.match(mime_type): 
     70                if eol_style == '': 
     71                    ## check if crlf in file contents 
     72                    if not force: 
     73                        if crlf_in_file(txn, repos, path): 
     74                            errmsg.append( "CRLF (DOS style EOL) in file: %s" % path.decode('utf-8','replace').encode('utf-8','replace') ) 
     75                        else: 
     76                            continue 
     77                    if mime_type == "": 
     78                        errmsg.append( "%s : 属性 svn:mime-type 或者 svn:eol-style 没有设置" % path.decode('utf-8','replace').encode('utf-8','replace') ) 
     79                    else: 
     80                        errmsg.append( "%s : svn:mime-type=%s 但是 svn:eol-style 没有设置" % (path.decode('utf-8','replace').encode('utf-8','replace'), mime_type) ) 
    6881 
    6982    if len( errmsg ) > 0: 
    7083        die( errmsg ) 
    7184 
    72  
     85def crlf_in_file(txn, repos, path): 
     86    cmd = '%s cat -t "%s" "%s" "%s"' % (SVNLOOK, txn, repos, path) 
     87    buff = os.popen(cmd, 'r').read(1024) 
     88    if '\r' in buff: 
     89        return True 
     90    else: 
     91        return False 
     92  
    7393def die(msg): 
    7494    """ 
     
    106126        sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0])) 
    107127    else: 
    108         main(sys.argv[1], sys.argv[2]) 
     128        main(sys.argv[1], sys.argv[2], sys.argv[3:] and sys.argv[3] or '') 
  • trunk/pysvnmanager/hooks/init/hook1.5/pre-commit

    r47 r92  
    7373if [ "$eol_style_check" = "yes" ]; then 
    7474    # New file must set svn:mime-type and svn:eol-style 
    75     $TOOLS_DIR/check-mime-type.py "$REPOS" "$TXN" || exit 1 
     75    $TOOLS_DIR/check-mime-type.py "$REPOS" "$TXN" $eol_style_check_force || exit 1 
    7676fi 
    7777 
  • trunk/pysvnmanager/hooks/init/hook1.5/scripts/check-mime-type.py

    r90 r92  
    2727MIN_LENGTH = 5 
    2828 
    29 def main(repos, txn): 
     29def main(repos, txn, force=""): 
    3030    """main entry point""" 
     31     
     32    if force == "no": 
     33        force = False  
     34    else: 
     35        force = True 
    3136 
    3237    files_added = [] 
     
    6267         
    6368        if check_mime: 
    64             if mime_type == "" and eol_style == '': 
    65                 errmsg.append( "%s : 属性 svn:mime-type 或者 svn:eol-style 没有设置" % path.decode('utf-8','replace').encode('utf-8','replace') ) 
    66             elif ptext.match(mime_type) and eol_style == '': 
    67                 errmsg.append( "%s : svn:mime-type=%s 但是 svn:eol-style 没有设置" % (path.decode('utf-8','replace').encode('utf-8','replace'), mime_type) ) 
     69            if mime_type == "" or ptext.match(mime_type): 
     70                if eol_style == '': 
     71                    ## check if crlf in file contents 
     72                    if not force: 
     73                        if crlf_in_file(txn, repos, path): 
     74                            errmsg.append( "CRLF (DOS style EOL) in file: %s" % path.decode('utf-8','replace').encode('utf-8','replace') ) 
     75                        else: 
     76                            continue 
     77                    if mime_type == "": 
     78                        errmsg.append( "%s : 属性 svn:mime-type 或者 svn:eol-style 没有设置" % path.decode('utf-8','replace').encode('utf-8','replace') ) 
     79                    else: 
     80                        errmsg.append( "%s : svn:mime-type=%s 但是 svn:eol-style 没有设置" % (path.decode('utf-8','replace').encode('utf-8','replace'), mime_type) ) 
    6881 
    6982    if len( errmsg ) > 0: 
    7083        die( errmsg ) 
    7184 
    72  
     85def crlf_in_file(txn, repos, path): 
     86    cmd = '%s cat -t "%s" "%s" "%s"' % (SVNLOOK, txn, repos, path) 
     87    buff = os.popen(cmd, 'r').read(1024) 
     88    if '\r' in buff: 
     89        return True 
     90    else: 
     91        return False 
     92  
    7393def die(msg): 
    7494    """ 
     
    106126        sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0])) 
    107127    else: 
    108         main(sys.argv[1], sys.argv[2]) 
     128        main(sys.argv[1], sys.argv[2], sys.argv[3:] and sys.argv[3] or '') 
  • trunk/pysvnmanager/hooks/plugins/EolStyleCheck.py

    r50 r92  
    3939     
    4040    # Plugin config option/value in config ini file. 
    41     key = "eol_style_check" 
    42     value = "yes" 
     41    key_switch = "eol_style_check" 
     42    key_force  = "eol_style_check_force" 
    4343     
    4444    section = 'pre_commit' 
     
    4949        Simply call 'has_config()'. 
    5050        """ 
    51         return self.has_config() 
     51        return self.has_config(self.key_switch) 
    5252     
    5353    def install_info(self): 
     
    5858        reST reference: http://docutils.sourceforge.net/docs/user/rst/quickref.html 
    5959        """ 
    60         return self.description 
     60        result = self.description 
     61        if self.enabled(): 
     62            result += "\n\n" 
     63            result += "**" + _("Current configuration") + "**\n\n" 
     64            force = self.get_config(self.key_force) 
     65            if force == "no": 
     66                result += "- " + _("Loose mode: permit checkin without svn:eol-style properity if no CRLF in text file.") 
     67            else: 
     68                result += "- " + _("Strict mode: must have svn:eol-style even if not CRLF in text file.") 
     69 
     70        return result 
     71  
    6172     
    6273    def install_config_form(self): 
     
    6677        Any html and javascript are welcome. 
    6778        """ 
    68         return "" 
     79        if self.get_config(self.key_force)=="no": 
     80            enable_checked  = "" 
     81            disable_checked = "checked" 
     82        else: 
     83            enable_checked  = "checked" 
     84            disable_checked = "" 
     85 
     86        result = "" 
     87        result += "<p><strong>%s</strong></p>" % _("Fill this form") 
     88        result += "<blockquote>" 
     89        result += "<dl>" 
     90        result += "\n<dt>" 
     91        result += "<input type='radio' name='force' value='yes' " + \ 
     92                enable_checked  + ">" + _("Strict mode") + "&nbsp;" 
     93        result += "\n<dd>" 
     94        result += _("Must set svn:eol-style even if CRLF not in text file (in Unix format).") 
     95        result += "\n<dt>" 
     96        result += "<input type='radio' name='force' value='no' " + \ 
     97                disable_checked + ">" + _("Loose mode") + "<br>" 
     98        result += "\n<dd>" 
     99        result += _("Permit checkin without svn:eol-style properity if is in Unix file format (no crlf in text file).") 
     100        result += "\n</dl>" 
     101        result += "</blockquote>" 
     102        return result 
    69103         
    70104    def uninstall(self): 
     
    73107        Simply call 'unset_config()' and 'save()'. 
    74108        """ 
    75         self.unset_config() 
     109        self.unset_config(self.key_switch) 
     110        self.unset_config(self.key_force) 
    76111        self.save() 
    77112     
     
    83118        Form fields in setup_config() will pass as params. 
    84119        """ 
    85         self.set_config() 
     120        force = params.get('force', 'no') 
     121        if force != 'no': 
     122            force = 'yes' 
     123        self.set_config(self.key_switch, 'yes') 
     124        self.set_config(self.key_force, force) 
    86125        self.save() 
    87126