1
1
// Copyright (C) 2011 The Android Open Source Project
2
2
// Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
3
- // Copyright (C) 2020 The Qt Company
3
+ // Copyright (C) 2021 The Qt Company
4
4
//
5
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
6
// you may not use this file except in compliance with the License.
@@ -288,7 +288,7 @@ public static Result updateRef(
288
288
return result ;
289
289
}
290
290
291
- private String getChangeId (RevCommit commit ) {
291
+ private static String getChangeId (RevCommit commit ) {
292
292
List <String > changeIds = commit .getFooterLines (FooterConstants .CHANGE_ID );
293
293
String changeId = null ;
294
294
if (!changeIds .isEmpty ()) changeId = changeIds .get (0 );
@@ -541,6 +541,7 @@ public static RevCommit merge(
541
541
RevWalk revWalk ,
542
542
RevCommit toMerge ,
543
543
RevCommit mergeTip ,
544
+ String customCommitMessage ,
544
545
boolean mergeAlways )
545
546
throws NoSuchRefException , IOException , MergeConflictException {
546
547
@@ -561,18 +562,20 @@ public static RevCommit merge(
561
562
return toMerge ;
562
563
}
563
564
564
- String message ;
565
- try {
566
- message = revWalk .parseCommit (toMerge ).getShortMessage ();
567
- } catch (Exception e ) {
568
- message = toMerge .toString ();
565
+ String message = customCommitMessage ;
566
+ if (message == null ) {
567
+ try {
568
+ message = revWalk .parseCommit (toMerge ).getShortMessage ();
569
+ } catch (Exception e ) {
570
+ message = toMerge .toString ();
571
+ }
572
+ message = "Merge \" " + toMerge .toString () + "\" " ;
569
573
}
570
- message = "Merge \" " + message + "\" " ;
571
574
572
575
final CommitBuilder mergeCommit = new CommitBuilder ();
573
576
mergeCommit .setTreeId (merger .getResultTreeId ());
574
577
mergeCommit .setParentIds (mergeTip , toMerge ); // important: mergeTip must be parent index 0
575
- mergeCommit .setAuthor (toMerge . getAuthorIdent () );
578
+ mergeCommit .setAuthor (committerIdent );
576
579
mergeCommit .setCommitter (committerIdent );
577
580
mergeCommit .setMessage (message );
578
581
@@ -585,17 +588,22 @@ public static RefUpdate.Result mergeBranches(
585
588
IdentifiedUser user ,
586
589
Repository git ,
587
590
final BranchNameKey branch ,
588
- final BranchNameKey destination )
591
+ final BranchNameKey destination ,
592
+ String customCommitMessage )
589
593
throws NoSuchRefException , IOException , MergeConflictException {
590
594
591
595
ObjectId srcId = git .resolve (branch .branch ());
592
596
if (srcId == null ) throw new NoSuchRefException ("Invalid Revision: " + branch );
593
597
594
- return mergeObjectToBranch (user , git , srcId , destination );
598
+ return mergeObjectToBranch (user , git , srcId , destination , customCommitMessage );
595
599
}
596
600
597
601
private static RefUpdate .Result mergeObjectToBranch (
598
- IdentifiedUser user , Repository git , ObjectId srcId , final BranchNameKey destination )
602
+ IdentifiedUser user ,
603
+ Repository git ,
604
+ ObjectId srcId ,
605
+ final BranchNameKey destination ,
606
+ String customCommitMessage )
599
607
throws NoSuchRefException , IOException , MergeConflictException {
600
608
601
609
Ref destRef = git .getRefDatabase ().getRef (destination .branch ());
@@ -613,7 +621,8 @@ private static RefUpdate.Result mergeObjectToBranch(
613
621
PersonIdent committer =
614
622
user .newCommitterIdent (new Timestamp (System .currentTimeMillis ()), TimeZone .getDefault ());
615
623
616
- RevCommit mergeCommit = merge (committer , git , objInserter , revWalk , toMerge , mergeTip , false );
624
+ RevCommit mergeCommit = merge (committer , git , objInserter , revWalk , toMerge ,
625
+ mergeTip , customCommitMessage , false );
617
626
logger .atInfo ().log ("qtcodereview: merge commit for %s added to %s" , srcId , destination );
618
627
619
628
RefUpdate refUpdate = git .updateRef (destination .branch ());
0 commit comments