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 */
@@ -255,9 +257,49 @@ static void get_correspondences(struct string_list *a, struct string_list *b,
255
257
free (b2a );
256
258
}
257
259
258
- static const char * short_oid (struct patch_util * util )
260
+ static void output_pair_header (struct strbuf * buf ,
261
+ struct strbuf * dashes ,
262
+ struct patch_util * a_util ,
263
+ struct patch_util * b_util )
259
264
{
260
- return find_unique_abbrev (& util -> oid , DEFAULT_ABBREV );
265
+ struct object_id * oid = a_util ? & a_util -> oid : & b_util -> oid ;
266
+ struct commit * commit ;
267
+
268
+ if (!dashes -> len )
269
+ strbuf_addchars (dashes , '-' ,
270
+ strlen (find_unique_abbrev (oid ,
271
+ DEFAULT_ABBREV )));
272
+
273
+ strbuf_reset (buf );
274
+ if (!a_util )
275
+ strbuf_addf (buf , "-: %s " , dashes -> buf );
276
+ else
277
+ strbuf_addf (buf , "%d: %s " , a_util -> i + 1 ,
278
+ find_unique_abbrev (& a_util -> oid , 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 -> buf );
291
+ else
292
+ strbuf_addf (buf , " %d: %s" , b_util -> i + 1 ,
293
+ find_unique_abbrev (& b_util -> oid , DEFAULT_ABBREV ));
294
+
295
+ commit = lookup_commit_reference (the_repository , oid );
296
+ if (commit ) {
297
+ strbuf_addch (buf , ' ' );
298
+ pp_commit_easy (CMIT_FMT_ONELINE , commit , buf );
299
+ }
300
+ strbuf_addch (buf , '\n' );
301
+
302
+ fwrite (buf -> buf , buf -> len , 1 , stdout );
261
303
}
262
304
263
305
static struct diff_filespec * get_filespec (const char * name , const char * p )
@@ -286,6 +328,7 @@ static void patch_diff(const char *a, const char *b,
286
328
static void output (struct string_list * a , struct string_list * b ,
287
329
struct diff_options * diffopt )
288
330
{
331
+ struct strbuf buf = STRBUF_INIT , dashes = STRBUF_INIT ;
289
332
int i = 0 , j = 0 ;
290
333
291
334
/*
@@ -307,32 +350,30 @@ static void output(struct string_list *a, struct string_list *b,
307
350
308
351
/* Show unmatched LHS commit whose predecessors were shown. */
309
352
if (i < a -> nr && a_util -> matching < 0 ) {
310
- printf ("%d: %s < -: --------\n" ,
311
- i + 1 , short_oid (a_util ));
353
+ output_pair_header (& buf , & dashes , a_util , NULL );
312
354
i ++ ;
313
355
continue ;
314
356
}
315
357
316
358
/* Show unmatched RHS commits. */
317
359
while (j < b -> nr && b_util -> matching < 0 ) {
318
- printf ("-: -------- > %d: %s\n" ,
319
- j + 1 , short_oid (b_util ));
360
+ output_pair_header (& buf , & dashes , NULL , b_util );
320
361
b_util = ++ j < b -> nr ? b -> items [j ].util : NULL ;
321
362
}
322
363
323
364
/* Show matching LHS/RHS pair. */
324
365
if (j < b -> nr ) {
325
366
a_util = a -> items [b_util -> matching ].util ;
326
- printf ("%d: %s ! %d: %s\n" ,
327
- b_util -> matching + 1 , short_oid (a_util ),
328
- j + 1 , short_oid (b_util ));
367
+ output_pair_header (& buf , & dashes , a_util , b_util );
329
368
if (!(diffopt -> output_format & DIFF_FORMAT_NO_OUTPUT ))
330
369
patch_diff (a -> items [b_util -> matching ].string ,
331
370
b -> items [j ].string , diffopt );
332
371
a_util -> shown = 1 ;
333
372
j ++ ;
334
373
}
335
374
}
375
+ strbuf_release (& buf );
376
+ strbuf_release (& dashes );
336
377
}
337
378
338
379
int show_range_diff (const char * range1 , const char * range2 ,
0 commit comments