git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: Pieter de Bie <pdebie@ai.rug.nl>,
	Pierre Habouzit <madcoder@debian.org>,
	Nicolas Pitre <nico@cam.org>,
	git@vger.kernel.org, Scott Chacon <schacon@gmail.com>
Subject: Re: libgit2 - a true git library
Date: Fri, 31 Oct 2008 17:13:00 -0700	[thread overview]
Message-ID: <20081101001300.GE14786@spearce.org> (raw)
In-Reply-To: <7v63n872bs.fsf@gitster.siamese.dyndns.org>

Junio C Hamano <gitster@pobox.com> wrote:
> I understand that the apidocs/ is a very early work-in-progress, but
> still, it bothers me that it is unclear to me what lifetime rules are in
> effect on the in-core objects.

Yes, this needs a lot more documentation.

> For example, in C-git, commit objects are
> not just parsed but are modified in place as history is traversed
> (e.g. their flags smudged and their parents simplified).  You have "flags"
> field in commit, which implies to me that the design shares this same
> "modified by processing in-place" assumption.

Yup.  I was assuming the same model, we modify in-place.

> It is great for processing
> efficiency as long as you are a "run once and let exit(3) clean-up" type
> of program, but is quite problematic otherwise.  commit.flags that C-git
> uses for traversal marker purposes, together with "who are parents and
> children of this commit", should probably be kept inside traversal module,
> if you want to make this truly reusable.

Its not efficient to keep this data inside of the "traversal module"
instance (aka what I called git_revp_t).  You really want it inside
of the commit itself (aka git_commit_t).

My thought here is that git_commit_t's are scoped within a given
git_revp_t that was used when they were parsed.  That is:

  git_revp_t *pool_a = git_revp_alloc(db, NULL);
  git_revp_t *pool_b = git_revp_alloc(db, NULL);
  git_oid_t id;
  git_commit_t *commit_a, *commit_b, *commit_c;

  git_oid_mkstr(&id, "3c223b36af9cace4f802a855fbb588b1dccf0648");
  commit_a = git_commit_parse(pool_a, &id);
  commit_b = git_commit_parse(pool_b, &id);
  commit_c = git_commit_parse(pool_a, &id);

  if (commit_a == commit_b)
    die("the world just exploded");
  else
    printf("this was correct behavior\n");

  if (commit_a == commit_c)
    printf("this was correct behavior\n");
  else
    die("the hash table is broken");

To completely different git_revp_t's on the same database yeild
different commit pointers, but successive calls to parse the same
commit in the same pool yield the same pointer.

Certain operations on the pool can cause it to alter its state
in a way that cannot be reversed (e.g. rewrite parents).  In such
cases the caller should free the pool and alloc a new one in order
to issue new traversals against the same object database, but with
the original (or differently rewritten) parent information.

> By the way, I hate git_result_t.  That should be "int", the most natural
> integral type on the platform.

Yea, I'm torn on git_result_t myself.  Some library APIs use their
own result type, but as a typedef off int.

I'm tempted to stick with int for the result type, but I don't
want readers to confuse our result type of 0 == success, <0 ==
failure with some case where we return a signed integral value as
a result of a computation.

I'm also debating the error handling.  Do we return the error
code as the return value from the function, or do we stick it into
some sort of thread-global like classic "errno", or do we ask the
application to pass in a structure to us?

E.g.:

Return code:

  git_result_t r = git_foo_bar(...);
  if (r < 0)
  	die("foo_bar failed: %s", git_strerr(r));

Use an errno:

  if (git_foo_bar(...))
  	die("foo_bar failed: %s", git_strerr(git_errno));

Use a caller allocated struct:

  git_error_t err;
  if (git_foo_bar(..., &err))
  	die("foo_bar failed: %s", git_strerr(&err));

I'm slightly leaning towards the result code approach, as it means
we don't have to mess around with thread local variables.

We don't get to pass back anything more complex than an int (possibly
losing context about parameter values and/or on-disk state we want
to report on), but we also don't have to deal with thread-locals
or some messy "always pass a thread context parameter".

