int (VcsRevisionNumber crev) { if (this == crev) return 0; if (crev instanceof GitRevisionNumber other) { if (myRevisionHash.equals(other.myRevisionHash)) { return 0; } if (other.myRevisionHash.indexOf("[") > 0) { return myTimestamp.compareTo(other.myTimestamp); } // check for parent revs String otherName = null; String thisName = null; int otherParents = -1; int thisParent = -1; if (other.myRevisionHash.contains("~")) { int tildeIndex = other.myRevisionHash.indexOf('~'); otherName = other.myRevisionHash.substring(0, tildeIndex); otherParents = Integer.parseInt(other.myRevisionHash.substring(tildeIndex)); } if (myRevisionHash.contains("~")) { int tildeIndex = myRevisionHash.indexOf('~'); thisName = myRevisionHash.substring(0, tildeIndex); thisParent = Integer.parseInt(myRevisionHash.substring(tildeIndex)); } if (otherName == null && thisName == null) { final int result = myTimestamp.compareTo(other.myTimestamp); if (result == 0) { // it can NOT be 0 - it would mean that revisions are equal but they have different hash codes // but this is NOT correct. but we don't know here how to sort return myRevisionHash.compareTo(other.myRevisionHash); } return result; } else if (otherName == null) { return 1; // I am an ancestor of the compared revision } else if (thisName == null) { return -1; // the compared revision is my ancestor } else { return thisParent - otherParents; // higher relative rev numbers are older ancestors } } return -1; }