From b4c212309b27c01dcf1a859774f6a0dc0a2338a5 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Wed, 19 Dec 2018 11:07:43 +0100 Subject: RebaseCommand: use orig-head in addition to head Since 2011-02-10 (i.e., git 1.7.6)[1] native git uses "orig-head" for REBASE_HEAD. JGit was still using "head". Currently native git has a legacy fall-back for reading this, but for how long? Let's write to both. Note that JGit never reads this file. [1] https://github.com/git/git/commit/84df4560 Bug: 511487 Change-Id: Id3742bf9bbc0001d850e801b26cc8880e646abfc Signed-off-by: Thomas Wolf --- org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 416a6c2dfc..4d3f2d9831 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -162,7 +162,10 @@ public class RebaseCommand extends GitCommand { private static final String PATCH = "patch"; //$NON-NLS-1$ - private static final String REBASE_HEAD = "head"; //$NON-NLS-1$ + private static final String REBASE_HEAD = "orig-head"; //$NON-NLS-1$ + + /** Pre git 1.7.6 file name for {@link #REBASE_HEAD}. */ + private static final String REBASE_HEAD_LEGACY = "head"; //$NON-NLS-1$ private static final String AMEND = "amend"; //$NON-NLS-1$ @@ -1120,6 +1123,7 @@ public class RebaseCommand extends GitCommand { repo.writeOrigHead(headId); rebaseState.createFile(REBASE_HEAD, headId.name()); + rebaseState.createFile(REBASE_HEAD_LEGACY, headId.name()); rebaseState.createFile(HEAD_NAME, headName); rebaseState.createFile(ONTO, upstreamCommit.name()); rebaseState.createFile(ONTO_NAME, upstreamCommitName); -- cgit v1.2.3 From 4ad53c0cbf9ec33984ad375b682fab91160d410b Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Wed, 19 Dec 2018 11:26:21 +0100 Subject: RebaseCommand: use orig-head to abort Aborting a rebase used ORIG_HEAD to reset. Strictly speaking this is not correct, since other commands run during the rebase (for instance, when the rebase stopped on a conflict) might have changed ORIG_HEAD. Prefer the OID recorded in the orig-head file, falling back to the older "head" file if "orig-head" doesn't exist, and use ORIG_HEAD only if neither exists. Bug: 511487 Change-Id: Ifa99221bb33e4e4754377f9b8f46e76c8936e072 Signed-off-by: Thomas Wolf --- .../src/org/eclipse/jgit/api/RebaseCommand.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 4d3f2d9831..9e83fc73d6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -1340,8 +1340,8 @@ public class RebaseCommand extends GitCommand { private RebaseResult abort(RebaseResult result) throws IOException, GitAPIException { + ObjectId origHead = getOriginalHead(); try { - ObjectId origHead = repo.readOrigHead(); String commitId = origHead != null ? origHead.name() : null; monitor.beginTask(MessageFormat.format( JGitText.get().abortingRebase, commitId), @@ -1380,7 +1380,7 @@ public class RebaseCommand extends GitCommand { // update the HEAD res = refUpdate.link(headName); } else { - refUpdate.setNewObjectId(repo.readOrigHead()); + refUpdate.setNewObjectId(origHead); res = refUpdate.forceUpdate(); } @@ -1407,6 +1407,19 @@ public class RebaseCommand extends GitCommand { } } + private ObjectId getOriginalHead() throws IOException { + try { + return ObjectId.fromString(rebaseState.readFile(REBASE_HEAD)); + } catch (FileNotFoundException e) { + try { + return ObjectId + .fromString(rebaseState.readFile(REBASE_HEAD_LEGACY)); + } catch (FileNotFoundException ex) { + return repo.readOrigHead(); + } + } + } + private boolean checkoutCommit(String headName, RevCommit commit) throws IOException, CheckoutConflictException { -- cgit v1.2.3 From 38e5a75ce49abe7068e4612f4159902114ca951f Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Wed, 19 Dec 2018 11:34:35 +0100 Subject: RebaseCommand: tighten check for --preserve-merges on --continue With native git, .git/rebase-merge/rewritten exists actually in two different cases: * as a file in git rebase --merge recording OIDs for copying notes * as a directory in git rebase --preserve-merges Add a comment, and check for isDirectory() instead of exists(). Bug: 511487 Change-Id: I6a3317b4234d4f41c41b3004cdc7ea0abf2c6223 Signed-off-by: Thomas Wolf --- org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 9e83fc73d6..0e3d000d3a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -180,6 +180,10 @@ public class RebaseCommand extends GitCommand { /** * The folder containing the hashes of (potentially) rewritten commits when * --preserve-merges is used. + *

+ * Native git rebase --merge uses a file of that name to record + * commits to copy notes at the end of the whole rebase. + *

*/ private static final String REWRITTEN = "rewritten"; //$NON-NLS-1$ @@ -292,7 +296,7 @@ public class RebaseCommand extends GitCommand { } this.upstreamCommit = walk.parseCommit(repo .resolve(upstreamCommitId)); - preserveMerges = rebaseState.getRewrittenDir().exists(); + preserveMerges = rebaseState.getRewrittenDir().isDirectory(); break; case BEGIN: autoStash(); -- cgit v1.2.3