-- 
Shawn.

  parent reply	other threads:[~2008-11-01  0:14 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-31 17:07 libgit2 - a true git library Shawn O. Pearce
2008-10-31 17:28 ` Pieter de Bie
2008-10-31 17:29   ` Pieter de Bie
2008-10-31 17:47 ` Pierre Habouzit
2008-10-31 18:41   ` Shawn O. Pearce
2008-10-31 18:54     ` Pierre Habouzit
2008-10-31 19:57       ` Shawn O. Pearce
2008-10-31 20:12         ` Pierre Habouzit
2008-10-31 20:05     ` Junio C Hamano
2008-10-31 21:58       ` Shawn O. Pearce
2008-11-01 17:30     ` Pierre Habouzit
2008-11-01 18:44       ` Andreas Ericsson
2008-11-01 18:48         ` Pierre Habouzit
2008-11-01 20:29         ` Shawn O. Pearce
2008-11-01 21:58           ` Andreas Ericsson
2008-11-02  1:50             ` Shawn O. Pearce
2008-11-03 10:17               ` Andreas Ericsson
2008-11-02  1:56       ` Shawn O. Pearce
2008-11-02  9:25         ` Pierre Habouzit
2008-10-31 20:24   ` Nicolas Pitre
2008-10-31 20:29     ` david
2008-10-31 20:56       ` Nicolas Pitre
2008-10-31 21:43         ` Shawn O. Pearce
2008-10-31 21:50           ` Shawn O. Pearce
2008-10-31 21:51           ` Pierre Habouzit
2008-10-31 21:31     ` Pierre Habouzit
2008-10-31 22:10       ` Nicolas Pitre
2008-11-01 10:52         ` Andreas Ericsson
2008-10-31 23:24       ` Pieter de Bie
2008-10-31 23:28         ` Shawn O. Pearce
2008-10-31 23:49           ` Junio C Hamano
2008-11-01  0:02             ` Pierre Habouzit
2008-11-01  0:19               ` Shawn O. Pearce
2008-11-01  1:02                 ` Pierre Habouzit
2008-11-01  0:13             ` Shawn O. Pearce [this message]
2008-11-01  1:15               ` Nicolas Pitre
2008-11-01  1:19                 ` Shawn O. Pearce
2008-11-01  1:45                   ` Nicolas Pitre
2008-11-01  1:52                     ` Shawn O. Pearce
2008-11-01  2:26                       ` Johannes Schindelin
2008-11-01 11:01                         ` Pierre Habouzit
2008-11-01 13:50                           ` Nicolas Pitre
2008-11-01 17:01                             ` Pierre Habouzit
2008-11-01 20:26                             ` Johannes Schindelin
2008-10-31 23:14     ` Junio C Hamano
2008-10-31 23:33       ` Pierre Habouzit
2008-10-31 23:41       ` Shawn O. Pearce
2008-10-31 23:56         ` Jakub Narebski
2008-11-01  0:41         ` david
2008-11-01  1:00           ` Shawn O. Pearce
2008-11-01  1:04             ` david
2008-11-01  1:08               ` Pierre Habouzit
2008-11-01  1:33                 ` Nicolas Pitre
2008-11-01  1:38                   ` Pierre Habouzit
2008-11-01  1:49                     ` Nicolas Pitre
2008-11-01  1:43                   ` Shawn O. Pearce
2008-11-01  1:53                     ` Nicolas Pitre
2008-11-01 22:57                       ` Shawn O. Pearce
2008-11-02  0:26                         ` Scott Chacon
2008-11-02  1:07                           ` Scott Chacon
2008-11-02  1:36                             ` Shawn O. Pearce
2008-11-02  5:09                             ` David Brown
2008-11-03 16:20                               ` Shawn O. Pearce
2008-11-01  1:06           ` Pierre Habouzit
2008-11-01  1:36             ` david
2008-10-31 20:24   ` Brian Gernhardt
2008-10-31 21:59   ` Andreas Ericsson
2008-10-31 22:01     ` Shawn O. Pearce
2008-10-31 22:51       ` Junio C Hamano
2008-11-01 11:17       ` Andreas Ericsson
2008-10-31 23:22     ` Johannes Schindelin
2008-10-31 23:18 ` Bruno Santos
2008-10-31 23:25   ` Shawn O. Pearce
2008-11-01 19:18 ` Andreas Ericsson
2008-11-01 20:42   ` Shawn O. Pearce
2008-11-02  2:30     ` Johannes Schindelin
2008-11-02  9:19     ` Pierre Habouzit
2008-11-03 13:08     ` Andreas Ericsson
2008-11-08 13:26 ` Steve Frécinaux
2008-11-08 14:35   ` Andreas Ericsson
2008-11-08 17:27     ` Pierre Habouzit
2008-11-09 10:17       ` Andreas Ericsson
2008-11-09 21:02         ` Shawn O. Pearce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081101001300.GE14786@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=madcoder@debian.org \
    --cc=nico@cam.org \
    --cc=pdebie@ai.rug.nl \
    --cc=schacon@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).