mdpage/diffpatch.py
def diffstat(self):
        """calculate diffstat and return as a string
            Notes: - original diffstat ouputs target filename
                   - single + or - shouldn't escape histogram
        """
        names = []
        insert = []
        delete = []
        delta = 0    # size change in bytes
        namelen = 0
        maxdiff = 0  # max number of changes for single file (for histogram width calculation)
        for patch in self.patches:
            i = d = 0
            for hunk in patch:
                for line in hunk.text:
                    if line.startswith('+'):
                        i += 1
                        delta += len(line) - 1
                    elif line.startswith('-'):
                        d += 1
                        delta -= len(line) - 1
            names.append(patch.target)
            insert.append(i)
            delete.append(d)
            namelen = max(namelen, len(patch.target))
            maxdiff = max(maxdiff, i + d)

        output = ''
        statlen = len(str(maxdiff))  # stats column width
        for i, n in enumerate(names):
            # %-19s | %-4d %s
            fmt = " %-" + str(namelen) + "s | %" + str(statlen) + "s %s\n"

            hist = ''
            # -- calculating histogram --
            width = len(fmt % ('', '', ''))
            histwidth = max(2, 80 - width)
            if maxdiff < histwidth:
                hist = "+" * insert[i] + "-" * delete[i]
            else:
                iratio = (float(insert[i]) / maxdiff) * histwidth
                dratio = (float(delete[i]) / maxdiff) * histwidth

                # make sure every entry gets at least one + or -
                iwidth = 1 if 0 < iratio < 1 else int(iratio)
                dwidth = 1 if 0 < dratio < 1 else int(dratio)
                # print(iratio, dratio, iwidth, dwidth, histwidth)
                hist = "+" * iwidth + "-" * dwidth

            # -- /calculating +- histogram --
            output += (fmt % (names[i], str(insert[i] + delete[i]), hist))

        return (
            f"{output} {len(names)} files changed, {sum(insert)} insertions(+), "
            f"{sum(delete)} deletions(-), {delta:+d} bytes"
        )
calculate diffstat and return as a string
            Notes: - original diffstat ouputs target filename
                   - single + or - shouldn't escape histogram
        
calculate diffstat and return as a string
Notes: - original diffstat ouputs target filename
single + or - shouldn't escape histogram
calculate diffstat and return as a string Notes : - original diffstat ouputs target filename single + or - shouldn ' t escape histogram
def diffstat(self):
        names = []
        insert = []
        delete = []
        delta = 0    
        namelen = 0
        maxdiff = 0  
        for patch in self.patches:
            i = d = 0
            for hunk in patch:
                for line in hunk.text:
                    if line.startswith('+'):
                        i += 1
                        delta += len(line) - 1
                    elif line.startswith('-'):
                        d += 1
                        delta -= len(line) - 1
            names.append(patch.target)
            insert.append(i)
            delete.append(d)
            namelen = max(namelen, len(patch.target))
            maxdiff = max(maxdiff, i + d)
        output = ''
        statlen = len(str(maxdiff))  
        for i, n in enumerate(names):
            fmt = " %-" + str(namelen) + "s | %" + str(statlen) + "s %s\n"
            hist = ''
            width = len(fmt % ('', '', ''))
            histwidth = max(2, 80 - width)
            if maxdiff < histwidth:
                hist = "+" * insert[i] + "-" * delete[i]
            else:
                iratio = (float(insert[i]) / maxdiff) * histwidth
                dratio = (float(delete[i]) / maxdiff) * histwidth
                iwidth = 1 if 0 < iratio < 1 else int(iratio)
                dwidth = 1 if 0 < dratio < 1 else int(dratio)
                hist = "+" * iwidth + "-" * dwidth
            output += (fmt % (names[i], str(insert[i] + delete[i]), hist))
        return (
            f"{output} {len(names)} files changed, {sum(insert)} insertions(+), "
            f"{sum(delete)} deletions(-), {delta:+d} bytes"
        )
def diffstat ( self ) : names = [ ] insert = [ ] delete = [ ] delta = 0 namelen = 0 maxdiff = 0 for patch in self . patches : i = d = 0 for hunk in patch : for line in hunk . text : if line . startswith ( '+' ) : i += 1 delta += len ( line ) - 1 elif line . startswith ( '-' ) : d += 1 delta -= len ( line ) - 1 names . append ( patch . target ) insert . append ( i ) delete . append ( d ) namelen = max ( namelen , len ( patch . target ) ) maxdiff = max ( maxdiff , i + d ) output = '' statlen = len ( str ( maxdiff ) ) for i , n in enumerate ( names ) : fmt = " %-" + str ( namelen ) + "s | %" + str ( statlen ) + "s %s\n" hist = '' width = len ( fmt % ( '' , '' , '' ) ) histwidth = max ( 2 , 80 - width ) if maxdiff < histwidth : hist = "+" * insert [ i ] + "-" * delete [ i ] else : iratio = ( float ( insert [ i ] ) / maxdiff ) * histwidth dratio = ( float ( delete [ i ] ) / maxdiff ) * histwidth iwidth = 1 if 0 < iratio < 1 else int ( iratio ) dwidth = 1 if 0 < dratio < 1 else int ( dratio ) hist = "+" * iwidth + "-" * dwidth output += ( fmt % ( names [ i ] , str ( insert [ i ] + delete [ i ] ) , hist ) ) return ( f"{output} {len(names)} files changed, {sum(insert)} insertions(+), " f"{sum(delete)} deletions(-), {delta:+d} bytes" )
calculate diffstat and return as a string
Notes: - original diffstat ouputs target filename
 single + or - shouldn't escape histogram
calculate diffstat and return as a string Notes : - original diffstat ouputs target filename single + or - shouldn ' t escape histogram
"""calculate diffstat and return as a string
            Notes: - original diffstat ouputs target filename
                   - single + or - shouldn't escape histogram
        """ # size change in bytes # max number of changes for single file (for histogram width calculation) # stats column width # %-19s | %-4d %s # -- calculating histogram -- # make sure every entry gets at least one + or - # print(iratio, dratio, iwidth, dwidth, histwidth) # -- /calculating +- histogram --
self