Edgewall Software
Modify

Opened 10 days ago

Last modified 9 days ago

#13796 assigned defect

Exception in diff view

Reported by: Dirk Stöcker Owned by: Jun Omae
Priority: normal Milestone: 1.6.1
Component: general Version: 1.6
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

As I now grep the log for ValueError for #13792 following came up:

2024-10-12 05:15:10,605 Trac[api] WARNING: HTML preview using PatchRenderer with <RenderingContext <Resource 'ticket:15802, attachment:circular_building_tool_3.patch'>> failed: 
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/trac/mimeview/api.py", line 810, in render
    result = renderer.render(context, full_mimetype,
  File "/usr/local/lib/python3.10/dist-packages/trac/mimeview/patch.py", line 51, in render
    changes = self._diff_to_hdf(content.splitlines(),
  File "/usr/local/lib/python3.10/dist-packages/trac/mimeview/patch.py", line 113, in _diff_to_hdf
    oldpath, newpath = diffcmd_line.split()[-2:]
ValueError: not enough values to unpack (expected 2, got 1)

Happens when calling: https://josm.openstreetmap.de/attachment/ticket/15802/circular_building_tool.patch

Seems the code assumes something about the diff which isn't true. Didn't investigate further.

Attachments (0)

Change History (2)

comment:1 by anonymous, 9 days ago

Summary: Exception in diff viwException in diff view

comment:2 by Jun Omae, 9 days ago

Milestone: 1.6.1
Owner: set to Jun Omae
Status: newassigned

It seems to be caused by the process for GIT binary patch in the diff file.

  • trac/mimeview/patch.py

    diff --git a/trac/mimeview/patch.py b/trac/mimeview/patch.py
    index e394aa486..4685400b9 100644
    a b class PatchRenderer(Component):  
    107107                if not line.startswith('--- '):
    108108                    if not line.startswith('Index: ') and line != '=' * 67:
    109109                        comments.append(line)
    110                     if line == "GIT binary patch":
    111                         binary = True
    112                         diffcmd_line = comments[0] # diff --git a/... b/,,,
    113                         oldpath, newpath = diffcmd_line.split()[-2:]
    114                         if any(c.startswith('new file') for c in comments):
    115                             oldpath = '/dev/null'
    116                         if any(c.startswith('deleted file') for c in comments):
    117                             newpath = '/dev/null'
    118                         oldinfo = ['', oldpath]
    119                         newinfo = ['', newpath]
    120                         index = [c for c in comments if c.startswith('index ')]
    121                         if index: # index 8f****78..1e****5c
    122                             oldrev, newrev = index[0].split()[-1].split('..')
    123                             oldinfo.append(oldrev)
    124                             newinfo.append(newrev)
     110                    if line != "GIT binary patch":
    125111                        line = next(lines)
    126                         while line:
    127                             comments.append(line)
    128                             line = next(lines)
     112                        continue
     113                    binary = True
     114                    for pos, c in enumerate(comments):
     115                        if c.startswith('diff --git '):
     116                            break
    129117                    else:
    130                         line = next(lines)
    131118                        continue
     119                    diffcmd_line = comments[pos]  # diff --git a/... b/,,,
     120                    oldpath, newpath = diffcmd_line.split()[-2:]
     121                    if any(c.startswith('new file') for c in comments[pos:]):
     122                        oldpath = '/dev/null'
     123                    if any(c.startswith('deleted file') for c
     124                                                        in comments[pos:]):
     125                        newpath = '/dev/null'
     126                    oldinfo = ['', oldpath]
     127                    newinfo = ['', newpath]
     128                    for c in comments[pos:]:
     129                        if c.startswith('index '):  # index 8f****78..1e****5c
     130                            oldrev, newrev = c.split()[-1].split('..')
     131                            oldinfo.append(oldrev)
     132                            newinfo.append(newrev)
     133                            break
     134                    line = next(lines)
     135                    while line:
     136                        comments.append(line)
     137                        line = next(lines)
    132138
    133139                if not oldinfo and not newinfo:
    134140                    # Base filename/version from '--- <file> [rev]'

Modify Ticket

Change Properties
Set your email in Preferences
Action
as assigned The owner will remain Jun Omae.
The ticket will be disowned. Next status will be 'new'.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.