213
218
((BatchingProgressMonitor)monitor).SetDelayStart(250, TimeUnit.MILLISECONDS);
215
monitor.BeginTask(JGitText.Get().updatingReferences, localUpdates.Count);
216
220
if (transport.IsRemoveDeletedRefs())
218
DeleteStaleTrackingRefs(result, walk);
222
DeleteStaleTrackingRefs(result, batch);
220
224
foreach (TrackingRefUpdate u in localUpdates)
228
catch (IOException err)
230
throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingTrackingRef
231
, u.GetLocalName(), err.Message), err);
227
batch.AddCommand(u.AsReceiveCommand());
229
foreach (ReceiveCommand cmd in batch.GetCommands())
231
cmd.UpdateType(walk);
232
if (cmd.GetType() == ReceiveCommand.Type.UPDATE_NONFASTFORWARD && cmd is TrackingRefUpdate.Command
233
&& !((TrackingRefUpdate.Command)cmd).CanForceUpdate())
235
cmd.SetResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD);
238
if (transport.IsDryRun())
240
foreach (ReceiveCommand cmd_1 in batch.GetCommands())
242
if (cmd_1.GetResult() == ReceiveCommand.Result.NOT_ATTEMPTED)
244
cmd_1.SetResult(ReceiveCommand.Result.OK);
250
batch.Execute(walk, monitor);
253
catch (IOException err)
255
throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingTrackingRef
256
, GetFirstFailedRefName(batch), err.Message), err);
447
469
private ICollection<Ref> ExpandAutoFollowTags()
449
471
ICollection<Ref> additionalTags = new AList<Ref>();
450
IDictionary<string, Ref> haveRefs = transport.local.GetAllRefs();
472
IDictionary<string, Ref> haveRefs = LocalRefs();
451
473
foreach (Ref r in conn.GetRefs())
498
520
/// <exception cref="NGit.Errors.TransportException"></exception>
499
521
private void ExpandFetchTags()
501
IDictionary<string, Ref> haveRefs = transport.local.GetAllRefs();
523
IDictionary<string, Ref> haveRefs = LocalRefs();
502
524
foreach (Ref r in conn.GetRefs())
525
547
ObjectId newId = src.GetObjectId();
526
548
if (spec.GetDestination() != null)
530
TrackingRefUpdate tru = CreateUpdate(spec, newId);
531
if (newId.Equals(tru.GetOldObjectId()))
535
localUpdates.AddItem(tru);
537
catch (IOException err)
539
// Bad symbolic ref? That is the most likely cause.
541
throw new TransportException(MessageFormat.Format(JGitText.Get().cannotResolveLocalTrackingRefForUpdating
542
, spec.GetDestination()), err);
550
TrackingRefUpdate tru = CreateUpdate(spec, newId);
551
if (newId.Equals(tru.GetOldObjectId()))
555
localUpdates.AddItem(tru);
545
557
askFor.Put(newId, src);
546
558
FetchHeadRecord fhr = new FetchHeadRecord();
551
563
fetchHeadUpdates.AddItem(fhr);
554
/// <exception cref="System.IO.IOException"></exception>
566
/// <exception cref="NGit.Errors.TransportException"></exception>
555
567
private TrackingRefUpdate CreateUpdate(RefSpec spec, ObjectId newId)
557
return new TrackingRefUpdate(transport.local, spec, newId, "fetch");
569
Ref @ref = LocalRefs().Get(spec.GetDestination());
570
ObjectId oldId = @ref != null && @ref.GetObjectId() != null ? @ref.GetObjectId() :
572
return new TrackingRefUpdate(spec.IsForceUpdate(), spec.GetSource(), spec.GetDestination
560
576
/// <exception cref="NGit.Errors.TransportException"></exception>
561
private void DeleteStaleTrackingRefs(FetchResult result, RevWalk walk)
563
Repository db = transport.local;
564
foreach (Ref @ref in db.GetAllRefs().Values)
577
private IDictionary<string, Ref> LocalRefs()
579
if (localRefs == null)
583
localRefs = transport.local.RefDatabase.GetRefs(RefDatabase.ALL);
585
catch (IOException err)
587
throw new TransportException(JGitText.Get().cannotListRefs, err);
593
/// <exception cref="System.IO.IOException"></exception>
594
private void DeleteStaleTrackingRefs(FetchResult result, BatchRefUpdate batch)
596
foreach (Ref @ref in LocalRefs().Values)
566
598
string refname = @ref.GetName();
567
599
foreach (RefSpec spec in toFetch)
571
603
RefSpec s = spec.ExpandFromDestination(refname);
572
604
if (result.GetAdvertisedRef(s.GetSource()) == null)
574
DeleteTrackingRef(result, db, walk, s, @ref);
606
DeleteTrackingRef(result, batch, s, @ref);
581
/// <exception cref="NGit.Errors.TransportException"></exception>
582
private void DeleteTrackingRef(FetchResult result, Repository db, RevWalk walk, RefSpec
613
private void DeleteTrackingRef(FetchResult result, BatchRefUpdate batch, RefSpec
585
string name = localRef.GetName();
588
TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.GetSource(), true, ObjectId
591
if (transport.IsDryRun())
596
switch (u.GetResult())
598
case RefUpdate.Result.NEW:
599
case RefUpdate.Result.NO_CHANGE:
600
case RefUpdate.Result.FAST_FORWARD:
601
case RefUpdate.Result.FORCED:
608
throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
609
().cannotDeleteStaleTrackingRef2, name, u.GetResult().ToString()));
613
catch (IOException e)
615
throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
616
().cannotDeleteStaleTrackingRef, name), e);
616
if (localRef.GetObjectId() == null)
620
TrackingRefUpdate update = new TrackingRefUpdate(true, spec.GetSource(), localRef
621
.GetName(), localRef.GetObjectId(), ObjectId.ZeroId);
623
batch.AddCommand(update.AsReceiveCommand());
620
626
private static bool IsTag(Ref r)
627
633
return name.StartsWith(Constants.R_TAGS);
636
private static string GetFirstFailedRefName(BatchRefUpdate batch)
638
foreach (ReceiveCommand cmd in batch.GetCommands())
640
if (cmd.GetResult() != ReceiveCommand.Result.OK)
642
return cmd.GetRefName();