@@ -361,44 +361,15 @@ private ObjectId pickChangesToStagingRef(
361
361
return newId ;
362
362
}
363
363
364
- // Step backwards from staging head and return 1st commit in integrating status
365
- private ObjectId findIntegrationHead (
366
- Repository git ,
367
- ObjectId stagingHead ,
368
- ObjectId branchHead ,
369
- List <ChangeData > integratingChanges )
370
- throws MissingObjectException , IOException {
371
-
372
- if (stagingHead .equals (branchHead )) return branchHead ;
373
-
374
- RevWalk revWalk = new RevWalk (git );
375
- RevCommit commit = revWalk .parseCommit (stagingHead );
376
- int count = 0 ;
377
- do {
378
- count ++;
379
- String changeId = getChangeId (commit );
380
- ChangeData change = findChangeFromList (changeId , integratingChanges );
381
- if (change != null ) return commit ;
382
-
383
- if (commit .getParentCount () > 0 ) {
384
- // It can always be trusted that parent in index 0 is the correct one
385
- commit = revWalk .parseCommit (commit .getParent (0 ));
386
- } else commit = null ;
387
-
388
- } while (commit != null && !commit .equals (branchHead ) && count < 100 );
389
-
390
- return branchHead ;
391
- }
392
-
393
364
// Step backwards from staging head and find commit that can be reused
394
365
private ObjectId findReusableStagingHead (
395
366
Repository git ,
396
367
ObjectId stagingHead ,
397
- ObjectId integrationHead ,
368
+ ObjectId branchHead ,
398
369
List <ChangeData > stagedChanges )
399
370
throws MissingObjectException , IOException {
400
371
401
- if (stagingHead .equals (integrationHead )) return integrationHead ;
372
+ if (stagingHead .equals (branchHead )) return branchHead ;
402
373
403
374
ObjectId reusableHead = null ;
404
375
RevWalk revWalk = new RevWalk (git );
@@ -417,9 +388,9 @@ private ObjectId findReusableStagingHead(
417
388
commit = revWalk .parseCommit (commit .getParent (0 ));
418
389
} else commit = null ;
419
390
420
- } while (commit != null && !commit .equals (integrationHead ) && count < 100 );
391
+ } while (commit != null && !commit .equals (branchHead ) && count < 100 );
421
392
422
- if (reusableHead == null ) reusableHead = integrationHead ;
393
+ if (reusableHead == null ) reusableHead = branchHead ;
423
394
return reusableHead ;
424
395
}
425
396
@@ -431,23 +402,18 @@ public void rebuildStagingBranch(
431
402
final BranchNameKey destBranchShortKey )
432
403
throws MergeConflictException {
433
404
InternalChangeQuery query = null ;
434
- List <ChangeData > changes_integrating = null ;
435
405
List <ChangeData > changes_staged = null ;
436
406
List <ChangeData > changes_to_cherrypick = null ;
437
407
ObjectId oldStageRef = null ;
438
408
ObjectId branchRef = null ;
439
409
ObjectId newStageRef = null ;
440
- ObjectId integratingRef = null ;
441
410
String stagingBranchName = null ;
442
411
443
412
try {
444
413
stagingBranchName = stagingBranchKey .branch ();
445
414
oldStageRef = git .resolve (stagingBranchName );
446
415
branchRef = git .resolve (destBranchShortKey .branch ());
447
416
448
- query = queryProvider .get ();
449
- changes_integrating = query .byBranchStatus (destBranchShortKey , Change .Status .INTEGRATING );
450
-
451
417
query = queryProvider .get ();
452
418
changes_staged = query .byBranchStatus (destBranchShortKey , Change .Status .STAGED );
453
419
} catch (IOException e ) {
@@ -466,9 +432,7 @@ public void rebuildStagingBranch(
466
432
throw new NoSuchRefException ("Cannot create staging ref: " + stagingBranchName );
467
433
logger .atInfo ().log (
468
434
"qtcodereview: rebuild staging ref reset to %s with result %s" , branchRef , result );
469
- integratingRef = findIntegrationHead (git , oldStageRef , branchRef , changes_integrating );
470
- logger .atInfo ().log ("qtcodereview: rebuild staging integration ref is %s" , integratingRef );
471
- newStageRef = findReusableStagingHead (git , oldStageRef , integratingRef , changes_staged );
435
+ newStageRef = findReusableStagingHead (git , oldStageRef , branchRef , changes_staged );
472
436
logger .atInfo ().log ("qtcodereview: rebuild staging reused staging ref is %s" , newStageRef );
473
437
changes_to_cherrypick = arrangeOrderLikeInRef (git , oldStageRef , newStageRef , changes_staged );
474
438
} catch (NoSuchRefException | IOException e ) {
@@ -481,7 +445,7 @@ public void rebuildStagingBranch(
481
445
newStageRef = pickChangesToStagingRef (git , projectKey , changes_to_cherrypick , newStageRef );
482
446
} catch (Exception e ) {
483
447
logger .atInfo ().log ("qtcodereview: rebuild staging ref %s merge conflict" , stagingBranchKey );
484
- newStageRef = integratingRef ;
448
+ newStageRef = branchRef ;
485
449
String message =
486
450
"Merge conflict in staging branch. Status changed back to new. Please stage again." ;
487
451
QtChangeUpdateOp op =
@@ -612,7 +576,9 @@ public static RevCommit merge(
612
576
mergeCommit .setCommitter (committerIdent );
613
577
mergeCommit .setMessage (message );
614
578
615
- return revWalk .parseCommit (objInserter .insert (mergeCommit ));
579
+ ObjectId commit = objInserter .insert (mergeCommit );
580
+ objInserter .flush ();
581
+ return revWalk .parseCommit (commit );
616
582
}
617
583
618
584
public static RefUpdate .Result mergeBranches (
@@ -648,7 +614,6 @@ private static RefUpdate.Result mergeObjectToBranch(
648
614
user .newCommitterIdent (new Timestamp (System .currentTimeMillis ()), TimeZone .getDefault ());
649
615
650
616
RevCommit mergeCommit = merge (committer , git , objInserter , revWalk , toMerge , mergeTip , false );
651
- objInserter .flush ();
652
617
logger .atInfo ().log ("qtcodereview: merge commit for %s added to %s" , srcId , destination );
653
618
654
619
RefUpdate refUpdate = git .updateRef (destination .branch ());
0 commit comments