Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Fwd: Use of RepositoryListener (especially RefsChangedListener)

On Mon, Jun 3, 2013 at 2:44 PM, Frank Blechschmidt <frable90@xxxxxxxxx> wrote:
> Is there an Example how to use RefsChangedListener or any other Listener?
> I want to get notified if a user do a pull on a local repository.
> GitListener listener = new GitListener(String name);
> Repository localRepo = new FileRepository(gitPath); //gitPath is like
> C:\Users\frabl_000\SoCoTestGit\socoLocal\socoLocal\.git
> localRepo.getListenerList().addRefsChangedListener(listener);
> Does the onRefsChanged() only get called if you use the localRepo variable
> or will it also be called if you modify the repository via command line or
> EGit?

This isn't magical. The listener is fired when the localRepo instance
observes the reference has changed. This can happen because localRepo
processed the update to modify the reference, or because localRepo was
asked to scan references again because of an invocation to getRefs()
that returned the updated reference.

If localRepo doesn't make the change and localRepo doesn't read the
reference, no notification is fired.

> My Goal:
> Get notified if the user pull from origin; reset a HashMap which saves if a
> file was opened.

Should work if the pull was executed using localRepo. Otherwise no,
you need to poll periodically to identify the reference you cared
about was moved.

Back to the top