RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 05-Sep-2013 18:50:28 Branch: rpm-5_4 Handle: 2013090516502700 Modified files: (Branch: rpm-5_4) rpm/rpmio librpmio.vers rpmgit.c rpmgit.h tgit.c Log: - git: add rev-parse.c fluff. Summary: Revision Changes Path 2.199.2.27 +3 -0 rpm/rpmio/librpmio.vers 2.1.2.37 +95 -30 rpm/rpmio/rpmgit.c 2.1.2.21 +18 -0 rpm/rpmio/rpmgit.h 1.1.2.33 +64 -0 rpm/rpmio/tgit.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/rpmio/librpmio.vers ============================================================================ $ cvs diff -u -r2.199.2.26 -r2.199.2.27 librpmio.vers --- rpm/rpmio/librpmio.vers 19 Jul 2013 08:56:51 -0000 2.199.2.26 +++ rpm/rpmio/librpmio.vers 5 Sep 2013 16:50:27 -0000 2.199.2.27 @@ -400,6 +400,7 @@ _rpmgit_tree; _rpmgitI; rpmgitAddFile; + rpmgitClose; rpmgitCmdAdd; rpmgitCmdCommit; rpmgitCmdDiff; @@ -410,6 +411,8 @@ rpmgitInfo; rpmgitInit; rpmgitNew; + rpmgitOid; + rpmgitOpen; rpmgitPopt; rpmgitPrintCommit; rpmgitPrintHead; @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmgit.c ============================================================================ $ cvs diff -u -r2.1.2.36 -r2.1.2.37 rpmgit.c --- rpm/rpmio/rpmgit.c 4 Sep 2013 21:14:45 -0000 2.1.2.36 +++ rpm/rpmio/rpmgit.c 5 Sep 2013 16:50:27 -0000 2.1.2.37 @@ -147,6 +147,30 @@ /*==============================================================*/ +static void check(int error, const char *message, const char *extra) +{ + const git_error *lg2err; + const char *lg2msg = ""; + const char *lg2spacer = ""; + + if (!error) + return; + + if ((lg2err = giterr_last()) != NULL && lg2err->message != NULL) { + lg2msg = lg2err->message; + lg2spacer = " - "; + } + + if (extra) + fprintf(stderr, "%s '%s' [%d]%s%s\n", + message, extra, error, lg2spacer, lg2msg); + else + fprintf(stderr, "%s [%d]%s%s\n", + message, error, lg2spacer, lg2msg); + + exit(1); +} + static int Xchkgit(/*@unused@*/ rpmgit git, const char * msg, int error, int printit, const char * func, const char * fn, unsigned ln) @@ -448,6 +472,7 @@ git->R = NULL; } /* XXX git_repository_init_ext(&git->R, git->fn, &opts); */ + /* XXX git->repodir? */ rc = chkgit(git, "git_repository_init", git_repository_init((git_repository **)&git->R, git->fn, git->is_bare)); @@ -604,8 +629,8 @@ } if (git->fp) fprintf(git->fp, "%s: %s\n", var_name, value); -SPEW(0, rc, git); +SPEW(0, rc, git); return rc; } #endif /* defined(WITH_LIBGT2) */ @@ -613,8 +638,8 @@ int rpmgitConfig(rpmgit git) { int rc = -1; -#if defined(WITH_LIBGIT2) +#if defined(WITH_LIBGIT2) /* Read/print/save configuration info. */ rc = chkgit(git, "git_repository_config", git_repository_config((git_config **)&git->cfg, git->R)); @@ -632,6 +657,59 @@ return rc; } +const char * rpmgitOid(rpmgit git, const void * _oid) +{ +#if defined(WITH_LIBGIT2) + git_oid * oid = (git_oid *) _oid; + git->str[0] = '\0'; + git_oid_tostr(git->str, sizeof(git->str), oid); + git->str[RPMGIT_OID_HEXSZ] = '\0'; +#else + git->str[0] = '\0'; +#endif /* defined(WITH_LIBGT2) */ + return git->str; +} + +int rpmgitClose(rpmgit git) +{ + int rc = 0; + +#if defined(WITH_LIBGIT2) + /* XXX other sanity checks and side effects? */ + if (git->R) { + git_repository_free(git->R); + git->R = NULL; + git->repodir = _free(git->repodir); + } +#endif /* defined(WITH_LIBGT2) */ + +SPEW(0, rc, git); + return rc; +} + +int rpmgitOpen(rpmgit git, const char * repodir) +{ + int rc = 0; + +#if defined(WITH_LIBGIT2) + /* XXX lazy close? */ + if (git->R == NULL) { + if (repodir) { + git->repodir = _free(git->repodir); + git->repodir = Realpath(repodir, NULL); + } else if (git->repodir == NULL) { + const char * dn = (git->fn ? git->fn : "."); + git->repodir = Realpath(dn, NULL); + } + rc = chkgit(git, "git_repository_open_ext", + git_repository_open_ext((git_repository **)&git->R, git->repodir, 0, NULL)); + } + +#endif /* defined(WITH_LIBGT2) */ +SPEW(0, rc, git); + return rc; +} + /*==============================================================*/ int rpmgitTree(rpmgit git) @@ -1013,6 +1091,7 @@ }; rpmgit git = rpmgitNew(argv, 0x80000000, initOpts); git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; + /* XXX git->repodir? */ const char * dir = git->fn; /* XXX */ int xx = -1; int i; @@ -1037,7 +1116,7 @@ opts.template_path = init_template; } if (init_gitdir) { - /* XXX use git->fn to eliminate dir */ + /* XXX use git->fn to eliminate dir. xstrdup? */ opts.workdir_path = dir; dir = init_gitdir; } @@ -1659,30 +1738,6 @@ FORMAT_PORCELAIN = 3, }; -static void check(int error, const char *message, const char *extra) -{ - const git_error *lg2err; - const char *lg2msg = ""; - const char *lg2spacer = ""; - - if (!error) - return; - - if ((lg2err = giterr_last()) != NULL && lg2err->message != NULL) { - lg2msg = lg2err->message; - lg2spacer = " - "; - } - - if (extra) - fprintf(stderr, "%s '%s' [%d]%s%s\n", - message, extra, error, lg2spacer, lg2msg); - else - fprintf(stderr, "%s [%d]%s%s\n", - message, error, lg2spacer, lg2msg); - - exit(1); -} - static void show_branch(git_repository *repo, int format) { int error = 0; @@ -2419,6 +2474,9 @@ git->core_bare = 0; git->is_bare = 0; + git->workdir = _free(git->workdir); + git->repodir = _free(git->repodir); + git->ac = 0; git->av = argvFree(git->av); git->con = poptFreeContext(git->con); @@ -2498,13 +2556,20 @@ } if (initialize) { + int xx; git_libgit2_version(&git->major, &git->minor, &git->rev); +#ifdef DYING if (git->fn && git->R == NULL) { - int xx; + git->repodir = xstrdup(git->fn); xx = chkgit(git, "git_repository_open", - git_repository_open((git_repository **)&git->R, git->fn)); + git_repository_open((git_repository **)&git->R, git->repodir)); } +#else + xx = rpmgitOpen(git, git->fn); +assert(xx == 0 && git->R != NULL && git->repodir != NULL); +#endif } + #ifdef NOTYET /* XXX rpmgitRun() uses pre-parsed git->av */ if (initialize) { static const char _rpmgitI_init[] = "%{?_rpmgitI_init}"; @@ -2523,7 +2588,7 @@ s = _free(s); } #endif /* NOTYET */ -#endif +#endif /* defined(WITH_LIBGIT2) */ return rpmgitLink(git); } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmgit.h ============================================================================ $ cvs diff -u -r2.1.2.20 -r2.1.2.21 rpmgit.h --- rpm/rpmio/rpmgit.h 4 Sep 2013 20:54:52 -0000 2.1.2.20 +++ rpm/rpmio/rpmgit.h 5 Sep 2013 16:50:27 -0000 2.1.2.21 @@ -47,6 +47,9 @@ ARGV_t av; int ac; + const char * repodir; /*!< open: absolute path */ + const char * workdir; /* XXX needed? */ + int is_bare; /*!< init: --bare */ int core_bare; @@ -84,6 +87,12 @@ time_t tstamp; #endif +#define RPMGIT_OID_RAWSZ 20 +#define RPMGIT_OID_HEXSZ (RPMGIT_OID_RAWSZ * 2) +#define RPMGIT_OID_MINPREFIXLEN 4 + unsigned char oid[RPMGIT_OID_RAWSZ]; /*!< struct git_oid */ + char str[RPMGIT_OID_HEXSZ + 1]; + #if defined(__LCLINT__) /*@refs@*/ int nrefs; /*!< (unused) keep splint happy */ @@ -204,6 +213,15 @@ int rpmgitConfig(rpmgit git) /*@*/; +const char * rpmgitOid(rpmgit git, const void * _oid) + /*@*/; + +int rpmgitClose(rpmgit git) + /*@*/; + +int rpmgitOpen(rpmgit git, const char * repodir) + /*@*/; + int rpmgitInfo(rpmgit git); int rpmgitTree(rpmgit git); int rpmgitWalk(rpmgit git); @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/tgit.c ============================================================================ $ cvs diff -u -r1.1.2.32 -r1.1.2.33 tgit.c --- rpm/rpmio/tgit.c 4 Sep 2013 21:14:45 -0000 1.1.2.32 +++ rpm/rpmio/tgit.c 5 Sep 2013 16:50:27 -0000 1.1.2.33 @@ -357,6 +357,60 @@ /*==============================================================*/ +#ifndef NOTYET +static int parse_revision(rpmgit git, const char *revstr) +{ + FILE * fp = stdout; + git_revspec rs; +int xx; + + xx = rpmgitOpen(git, git->fn); + if (xx) { + fprintf(fp, "Could not open repository (%s)\n", git->repodir); + goto exit; + } + + xx = chkgit(git, "git_revparse", + git_revparse(&rs, git->R, revstr)); + if (xx) { + fprintf(fp, "Could not parse \"%s\"\n", revstr); + goto exit; + } + + if ((rs.flags & GIT_REVPARSE_SINGLE) != 0) { + printf("%s\n", rpmgitOid(git, git_object_id(rs.from))); + git_object_free(rs.from); +xx = 0; + } else if ((rs.flags & GIT_REVPARSE_RANGE) != 0) { + printf("%s\n", rpmgitOid(git, git_object_id(rs.to))); + git_object_free(rs.to); + + if ((rs.flags & GIT_REVPARSE_MERGE_BASE) != 0) { + git_oid base; + xx = chkgit(git, "git_merge_base", + git_merge_base(&base, git->R, + git_object_id(rs.from), git_object_id(rs.to))); + if (xx) { + fprintf(fp, "Could not find merge base (%s)\n", revstr); + goto exit; + } + + printf("%s\n", rpmgitOid(git, &base)); + } + + printf("^%s\n", rpmgitOid(git, git_object_id(rs.from))); + git_object_free(rs.from); +xx = 0; + } else { + fprintf(fp, "Invalid results from git_revparse(\"%s\")\n", revstr); +xx = -1; + } + +exit: + return xx; +} +#endif + #ifdef REFERENCE OPTIONS --parseopt @@ -434,6 +488,7 @@ --all Show all refs found in refs/. +/* --branches[=pattern], --tags[=pattern], --remotes[=pattern] Show all branches, tags, or remote-tracking branches, respectively (i.e., refs found in refs/heads, refs/tags, or refs/remotes, @@ -448,6 +503,7 @@ pattern does not start with refs/, this is automatically prepended. If the pattern does not contain a globbing character (?, *, or [), it is turned into a prefix match by appending /\*. +*/ --show-toplevel Show the absolute path of the top-level directory. @@ -654,6 +710,14 @@ exit: rc = (xx ? RPMRC_FAIL : RPMRC_OK); SPEW(0, rc, git); + rp_default = _free(rp_default); + rp_abbrev_ref = _free(rp_abbrev_ref); + rp_branches_pat = _free(rp_branches_pat); + rp_tags_pat = _free(rp_tags_pat); + rp_remotes_pat = _free(rp_remotes_pat); + rp_glob_pat = _free(rp_glob_pat); + rp_since = _free(rp_since); + rp_until = _free(rp_until); git = rpmgitFree(git); return rc; @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org