Skip to content

Commit 607e91a

Browse files
committed
lsdiff: fix output with --git-prefixes=strip --addprefix=...
Assisted-by: Cursor
1 parent 5f0a7ee commit 607e91a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ read_timestamp (const char *timestamp, struct tm *result, long *zone)
10901090
}
10911091

10921092
/* Helper function to strip Git a/ or b/ prefixes from a filename */
1093-
static char *
1093+
char *
10941094
strip_git_prefix_from_filename (const char *filename, enum git_prefix_mode prefix_mode)
10951095
{
10961096
if (prefix_mode == GIT_PREFIX_STRIP &&

src/diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ enum git_prefix_mode {
7272

7373
char *filename_from_header (const char *header);
7474
char *filename_from_header_with_git_prefix_mode (const char *header, enum git_prefix_mode prefix_mode);
75+
char *strip_git_prefix_from_filename (const char *filename, enum git_prefix_mode prefix_mode);
7576

7677
enum git_diff_type detect_git_diff_type (char **headers, unsigned int num_headers);
7778
int extract_git_filenames (char **headers, unsigned int num_headers,

src/filterdiff.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ file_matches (void)
273273
static void display_filename (unsigned long linenum, char status,
274274
const char *filename, const char *patchname)
275275
{
276+
const char *processed_filename;
277+
char *git_stripped_filename = NULL;
278+
276279
if (mode == mode_list && !file_matches ())
277280
/* This is lsdiff --files=... and this file is not to be
278281
* listed. */
@@ -288,7 +291,15 @@ static void display_filename (unsigned long linenum, char status,
288291
printf ("%c ", status);
289292
if (prefix_to_add)
290293
fputs (prefix_to_add, stdout);
291-
puts (stripped (filename, strip_components));
294+
295+
/* Handle git prefix stripping if needed */
296+
git_stripped_filename = strip_git_prefix_from_filename(filename, git_prefix_mode);
297+
processed_filename = stripped(git_stripped_filename, strip_components);
298+
299+
puts (processed_filename);
300+
301+
/* Clean up allocated memory */
302+
free (git_stripped_filename);
292303
}
293304

294305
static int

0 commit comments

Comments
 (0)