7
7
#include "xdiff-interface.h"
8
8
#include "linear-assignment.h"
9
9
#include "diffcore.h"
10
+ #include "commit.h"
11
+ #include "pretty.h"
10
12
11
13
struct patch_util {
12
14
/* For the search for an exact match */
@@ -251,9 +253,59 @@ static void get_correspondences(struct string_list *a, struct string_list *b,
251
253
free (b2a );
252
254
}
253
255
254
- static const char * short_oid (struct patch_util * util )
256
+ static void output_pair_header (struct strbuf * buf ,
257
+ struct patch_util * a_util ,
258
+ struct patch_util * b_util )
255
259
{
256
- return find_unique_abbrev (util -> oid .hash , DEFAULT_ABBREV );
260
+ static char * dashes ;
261
+ struct object_id * oid = a_util ? & a_util -> oid : & b_util -> oid ;
262
+ struct commit * commit ;
263
+
264
+ if (!dashes ) {
265
+ char * p ;
266
+
267
+ dashes = xstrdup (find_unique_abbrev (oid -> hash , DEFAULT_ABBREV ));
268
+ for (p = dashes ; * p ; p ++ )
269
+ * p = '-' ;
270
+ }
271
+
272
+ strbuf_reset (buf );
273
+ if (!a_util )
274
+ strbuf_addf (buf , "-: %s " , dashes );
275
+ else
276
+ strbuf_addf (buf , "%d: %s " , a_util -> i + 1 ,
277
+ find_unique_abbrev (a_util -> oid .hash ,
278
+ DEFAULT_ABBREV ));
279
+
280
+ if (!a_util )
281
+ strbuf_addch (buf , '>' );
282
+ else if (!b_util )
283
+ strbuf_addch (buf , '<' );
284
+ else if (strcmp (a_util -> patch , b_util -> patch ))
285
+ strbuf_addch (buf , '!' );
286
+ else
287
+ strbuf_addch (buf , '=' );
288
+
289
+ if (!b_util )
290
+ strbuf_addf (buf , " -: %s" , dashes );
291
+ else
292
+ strbuf_addf (buf , " %d: %s" , b_util -> i + 1 ,
293
+ find_unique_abbrev (b_util -> oid .hash ,
294
+ DEFAULT_ABBREV ));
295
+
296
+ commit = lookup_commit_reference (oid );
297
+ if (commit ) {
298
+ const char * commit_buffer = get_commit_buffer (commit , NULL );
299
+ const char * subject ;
300
+
301
+ find_commit_subject (commit_buffer , & subject );
302
+ strbuf_addch (buf , ' ' );
303
+ format_subject (buf , subject , " " );
304
+ unuse_commit_buffer (commit , commit_buffer );
305
+ }
306
+ strbuf_addch (buf , '\n' );
307
+
308
+ fwrite (buf -> buf , buf -> len , 1 , stdout );
257
309
}
258
310
259
311
static struct diff_filespec * get_filespec (const char * name , const char * p )
@@ -282,6 +334,7 @@ static void patch_diff(const char *a, const char *b,
282
334
static void output (struct string_list * a , struct string_list * b ,
283
335
struct diff_options * diffopt )
284
336
{
337
+ struct strbuf buf = STRBUF_INIT ;
285
338
int i = 0 , j = 0 ;
286
339
287
340
/*
@@ -303,32 +356,29 @@ static void output(struct string_list *a, struct string_list *b,
303
356
304
357
/* Show unmatched LHS commit whose predecessors were shown. */
305
358
if (i < a -> nr && a_util -> matching < 0 ) {
306
- printf ("%d: %s < -: --------\n" ,
307
- i + 1 , short_oid (a_util ));
359
+ output_pair_header (& buf , a_util , NULL );
308
360
i ++ ;
309
361
continue ;
310
362
}
311
363
312
364
/* Show unmatched RHS commits. */
313
365
while (j < b -> nr && b_util -> matching < 0 ) {
314
- printf ("-: -------- > %d: %s\n" ,
315
- j + 1 , short_oid (b_util ));
366
+ output_pair_header (& buf , NULL , b_util );
316
367
b_util = ++ j < b -> nr ? b -> items [j ].util : NULL ;
317
368
}
318
369
319
370
/* Show matching LHS/RHS pair. */
320
371
if (j < b -> nr ) {
321
372
a_util = a -> items [b_util -> matching ].util ;
322
- printf ("%d: %s ! %d: %s\n" ,
323
- b_util -> matching + 1 , short_oid (a_util ),
324
- j + 1 , short_oid (b_util ));
373
+ output_pair_header (& buf , a_util , b_util );
325
374
if (!(diffopt -> output_format & DIFF_FORMAT_NO_OUTPUT ))
326
375
patch_diff (a -> items [b_util -> matching ].string ,
327
376
b -> items [j ].string , diffopt );
328
377
a_util -> shown = 1 ;
329
378
j ++ ;
330
379
}
331
380
}
381
+ strbuf_release (& buf );
332
382
}
333
383
334
384
int show_range_diff (const char * range1 , const char * range2 ,
0 commit comments