comparison src/org/tmatesoft/hg/repo/StatusCollector.java @ 90:a95c700408a9

Correctly report copy/rename events for rev..working copy case
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 26 Jan 2011 06:31:40 +0100
parents 42bcb4bffd17
children d55d4eedfc57
comparison
equal deleted inserted replaced
89:42bcb4bffd17 90:a95c700408a9
145 inspector.clean(fname); 145 inspector.clean(fname);
146 } else { 146 } else {
147 inspector.modified(fname); 147 inspector.modified(fname);
148 } 148 }
149 } else { 149 } else {
150 HgDataFile df = repo.getFileNode(fname); 150 String copyOrigin = getOriginIfCopy(repo, fname, r1Files, rev1);
151 boolean isCopy = false; 151 if (copyOrigin != null) {
152 while (df.isCopy()) { 152 inspector.copied(copyOrigin, fname);
153 Path original = df.getCopySourceName(); 153 } else {
154 if (r1Files.contains(original.toString())) {
155 df = repo.getFileNode(original);
156 int changelogRevision = df.getChangesetLocalRevision(0);
157 if (changelogRevision <= rev1) {
158 // copy/rename source was known prior to rev1
159 // (both r1Files.contains is true and original was created earlier than rev1)
160 // without r1Files.contains changelogRevision <= rev1 won't suffice as the file
161 // might get removed somewhere in between (changelogRevision < R < rev1)
162 inspector.copied(original.toString(), fname);
163 isCopy = true;
164 }
165 break;
166 }
167 df = repo.getFileNode(original); // try more steps away
168 }
169 if (!isCopy) {
170 inspector.added(fname); 154 inspector.added(fname);
171 } 155 }
172 } 156 }
173 } 157 }
174 for (String left : r1Files) { 158 for (String left : r1Files) {
179 163
180 public Record status(int rev1, int rev2) { 164 public Record status(int rev1, int rev2) {
181 Record rv = new Record(); 165 Record rv = new Record();
182 walk(rev1, rev2, rv); 166 walk(rev1, rev2, rv);
183 return rv; 167 return rv;
168 }
169
170 /*package-local*/static String getOriginIfCopy(HgRepository hgRepo, String fname, Collection<String> originals, int originalChangelogRevision) {
171 HgDataFile df = hgRepo.getFileNode(fname);
172 while (df.isCopy()) {
173 Path original = df.getCopySourceName();
174 if (originals.contains(original.toString())) {
175 df = hgRepo.getFileNode(original);
176 int changelogRevision = df.getChangesetLocalRevision(0);
177 if (changelogRevision <= originalChangelogRevision) {
178 // copy/rename source was known prior to rev1
179 // (both r1Files.contains is true and original was created earlier than rev1)
180 // without r1Files.contains changelogRevision <= rev1 won't suffice as the file
181 // might get removed somewhere in between (changelogRevision < R < rev1)
182 return original.toString();
183 }
184 break; // copy/rename done later
185 }
186 df = hgRepo.getFileNode(original); // try more steps away
187 }
188 return null;
184 } 189 }
185 190
186 public interface Inspector { 191 public interface Inspector {
187 void modified(String fname); 192 void modified(String fname);
188 void added(String fname); 193 void added(String fname);