librelist archives

« back to archive

synchronization with other Git processes?

synchronization with other Git processes?

From:
Han-Wen Nienhuys
Date:
2012-02-27 @ 22:08
Hi there,

what is the story on synchronizing libgit2 with changes made by other
git processes?  Is there a flush call of sorts, or does everything
work automatically?

Background: I want to transition a program in python from git
fork/exec to pygit2 calls.  Since the program is large, I will have
intermediate versions that read and write both through git,
git-fast-import and pygit2.

For example, I have code like

branch = repo.CurentBranch()
# .. do lots of slow stuff; user might run "git checkout OTHER-BRANCH" ..
if branch == repo.CurrentBranch()
 .. something special ..

Right now, since I use fork/exec with git-symbolic-ref HEAD for
CurrentBranch(), I don't need special synchronization.  If I move to
pygit2, do I need something special to make sure the latest data is
read from disk?


-- 
Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen

Re: [libgit2] synchronization with other Git processes?

From:
Vicent Marti
Date:
2012-02-27 @ 22:14
Hey Han-Wen,

when dealing with references, you should call `git_reference_reload`
if you suspect that the reference may have been modified while the
library is running. I am not sure whether this API call has been
wrapped in pygit2.

Pretty much everything else is synchronous at the FS level, including
the ODB, so there's nothing to do there. Configuration files must be
re-opened if they are modified externally (but this is a rare case).
The index file can be reloaded, but I'd strongly advice against having
two processes working on the same index at the same time.

Cheers,
Vicent

On Mon, Feb 27, 2012 at 11:08 PM, Han-Wen Nienhuys <hanwenn@gmail.com> wrote:
> Hi there,
>
> what is the story on synchronizing libgit2 with changes made by other
> git processes?  Is there a flush call of sorts, or does everything
> work automatically?
>
> Background: I want to transition a program in python from git
> fork/exec to pygit2 calls.  Since the program is large, I will have
> intermediate versions that read and write both through git,
> git-fast-import and pygit2.
>
> For example, I have code like
>
> branch = repo.CurentBranch()
> # .. do lots of slow stuff; user might run "git checkout OTHER-BRANCH" ..
> if branch == repo.CurrentBranch()
>  .. something special ..
>
> Right now, since I use fork/exec with git-symbolic-ref HEAD for
> CurrentBranch(), I don't need special synchronization.  If I move to
> pygit2, do I need something special to make sure the latest data is
> read from disk?
>
>
> --
> Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen

Re: [libgit2] synchronization with other Git processes?

From:
Han-Wen Nienhuys
Date:
2012-02-27 @ 22:40
On Mon, Feb 27, 2012 at 7:14 PM, Vicent Marti <vicent@github.com> wrote:
> Hey Han-Wen,
>
> when dealing with references, you should call `git_reference_reload`
> if you suspect that the reference may have been modified while the
> library is running. I am not sure whether this API call has been
> wrapped in pygit2.

Can I get away with trying to load and resolve the reference from
scratch, or is there an internal reference cache?

I'll have a look at adding the call to pygit2 if necessary.
-- 
Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen

Re: [libgit2] synchronization with other Git processes?

From:
Vicent Marti
Date:
2012-02-27 @ 23:41
On Mon, Feb 27, 2012 at 11:40 PM, Han-Wen Nienhuys <hanwenn@gmail.com> wrote:
> On Mon, Feb 27, 2012 at 7:14 PM, Vicent Marti <vicent@github.com> wrote:
> Can I get away with trying to load and resolve the reference from
> scratch, or is there an internal reference cache?

Absolutely. Loading a reference from scratch will get an updated
version it if it has changed on disk (just ensure that the old ones
are free'd or memory will leak). The `reload` API is more efficient,
though.