You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RenameDetector.java 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * Copyright (C) 2010, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.diff;
  44. import java.io.IOException;
  45. import java.util.ArrayList;
  46. import java.util.Arrays;
  47. import java.util.Collection;
  48. import java.util.Collections;
  49. import java.util.Comparator;
  50. import java.util.HashMap;
  51. import java.util.List;
  52. import org.eclipse.jgit.JGitText;
  53. import org.eclipse.jgit.diff.DiffEntry.ChangeType;
  54. import org.eclipse.jgit.lib.AbbreviatedObjectId;
  55. import org.eclipse.jgit.lib.Constants;
  56. import org.eclipse.jgit.lib.FileMode;
  57. import org.eclipse.jgit.lib.NullProgressMonitor;
  58. import org.eclipse.jgit.lib.ObjectReader;
  59. import org.eclipse.jgit.lib.ProgressMonitor;
  60. import org.eclipse.jgit.lib.Repository;
  61. /** Detect and resolve object renames. */
  62. public class RenameDetector {
  63. private static final int EXACT_RENAME_SCORE = 100;
  64. private static final Comparator<DiffEntry> DIFF_COMPARATOR = new Comparator<DiffEntry>() {
  65. public int compare(DiffEntry a, DiffEntry b) {
  66. int cmp = nameOf(a).compareTo(nameOf(b));
  67. if (cmp == 0)
  68. cmp = sortOf(a.getChangeType()) - sortOf(b.getChangeType());
  69. return cmp;
  70. }
  71. private String nameOf(DiffEntry ent) {
  72. // Sort by the new name, unless the change is a delete. On
  73. // deletes the new name is /dev/null, so we sort instead by
  74. // the old name.
  75. //
  76. if (ent.changeType == ChangeType.DELETE)
  77. return ent.oldPath;
  78. return ent.newPath;
  79. }
  80. private int sortOf(ChangeType changeType) {
  81. // Sort deletes before adds so that a major type change for
  82. // a file path (such as symlink to regular file) will first
  83. // remove the path, then add it back with the new type.
  84. //
  85. switch (changeType) {
  86. case DELETE:
  87. return 1;
  88. case ADD:
  89. return 2;
  90. default:
  91. return 10;
  92. }
  93. }
  94. };
  95. private List<DiffEntry> entries = new ArrayList<DiffEntry>();
  96. private List<DiffEntry> deleted = new ArrayList<DiffEntry>();
  97. private List<DiffEntry> added = new ArrayList<DiffEntry>();
  98. private boolean done;
  99. private final Repository repo;
  100. /** Similarity score required to pair an add/delete as a rename. */
  101. private int renameScore = 60;
  102. /**
  103. * Similarity score required to keep modified file pairs together. Any
  104. * modified file pairs with a similarity score below this will be broken
  105. * apart.
  106. */
  107. private int breakScore = -1;
  108. /** Limit in the number of files to consider for renames. */
  109. private int renameLimit;
  110. /** Set if the number of adds or deletes was over the limit. */
  111. private boolean overRenameLimit;
  112. /**
  113. * Create a new rename detector for the given repository
  114. *
  115. * @param repo
  116. * the repository to use for rename detection
  117. */
  118. public RenameDetector(Repository repo) {
  119. this.repo = repo;
  120. DiffConfig cfg = repo.getConfig().get(DiffConfig.KEY);
  121. renameLimit = cfg.getRenameLimit();
  122. }
  123. /**
  124. * @return minimum score required to pair an add/delete as a rename. The
  125. * score ranges are within the bounds of (0, 100).
  126. */
  127. public int getRenameScore() {
  128. return renameScore;
  129. }
  130. /**
  131. * Set the minimum score required to pair an add/delete as a rename.
  132. * <p>
  133. * When comparing two files together their score must be greater than or
  134. * equal to the rename score for them to be considered a rename match. The
  135. * score is computed based on content similarity, so a score of 60 implies
  136. * that approximately 60% of the bytes in the files are identical.
  137. *
  138. * @param score
  139. * new rename score, must be within [0, 100].
  140. * @throws IllegalArgumentException
  141. * the score was not within [0, 100].
  142. */
  143. public void setRenameScore(int score) {
  144. if (score < 0 || score > 100)
  145. throw new IllegalArgumentException(
  146. JGitText.get().similarityScoreMustBeWithinBounds);
  147. renameScore = score;
  148. }
  149. /**
  150. * @return the similarity score required to keep modified file pairs
  151. * together. Any modify pairs that score below this will be broken
  152. * apart into separate add/deletes. Values less than or equal to
  153. * zero indicate that no modifies will be broken apart. Values over
  154. * 100 cause all modify pairs to be broken.
  155. */
  156. public int getBreakScore() {
  157. return breakScore;
  158. }
  159. /**
  160. * @param breakScore
  161. * the similarity score required to keep modified file pairs
  162. * together. Any modify pairs that score below this will be
  163. * broken apart into separate add/deletes. Values less than or
  164. * equal to zero indicate that no modifies will be broken apart.
  165. * Values over 100 cause all modify pairs to be broken.
  166. */
  167. public void setBreakScore(int breakScore) {
  168. this.breakScore = breakScore;
  169. }
  170. /** @return limit on number of paths to perform inexact rename detection. */
  171. public int getRenameLimit() {
  172. return renameLimit;
  173. }
  174. /**
  175. * Set the limit on the number of files to perform inexact rename detection.
  176. * <p>
  177. * The rename detector has to build a square matrix of the rename limit on
  178. * each side, then perform that many file compares to determine similarity.
  179. * If 1000 files are added, and 1000 files are deleted, a 1000*1000 matrix
  180. * must be allocated, and 1,000,000 file compares may need to be performed.
  181. *
  182. * @param limit
  183. * new file limit.
  184. */
  185. public void setRenameLimit(int limit) {
  186. renameLimit = limit;
  187. }
  188. /**
  189. * Check if the detector is over the rename limit.
  190. * <p>
  191. * This method can be invoked either before or after {@code getEntries} has
  192. * been used to perform rename detection.
  193. *
  194. * @return true if the detector has more file additions or removals than the
  195. * rename limit is currently set to. In such configurations the
  196. * detector will skip expensive computation.
  197. */
  198. public boolean isOverRenameLimit() {
  199. if (done)
  200. return overRenameLimit;
  201. int cnt = Math.max(added.size(), deleted.size());
  202. return getRenameLimit() != 0 && getRenameLimit() < cnt;
  203. }
  204. /**
  205. * Add entries to be considered for rename detection.
  206. *
  207. * @param entriesToAdd
  208. * one or more entries to add.
  209. * @throws IllegalStateException
  210. * if {@code getEntries} was already invoked.
  211. */
  212. public void addAll(Collection<DiffEntry> entriesToAdd) {
  213. if (done)
  214. throw new IllegalStateException(JGitText.get().renamesAlreadyFound);
  215. for (DiffEntry entry : entriesToAdd) {
  216. switch (entry.getChangeType()) {
  217. case ADD:
  218. added.add(entry);
  219. break;
  220. case DELETE:
  221. deleted.add(entry);
  222. break;
  223. case MODIFY:
  224. if (sameType(entry.getOldMode(), entry.getNewMode())) {
  225. entries.add(entry);
  226. } else {
  227. List<DiffEntry> tmp = DiffEntry.breakModify(entry);
  228. deleted.add(tmp.get(0));
  229. added.add(tmp.get(1));
  230. }
  231. break;
  232. case COPY:
  233. case RENAME:
  234. default:
  235. entriesToAdd.add(entry);
  236. }
  237. }
  238. }
  239. /**
  240. * Add an entry to be considered for rename detection.
  241. *
  242. * @param entry
  243. * to add.
  244. * @throws IllegalStateException
  245. * if {@code getEntries} was already invoked.
  246. */
  247. public void add(DiffEntry entry) {
  248. addAll(Collections.singletonList(entry));
  249. }
  250. /**
  251. * Detect renames in the current file set.
  252. * <p>
  253. * This convenience function runs without a progress monitor.
  254. *
  255. * @return an unmodifiable list of {@link DiffEntry}s representing all files
  256. * that have been changed.
  257. * @throws IOException
  258. * file contents cannot be read from the repository.
  259. */
  260. public List<DiffEntry> compute() throws IOException {
  261. return compute(NullProgressMonitor.INSTANCE);
  262. }
  263. /**
  264. * Detect renames in the current file set.
  265. *
  266. * @param pm
  267. * report progress during the detection phases.
  268. * @return an unmodifiable list of {@link DiffEntry}s representing all files
  269. * that have been changed.
  270. * @throws IOException
  271. * file contents cannot be read from the repository.
  272. */
  273. public List<DiffEntry> compute(ProgressMonitor pm) throws IOException {
  274. if (!done) {
  275. done = true;
  276. if (pm == null)
  277. pm = NullProgressMonitor.INSTANCE;
  278. ObjectReader reader = repo.newObjectReader();
  279. try {
  280. breakModifies(reader, pm);
  281. findExactRenames(pm);
  282. findContentRenames(reader, pm);
  283. rejoinModifies(pm);
  284. } finally {
  285. reader.release();
  286. }
  287. entries.addAll(added);
  288. added = null;
  289. entries.addAll(deleted);
  290. deleted = null;
  291. Collections.sort(entries, DIFF_COMPARATOR);
  292. }
  293. return Collections.unmodifiableList(entries);
  294. }
  295. private void breakModifies(ObjectReader reader, ProgressMonitor pm)
  296. throws IOException {
  297. if (breakScore <= 0)
  298. return;
  299. ArrayList<DiffEntry> newEntries = new ArrayList<DiffEntry>(entries.size());
  300. pm.beginTask(JGitText.get().renamesBreakingModifies, entries.size());
  301. for (int i = 0; i < entries.size(); i++) {
  302. DiffEntry e = entries.get(i);
  303. if (e.getChangeType() == ChangeType.MODIFY) {
  304. int score = calculateModifyScore(reader, e);
  305. if (score < breakScore) {
  306. List<DiffEntry> tmp = DiffEntry.breakModify(e);
  307. DiffEntry del = tmp.get(0);
  308. del.score = score;
  309. deleted.add(del);
  310. added.add(tmp.get(1));
  311. } else {
  312. newEntries.add(e);
  313. }
  314. } else {
  315. newEntries.add(e);
  316. }
  317. pm.update(1);
  318. }
  319. entries = newEntries;
  320. }
  321. private void rejoinModifies(ProgressMonitor pm) {
  322. HashMap<String, DiffEntry> nameMap = new HashMap<String, DiffEntry>();
  323. ArrayList<DiffEntry> newAdded = new ArrayList<DiffEntry>(added.size());
  324. pm.beginTask(JGitText.get().renamesRejoiningModifies, added.size()
  325. + deleted.size());
  326. for (DiffEntry src : deleted) {
  327. nameMap.put(src.oldPath, src);
  328. pm.update(1);
  329. }
  330. for (DiffEntry dst : added) {
  331. DiffEntry src = nameMap.remove(dst.newPath);
  332. if (src != null) {
  333. if (sameType(src.oldMode, dst.newMode)) {
  334. entries.add(DiffEntry.pair(ChangeType.MODIFY, src, dst,
  335. src.score));
  336. } else {
  337. nameMap.put(src.oldPath, src);
  338. newAdded.add(dst);
  339. }
  340. } else {
  341. newAdded.add(dst);
  342. }
  343. pm.update(1);
  344. }
  345. added = newAdded;
  346. deleted = new ArrayList<DiffEntry>(nameMap.values());
  347. }
  348. private int calculateModifyScore(ObjectReader reader, DiffEntry d)
  349. throws IOException {
  350. SimilarityIndex src = new SimilarityIndex();
  351. src.hash(reader.open(d.oldId.toObjectId(), Constants.OBJ_BLOB));
  352. src.sort();
  353. SimilarityIndex dst = new SimilarityIndex();
  354. dst.hash(reader.open(d.newId.toObjectId(), Constants.OBJ_BLOB));
  355. dst.sort();
  356. return src.score(dst, 100);
  357. }
  358. private void findContentRenames(ObjectReader reader, ProgressMonitor pm)
  359. throws IOException {
  360. int cnt = Math.max(added.size(), deleted.size());
  361. if (cnt == 0)
  362. return;
  363. if (getRenameLimit() == 0 || cnt <= getRenameLimit()) {
  364. SimilarityRenameDetector d;
  365. d = new SimilarityRenameDetector(reader, deleted, added);
  366. d.setRenameScore(getRenameScore());
  367. d.compute(pm);
  368. deleted = d.getLeftOverSources();
  369. added = d.getLeftOverDestinations();
  370. entries.addAll(d.getMatches());
  371. } else {
  372. overRenameLimit = true;
  373. }
  374. }
  375. @SuppressWarnings("unchecked")
  376. private void findExactRenames(ProgressMonitor pm) {
  377. if (added.isEmpty() || deleted.isEmpty())
  378. return;
  379. pm.beginTask(JGitText.get().renamesFindingExact, //
  380. added.size() + added.size() + deleted.size()
  381. + added.size() * deleted.size());
  382. HashMap<AbbreviatedObjectId, Object> deletedMap = populateMap(deleted, pm);
  383. HashMap<AbbreviatedObjectId, Object> addedMap = populateMap(added, pm);
  384. ArrayList<DiffEntry> uniqueAdds = new ArrayList<DiffEntry>(added.size());
  385. ArrayList<List<DiffEntry>> nonUniqueAdds = new ArrayList<List<DiffEntry>>();
  386. for (Object o : addedMap.values()) {
  387. if (o instanceof DiffEntry)
  388. uniqueAdds.add((DiffEntry) o);
  389. else
  390. nonUniqueAdds.add((List<DiffEntry>) o);
  391. }
  392. ArrayList<DiffEntry> left = new ArrayList<DiffEntry>(added.size());
  393. for (DiffEntry a : uniqueAdds) {
  394. Object del = deletedMap.get(a.newId);
  395. if (del instanceof DiffEntry) {
  396. // We have one add to one delete: pair them if they are the same
  397. // type
  398. DiffEntry e = (DiffEntry) del;
  399. if (sameType(e.oldMode, a.newMode)) {
  400. e.changeType = ChangeType.RENAME;
  401. entries.add(exactRename(e, a));
  402. } else {
  403. left.add(a);
  404. }
  405. } else if (del != null) {
  406. // We have one add to many deletes: find the delete with the
  407. // same type and closest name to the add, then pair them
  408. List<DiffEntry> list = (List<DiffEntry>) del;
  409. DiffEntry best = bestPathMatch(a, list);
  410. if (best != null) {
  411. best.changeType = ChangeType.RENAME;
  412. entries.add(exactRename(best, a));
  413. } else {
  414. left.add(a);
  415. }
  416. } else {
  417. left.add(a);
  418. }
  419. pm.update(1);
  420. }
  421. for (List<DiffEntry> adds : nonUniqueAdds) {
  422. Object o = deletedMap.get(adds.get(0).newId);
  423. if (o instanceof DiffEntry) {
  424. // We have many adds to one delete: find the add with the same
  425. // type and closest name to the delete, then pair them. Mark the
  426. // rest as copies of the delete.
  427. DiffEntry d = (DiffEntry) o;
  428. DiffEntry best = bestPathMatch(d, adds);
  429. if (best != null) {
  430. d.changeType = ChangeType.RENAME;
  431. entries.add(exactRename(d, best));
  432. for (DiffEntry a : adds) {
  433. if (a != best) {
  434. if (sameType(d.oldMode, a.newMode)) {
  435. entries.add(exactCopy(d, a));
  436. } else {
  437. left.add(a);
  438. }
  439. }
  440. }
  441. } else {
  442. left.addAll(adds);
  443. }
  444. } else if (o != null) {
  445. // We have many adds to many deletes: score all the adds against
  446. // all the deletes by path name, take the best matches, pair
  447. // them as renames, then call the rest copies
  448. List<DiffEntry> dels = (List<DiffEntry>) o;
  449. long[] matrix = new long[dels.size() * adds.size()];
  450. int mNext = 0;
  451. for (int addIdx = 0; addIdx < adds.size(); addIdx++) {
  452. String addedName = adds.get(addIdx).newPath;
  453. for (int delIdx = 0; delIdx < dels.size(); delIdx++) {
  454. String deletedName = dels.get(delIdx).oldPath;
  455. int score = SimilarityRenameDetector.nameScore(addedName, deletedName);
  456. matrix[mNext] = SimilarityRenameDetector.encode(score, addIdx, delIdx);
  457. mNext++;
  458. }
  459. }
  460. Arrays.sort(matrix);
  461. for (--mNext; mNext >= 0; mNext--) {
  462. long ent = matrix[mNext];
  463. int delIdx = SimilarityRenameDetector.srcFile(ent);
  464. int addIdx = SimilarityRenameDetector.dstFile(ent);
  465. DiffEntry d = dels.get(delIdx);
  466. DiffEntry a = adds.get(addIdx);
  467. if (a == null) {
  468. pm.update(1);
  469. continue; // was already matched earlier
  470. }
  471. ChangeType type;
  472. if (d.changeType == ChangeType.DELETE) {
  473. // First use of this source file. Tag it as a rename so we
  474. // later know it is already been used as a rename, other
  475. // matches (if any) will claim themselves as copies instead.
  476. //
  477. d.changeType = ChangeType.RENAME;
  478. type = ChangeType.RENAME;
  479. } else {
  480. type = ChangeType.COPY;
  481. }
  482. entries.add(DiffEntry.pair(type, d, a, 100));
  483. adds.set(addIdx, null); // Claim the destination was matched.
  484. pm.update(1);
  485. }
  486. } else {
  487. left.addAll(adds);
  488. }
  489. }
  490. added = left;
  491. deleted = new ArrayList<DiffEntry>(deletedMap.size());
  492. for (Object o : deletedMap.values()) {
  493. if (o instanceof DiffEntry) {
  494. DiffEntry e = (DiffEntry) o;
  495. if (e.changeType == ChangeType.DELETE)
  496. deleted.add(e);
  497. } else {
  498. List<DiffEntry> list = (List<DiffEntry>) o;
  499. for (DiffEntry e : list) {
  500. if (e.changeType == ChangeType.DELETE)
  501. deleted.add(e);
  502. }
  503. }
  504. }
  505. pm.endTask();
  506. }
  507. /**
  508. * Find the best match by file path for a given DiffEntry from a list of
  509. * DiffEntrys. The returned DiffEntry will be of the same type as <src>. If
  510. * no DiffEntry can be found that has the same type, this method will return
  511. * null.
  512. *
  513. * @param src
  514. * the DiffEntry to try to find a match for
  515. * @param list
  516. * a list of DiffEntrys to search through
  517. * @return the DiffEntry from <list> who's file path best matches <src>
  518. */
  519. private static DiffEntry bestPathMatch(DiffEntry src, List<DiffEntry> list) {
  520. DiffEntry best = null;
  521. int score = -1;
  522. for (DiffEntry d : list) {
  523. if (sameType(mode(d), mode(src))) {
  524. int tmp = SimilarityRenameDetector
  525. .nameScore(path(d), path(src));
  526. if (tmp > score) {
  527. best = d;
  528. score = tmp;
  529. }
  530. }
  531. }
  532. return best;
  533. }
  534. @SuppressWarnings("unchecked")
  535. private HashMap<AbbreviatedObjectId, Object> populateMap(
  536. List<DiffEntry> diffEntries, ProgressMonitor pm) {
  537. HashMap<AbbreviatedObjectId, Object> map = new HashMap<AbbreviatedObjectId, Object>();
  538. for (DiffEntry de : diffEntries) {
  539. Object old = map.put(id(de), de);
  540. if (old instanceof DiffEntry) {
  541. ArrayList<DiffEntry> list = new ArrayList<DiffEntry>(2);
  542. list.add((DiffEntry) old);
  543. list.add(de);
  544. map.put(id(de), list);
  545. } else if (old != null) {
  546. // Must be a list of DiffEntries
  547. ((List<DiffEntry>) old).add(de);
  548. map.put(id(de), old);
  549. }
  550. pm.update(1);
  551. }
  552. return map;
  553. }
  554. private static String path(DiffEntry de) {
  555. return de.changeType == ChangeType.DELETE ? de.oldPath : de.newPath;
  556. }
  557. private static FileMode mode(DiffEntry de) {
  558. return de.changeType == ChangeType.DELETE ? de.oldMode : de.newMode;
  559. }
  560. private static AbbreviatedObjectId id(DiffEntry de) {
  561. return de.changeType == ChangeType.DELETE ? de.oldId : de.newId;
  562. }
  563. static boolean sameType(FileMode a, FileMode b) {
  564. // Files have to be of the same type in order to rename them.
  565. // We would never want to rename a file to a gitlink, or a
  566. // symlink to a file.
  567. //
  568. int aType = a.getBits() & FileMode.TYPE_MASK;
  569. int bType = b.getBits() & FileMode.TYPE_MASK;
  570. return aType == bType;
  571. }
  572. private static DiffEntry exactRename(DiffEntry src, DiffEntry dst) {
  573. return DiffEntry.pair(ChangeType.RENAME, src, dst, EXACT_RENAME_SCORE);
  574. }
  575. private static DiffEntry exactCopy(DiffEntry src, DiffEntry dst) {
  576. return DiffEntry.pair(ChangeType.COPY, src, dst, EXACT_RENAME_SCORE);
  577. }
  578. }