Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 984e4440618e97d5a2415c6edff47d2344d4081d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.egit.ui.internal.history;

import java.io.IOException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;

class GenerateHistoryJob extends Job {
	private static final int BATCH_SIZE = 256;

	private final GitHistoryPage page;

	private final SWTCommitList allCommits;

	private int lastUpdateCnt;

	private long lastUpdateAt;

	GenerateHistoryJob(final GitHistoryPage ghp, final SWTCommitList list) {
		super(UIText.HistoryPage_refreshJob);
		page = ghp;
		allCommits = list;
	}

	@Override
	protected IStatus run(final IProgressMonitor monitor) {
		IStatus status = Status.OK_STATUS;
		try {
			try {
				for (;;) {
					final int oldsz = allCommits.size();
					allCommits.fillTo(oldsz + BATCH_SIZE - 1);
					if (monitor.isCanceled() || oldsz == allCommits.size())
						break;

					final long now = System.currentTimeMillis();
					if (now - lastUpdateAt < 2000 && lastUpdateCnt > 0)
						continue;
					updateUI();
					lastUpdateAt = now;
				}
			} catch (IOException e) {
				status = new Status(IStatus.ERROR, Activator.getPluginId(),
						UIText.GenerateHistoryJob_errorComputingHistory, e);
			}

			if (monitor.isCanceled())
				return Status.CANCEL_STATUS;
			updateUI();
		} finally {
			monitor.done();
		}
		return status;
	}

	void updateUI() {
		if (allCommits.size() == lastUpdateCnt)
			return;

		final SWTCommit[] asArray = new SWTCommit[allCommits.size()];
		allCommits.toArray(asArray);
		page.showCommitList(this, allCommits, asArray);
		lastUpdateCnt = allCommits.size();
	}
}

Back to the top