private void addUpdateBatchCommands(FetchResult result, BatchRefUpdate batch) throws TransportException { Map<String, ObjectId> refs = new HashMap<>(); for (TrackingRefUpdate u : localUpdates) { // Try to skip duplicates if they'd update to the same object ID ObjectId existing = refs.get(u.getLocalName()); if (existing == null) { refs.put(u.getLocalName(), u.getNewObjectId()); result.add(u); batch.addCommand(u.asReceiveCommand()); } else if (!existing.equals(u.getNewObjectId())) { throw new TransportException(MessageFormat .format(JGitText.get().duplicateRef, u.getLocalName())); } } }
private void want(Ref src, RefSpec spec) throws TransportException { final ObjectId newId = src.getObjectId(); if (newId == null) { throw new NullPointerException(MessageFormat.format( JGitText.get().transportProvidedRefWithNoObjectId, src.getName())); } if (spec.getDestination() != null) { final TrackingRefUpdate tru = createUpdate(spec, newId); if (newId.equals(tru.getOldObjectId())) return; localUpdates.add(tru); } askFor.put(newId, src); final FetchHeadRecord fhr = new FetchHeadRecord(); fhr.newValue = newId; fhr.notForMerge = spec.getDestination() != null; fhr.sourceName = src.getName(); fhr.sourceURI = transport.getURI(); fetchHeadUpdates.add(fhr); }
private void deleteTrackingRef(final FetchResult result, final BatchRefUpdate batch, final RefSpec spec, final Ref localRef) { if (localRef.getObjectId() == null) return; TrackingRefUpdate update = new TrackingRefUpdate( true, spec.getSource(), localRef.getName(), localRef.getObjectId(), ObjectId.zeroId()); result.add(update); batch.addCommand(update.asReceiveCommand()); }
ReceiveCommand receiveCommand = trackingRefUpdate.asReceiveCommand(); if (receiveCommand.getType() == DELETE) { String localRefName = trackingRefUpdate.getLocalName(); if (StringUtils.startsWithIgnoreCase(localRefName, LOCAL_BRANCH_REF_PREFIX)) { String localBranchName = localRefName.substring(LOCAL_BRANCH_REF_PREFIX.length(), localRefName.length());
private List<TrackingRefUpdate> fetch(Repository repository) throws Exception { logger.info("Fetching changes of repository {}", repository.getDirectory().toString()); try (Git git = new Git(repository)) { FetchResult result = git.fetch().call(); Collection<TrackingRefUpdate> updates = result.getTrackingRefUpdates(); List<TrackingRefUpdate> remoteRefsChanges = new ArrayList<TrackingRefUpdate>(); for (TrackingRefUpdate update : updates) { String refName = update.getLocalName(); if (refName.startsWith(REMOTE_REFS_PREFIX)) { ObjectId newObjectId = update.getNewObjectId(); logger.info("{} is now at {}", refName, newObjectId.getName()); remoteRefsChanges.add(update); } } if (updates.isEmpty()) { logger.info("Nothing changed"); } return remoteRefsChanges; } }
private static String longTypeOf(ObjectReader reader, final TrackingRefUpdate u) { final RefUpdate.Result r = u.getResult(); if (r == RefUpdate.Result.LOCK_FAILURE) return "[lock fail]"; if (r == RefUpdate.Result.REJECTED) return "[rejected]"; if (ObjectId.zeroId().equals(u.getNewObjectId())) return "[deleted]"; if (u.getRemoteName().startsWith(Constants.R_HEADS)) return "[new branch]"; else if (u.getLocalName().startsWith(Constants.R_TAGS)) return "[new tag]"; return "[new]"; final String aOld = safeAbbreviate(reader, u.getOldObjectId()); final String aNew = safeAbbreviate(reader, u.getNewObjectId()); return aOld + "..." + aNew; //$NON-NLS-1$ final String aOld = safeAbbreviate(reader, u.getOldObjectId()); final String aNew = safeAbbreviate(reader, u.getNewObjectId()); return aOld + ".." + aNew; //$NON-NLS-1$
public ImageDescriptor getImageDescriptor(Object object) { switch (update.getResult()) { case IO_FAILURE: case LOCK_FAILURE: case RENAMED: case FAST_FORWARD: if (update.getRemoteName().startsWith(Constants.R_HEADS)) return UIIcons.BRANCH; if (update.getLocalName().startsWith(Constants.R_TAGS)) return UIIcons.TAG; if (update.getLocalName().startsWith(Constants.R_NOTES)) return UIIcons.NOTE; break; case NEW: if (update.getRemoteName().startsWith(Constants.R_HEADS)) return UIIcons.CREATE_BRANCH; if (update.getLocalName().startsWith(Constants.R_TAGS)) return UIIcons.CREATE_TAG; if (update.getLocalName().startsWith(Constants.R_NOTES)) return UIIcons.NOTE; break;
if (GitUtil.isHead(tru.getLocalName())) ObjectId oldId = tru.getOldObjectId(); ObjectId newId = tru.getNewObjectId();
private void addCommits(StyledString styled, String separator) { styled.append('[', StyledString.DECORATIONS_STYLER); styled.append(safeAbbreviate(update.getNewObjectId()), StyledString.DECORATIONS_STYLER); styled.append(separator, StyledString.DECORATIONS_STYLER); styled.append(safeAbbreviate(update.getOldObjectId()), StyledString.DECORATIONS_STYLER); styled.append(']', StyledString.DECORATIONS_STYLER); styled.append(MessageFormat.format( UIText.FetchResultTable_counterCommits, Integer.valueOf(getChildren(this).length)), StyledString.COUNTER_STYLER); }
/** * Create a new instance of this object basing on existing instance for * configuration. State (like {@link #getMessage()}, {@link #getStatus()}) * of base object is not shared. Expected old object id is set up from * scratch, as this constructor may be used for 2-stage push: first one * being dry run, second one being actual push. * * @param base * configuration base. * @param newExpectedOldObjectId * new expected object id value. * @throws java.io.IOException * when I/O error occurred during creating * {@link org.eclipse.jgit.transport.TrackingRefUpdate} for * local tracking branch or srcRef of base object no longer can * be resolved to any object. */ public RemoteRefUpdate(final RemoteRefUpdate base, final ObjectId newExpectedOldObjectId) throws IOException { this(base.localDb, base.srcRef, base.remoteName, base.forceUpdate, (base.trackingRefUpdate == null ? null : base.trackingRefUpdate .getLocalName()), newExpectedOldObjectId); }
public Object[] getChildren(Object object) { if (children != null) return children; switch (update.getResult()) { case FORCED: case FAST_FORWARD: RevWalk walk = new RevWalk(reader); try { walk.setRetainBody(true); walk.markStart(walk.parseCommit(update.getNewObjectId())); walk.markUninteresting(walk.parseCommit(update .getOldObjectId())); List<RepositoryCommit> commits = new ArrayList<RepositoryCommit>(); for (RevCommit commit : walk) commits.add(new RepositoryCommit(repo, commit)); children = commits.toArray(); break; } catch (IOException e) { Activator.logError( "Error parsing commits from fetch result", e); //$NON-NLS-1$ } finally { walk.release(); } //$FALL-THROUGH$ default: children = super.getChildren(object); } return children; }
private void removeTrackingRefUpdate(ObjectId want) { final Iterator<TrackingRefUpdate> i = localUpdates.iterator(); while (i.hasNext()) { final TrackingRefUpdate u = i.next(); if (u.getNewObjectId().equals(want)) i.remove(); } }
private TrackingRefUpdate createUpdate(RefSpec spec, ObjectId newId) throws TransportException { Ref ref = localRefs().get(spec.getDestination()); ObjectId oldId = ref != null && ref.getObjectId() != null ? ref.getObjectId() : ObjectId.zeroId(); return new TrackingRefUpdate( spec.isForceUpdate(), spec.getSource(), spec.getDestination(), oldId, newId); }
@Override public String getToolTipText(final Object element) { if (element instanceof FetchResultAdapter) { switch (((FetchResultAdapter) element).update.getResult()) { case FAST_FORWARD: return UIText.FetchResultTable_statusDetailFastForward; case FORCED: case REJECTED: return UIText.FetchResultTable_statusDetailNonFastForward; case IO_FAILURE: return UIText.FetchResultTable_statusDetailIOError; case LOCK_FAILURE: return UIText.FetchResultTable_statusDetailCouldntLock; default: return super.getToolTipText(element); } } return super.getToolTipText(element); }
/** * Update locally stored tracking branch with the new object. * * @param walk * walker used for checking update properties. * @throws java.io.IOException * when I/O error occurred during update */ protected void updateTrackingRef(RevWalk walk) throws IOException { if (isDelete()) trackingRefUpdate.setResult(localUpdate.delete(walk)); else trackingRefUpdate.setResult(localUpdate.update(walk)); }
for (TrackingRefUpdate u : localUpdates) { result.add(u); batch.addCommand(u.asReceiveCommand());
private List<TrackingRefUpdate> fetch(Repository repository) throws Exception { logger.info("Fetching changes of repository {}", repository.getDirectory().toString()); try (Git git = new Git(repository)) { FetchResult result = git.fetch().call(); Collection<TrackingRefUpdate> updates = result.getTrackingRefUpdates(); List<TrackingRefUpdate> remoteRefsChanges = new ArrayList<TrackingRefUpdate>(); for (TrackingRefUpdate update : updates) { String refName = update.getLocalName(); if (refName.startsWith(REMOTE_REFS_PREFIX)) { ObjectId newObjectId = update.getNewObjectId(); logger.info("{} is now at {}", refName, newObjectId.getName()); remoteRefsChanges.add(update); } } if (updates.isEmpty()) { logger.info("Nothing changed"); } return remoteRefsChanges; } }
protected void showFetchResult(final FetchResult r) throws IOException { ObjectReader reader = db.newObjectReader(); try { boolean shownURI = false; for (final TrackingRefUpdate u : r.getTrackingRefUpdates()) { if (!verbose && u.getResult() == RefUpdate.Result.NO_CHANGE) continue; final char type = shortTypeOf(u.getResult()); final String longType = longTypeOf(reader, u); final String src = abbreviateRef(u.getRemoteName(), false); final String dst = abbreviateRef(u.getLocalName(), true); if (!shownURI) { outw.println(MessageFormat.format(CLIText.get().fromURI, r.getURI())); shownURI = true; } outw.format(" %c %-17s %-10s -> %s", valueOf(type), longType, //$NON-NLS-1$ src, dst); outw.println(); } } finally { reader.release(); } showRemoteMessages(errw, r.getMessages()); }
for (RemoteRefUpdate refUpdate : pushResult.getRemoteUpdates()) { Status status = refUpdate.getStatus(); ObjectId from = refUpdate.getTrackingRefUpdate() == null || refUpdate.getTrackingRefUpdate().getOldObjectId() == null ? refUpdate.getExpectedOldObjectId() : refUpdate.getTrackingRefUpdate().getOldObjectId(); ObjectId to = refUpdate.getTrackingRefUpdate() == null || refUpdate.getTrackingRefUpdate().getNewObjectId() == null ? refUpdate.getNewObjectId() : refUpdate.getTrackingRefUpdate().getNewObjectId(); if (status == Status.OK) { acceptedUpdates.put(refUpdate.getSrcRef(), new RemoteBranchChange(refUpdate.getSrcRef(), refUpdate)
void add(TrackingRefUpdate u) { updates.put(u.getLocalName(), u); }