@@ -302,6 +302,54 @@ static void create_tag(const unsigned char *object, const char *tag,
302
302
}
303
303
}
304
304
305
+ static void create_reflog_msg (const unsigned char * sha1 , struct strbuf * sb )
306
+ {
307
+ enum object_type type ;
308
+ struct commit * c ;
309
+ char * buf ;
310
+ unsigned long size ;
311
+ int subject_len = 0 ;
312
+ const char * subject_start ;
313
+
314
+ char * rla = getenv ("GIT_REFLOG_ACTION" );
315
+ if (rla ) {
316
+ strbuf_addstr (sb , rla );
317
+ } else {
318
+ strbuf_addstr (sb , _ ("tag: tagging " ));
319
+ strbuf_add_unique_abbrev (sb , sha1 , DEFAULT_ABBREV );
320
+ }
321
+
322
+ strbuf_addstr (sb , " (" );
323
+ type = sha1_object_info (sha1 , NULL );
324
+ switch (type ) {
325
+ default :
326
+ strbuf_addstr (sb , _ ("object of unknown type" ));
327
+ break ;
328
+ case OBJ_COMMIT :
329
+ if ((buf = read_sha1_file (sha1 , & type , & size )) != NULL ) {
330
+ subject_len = find_commit_subject (buf , & subject_start );
331
+ strbuf_insert (sb , sb -> len , subject_start , subject_len );
332
+ } else {
333
+ strbuf_addstr (sb , _ ("commit object" ));
334
+ }
335
+ free (buf );
336
+
337
+ if ((c = lookup_commit_reference (sha1 )) != NULL )
338
+ strbuf_addf (sb , ", %s" , show_date (c -> date , 0 , DATE_MODE (SHORT )));
339
+ break ;
340
+ case OBJ_TREE :
341
+ strbuf_addstr (sb , _ ("tree object" ));
342
+ break ;
343
+ case OBJ_BLOB :
344
+ strbuf_addstr (sb , _ ("blob object" ));
345
+ break ;
346
+ case OBJ_TAG :
347
+ strbuf_addstr (sb , _ ("other tag object" ));
348
+ break ;
349
+ }
350
+ strbuf_addch (sb , ')' );
351
+ }
352
+
305
353
struct msg_arg {
306
354
int given ;
307
355
struct strbuf buf ;
@@ -335,6 +383,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
335
383
{
336
384
struct strbuf buf = STRBUF_INIT ;
337
385
struct strbuf ref = STRBUF_INIT ;
386
+ struct strbuf reflog_msg = STRBUF_INIT ;
338
387
unsigned char object [20 ], prev [20 ];
339
388
const char * object_ref , * tag ;
340
389
struct create_tag_options opt ;
@@ -496,6 +545,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
496
545
else
497
546
die (_ ("Invalid cleanup mode %s" ), cleanup_arg );
498
547
548
+ create_reflog_msg (object , & reflog_msg );
549
+
499
550
if (create_tag_object ) {
500
551
if (force_sign_annotate && !annotate )
501
552
opt .sign = 1 ;
@@ -506,7 +557,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
506
557
if (!transaction ||
507
558
ref_transaction_update (transaction , ref .buf , object , prev ,
508
559
create_reflog ? REF_FORCE_CREATE_REFLOG : 0 ,
509
- NULL , & err ) ||
560
+ reflog_msg . buf , & err ) ||
510
561
ref_transaction_commit (transaction , & err ))
511
562
die ("%s" , err .buf );
512
563
ref_transaction_free (transaction );
@@ -516,5 +567,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
516
567
strbuf_release (& err );
517
568
strbuf_release (& buf );
518
569
strbuf_release (& ref );
570
+ strbuf_release (& reflog_msg );
519
571
return 0 ;
520
572
}
0 commit comments