subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhuij...@apache.org
Subject svn commit: r1718839 - in /subversion/branches/ra-git/subversion/libsvn_fs_git: fs_git.h fsgit-queries.sql git-fs.c git-revroot.c gitdb.c
Date Wed, 09 Dec 2015 12:51:39 GMT
Author: rhuijben
Date: Wed Dec  9 12:51:39 2015
New Revision: 1718839

URL: http://svn.apache.org/viewvc?rev=1718839&view=rev
Log:
On the ra-git branch: Start describe branching and tagging operations
as copies in changed paths and via specific fetch copy/origin apis.

* subversion/libsvn_fs_git/fsgit-queries.sql
  (STMT_SELECT_COMMIT_BY_REV_WITH_SRC,
   STMT_SELECT_CLOSEST_BRANCH_COPY): New query.

* subversion/libsvn_fs_git/fs_git.h
  (svn_fs_git__db_fetch_oid): Add some optional output arguments.
  (svn_fs_git__db_branch_closest_copy): New function.

* subversion/libsvn_fs_git/git-fs.c
  (fs_git_revision_proplist): Update caller.

* subversion/libsvn_fs_git/git-revroot.c
  (fs_git_paths_changed): Describe the creation of /tags/ in r1.
    Describe tag and branch operations.
  (fs_git_node_origin_rev): Add implementation.
  (fs_git_node_created_path): Update caller.
  (fs_git_copied_from): Add implementation.
  (fs_git_closest_copy): Add implementation.
  (fs_git_node_prop): Return no value instead of error.

* subversion/libsvn_fs_git/gitdb.c
  (svn_fs_git__db_fetch_oid): Add 3 arguments to allow fetching the branch
    operation in the same transaction.
  (db_branch_closest_copy,
   svn_fs_git__db_branch_closest_copy): New function.

Modified:
    subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h
    subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql
    subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c
    subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c
    subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c

Modified: subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h?rev=1718839&r1=1718838&r2=1718839&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h Wed Dec  9 12:51:39 2015
@@ -94,6 +94,10 @@ svn_error_t *
 svn_fs_git__db_fetch_oid(svn_boolean_t *found,
                          const git_oid **oid,
                          const char **path,
+                         svn_boolean_t *is_add,
+                         svn_boolean_t *is_replace,
+                         const char **copyfrom_path,
+                         svn_revnum_t *copyfrom_rev,
                          svn_fs_t *fs,
                          svn_revnum_t revnum,
                          apr_pool_t *result_pool,
@@ -155,6 +159,15 @@ svn_fs_git__db_set_uuid(svn_fs_t *fs,
                         const char *uuid,
                         apr_pool_t *scratch_pool);
 
+svn_error_t *
+svn_fs_git__db_branch_closest_copy(svn_revnum_t *revnum_p,
+                                   const char **relpath_p,
+                                   svn_fs_t *fs,
+                                   const char *relpath,
+                                   svn_revnum_t rev,
+                                   apr_pool_t *result_pool,
+                                   apr_pool_t *scratch_pool);
+
 /* */
 svn_error_t *
 svn_fs_git__revision_root(svn_fs_root_t **root_p,

Modified: subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql?rev=1718839&r1=1718838&r2=1718839&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql Wed Dec  9 12:51:39
2015
@@ -49,6 +49,34 @@ WHERE revnum <= ?1
 ORDER BY revnum DESC
 LIMIT 1
 
+-- STMT_SELECT_COMMIT_BY_REV_WITH_SRC
+SELECT r.commit_id, r.relpath, r.revnum, p.revnum, o.revnum, o.relpath
+FROM REVMAP r
+LEFT JOIN REVMAP p ON p.revnum = (SELECT MAX(x.revnum) FROM
+                                  REVMAP x
+                                  WHERE x.revnum < r.revnum
+                                    AND x.relpath = r.relpath)
+LEFT JOIN REVMAP o ON o.revnum=r.prev_revnum AND o.relpath != r.relpath
+WHERE r.revnum <= ?1
+ORDER BY r.revnum DESC
+LIMIT 1
+
+/* Selects the target of the closest copy */
+-- STMT_SELECT_CLOSEST_BRANCH_COPY
+SELECT r.revnum AS revnum, r.relpath AS relpath
+FROM REVMAP r
+WHERE r.relpath != (SELECT o.relpath
+                    FROM revmap o
+                    WHERE o.revnum = r.prev_revnum)
+  AND r.relpath = ?1
+  AND r.revnum <= ?2
+UNION ALL
+SELECT t.revnum AS revnum, t.relpath AS relpath
+FROM TAGMAP t
+WHERE t.relpath= ?1 AND t.revnum >= ?2
+ORDER BY revnum DESC
+LIMIT 1
+
 -- STMT_INSERT_COMMIT
 INSERT INTO REVMAP (revnum, commit_id, relpath, prev_revnum)
 VALUES (?1, ?2, ?3, ?4)

Modified: subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c?rev=1718839&r1=1718838&r2=1718839&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c Wed Dec  9 12:51:39 2015
@@ -68,7 +68,9 @@ fs_git_revision_proplist(apr_hash_t **ta
   git_oid *oid;
   *table_p = apr_hash_make(result_pool);
 
-  SVN_ERR(svn_fs_git__db_fetch_oid(&found, &oid, NULL, fs, rev,
+  SVN_ERR(svn_fs_git__db_fetch_oid(&found, &oid, NULL,
+                                   NULL, NULL, NULL, NULL,
+                                   fs, rev,
                                    scratch_pool, scratch_pool));
 
   if (found)

Modified: subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c?rev=1718839&r1=1718838&r2=1718839&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c Wed Dec  9 12:51:39
2015
@@ -359,6 +359,9 @@ fs_git_paths_changed(apr_hash_t **change
   git_tree *tree, *parent_tree;
   const git_oid *parent_oid;
   svn_boolean_t found;
+  const char *copyfrom_relpath;
+  svn_revnum_t copyfrom_rev;
+  svn_boolean_t is_add, is_replace;
 
   *changed_paths_p = changed_paths;
 
@@ -380,14 +383,47 @@ fs_git_paths_changed(apr_hash_t **change
                                                pool);
       ch->node_kind = svn_node_dir;
       svn_hash_sets(changed_paths, "/branches", ch);
+
+      ch = svn_fs__path_change_create_internal(make_id(root, "tags",
+                                                       pool),
+                                               svn_fs_path_change_add,
+                                               pool);
+      ch->node_kind = svn_node_dir;
+      svn_hash_sets(changed_paths, "/tags", ch);
     }
 
   /* TODO: Add branch + tag changes */
 
   SVN_ERR(svn_fs_git__db_fetch_oid(&found, &cmt_oid, &branch_path,
+                                   &is_add, &is_replace,
+                                   &copyfrom_relpath, &copyfrom_rev,
                                    root->fs, root->rev,
                                    pool, pool));
 
+  if ((is_add || is_replace)
+      && (root->rev > 2 || strcmp(branch_path, "trunk") != 0))
+    {
+      svn_fs_path_change2_t *ch;
+
+      ch = svn_fs__path_change_create_internal(make_id(root, branch_path, pool),
+                                               svn_fs_path_change_add,
+                                               pool);
+      ch->node_kind = svn_node_dir;
+
+      if (is_replace)
+        ch->change_kind = svn_fs_path_change_replace;
+
+      ch->copyfrom_known = svn_tristate_true;
+
+      if (copyfrom_relpath)
+        {
+          ch->copyfrom_path = make_fspath(copyfrom_relpath, pool);
+          ch->copyfrom_rev = copyfrom_rev;
+        }
+
+      svn_hash_sets(changed_paths, make_fspath(branch_path, pool), ch);
+    }
+
   if (!found || !cmt_oid)
     return SVN_NO_ERROR; /* No actual changes in this revision*/
 
@@ -726,7 +762,44 @@ fs_git_node_origin_rev(svn_revnum_t *rev
                        svn_fs_root_t *root, const char *path,
                        apr_pool_t *pool)
 {
-  *revision = root->rev; /* No common ancestry */
+  apr_pool_t *cur_pool = svn_pool_create(pool);
+  apr_pool_t *last_pool = svn_pool_create(pool);
+  svn_fs_history_t *hist;
+
+  /* For now, just fall back on the history walker which already handles
+     most (if not all) of the cases for specific paths */
+  SVN_ERR(fs_git_node_history(&hist, root, path, last_pool, cur_pool));
+
+  while (hist)
+    {
+      apr_pool_t *tmp_pool;
+      svn_fs_history_t *next;
+
+      svn_pool_clear(cur_pool);
+
+      SVN_ERR(svn_fs_history_prev2(&next, hist, TRUE, cur_pool, last_pool));
+
+      if (!next)
+        break;
+
+      hist = next;
+
+      tmp_pool = last_pool;
+      last_pool = cur_pool;
+      cur_pool = tmp_pool;
+    }
+
+  if (hist)
+    {
+      const char *path_dummy;
+      SVN_ERR(svn_fs_history_location(&path_dummy, revision, hist, last_pool));
+    }
+  else
+    *revision = root->rev;
+
+  svn_pool_destroy(last_pool);
+  svn_pool_destroy(cur_pool);
+
   return SVN_NO_ERROR;
 }
 
@@ -748,7 +821,9 @@ fs_git_node_created_path(const char **cr
     }
 
   SVN_ERR(find_branch(&commit, &relpath, root, path, pool));
-  SVN_ERR(svn_fs_git__db_fetch_oid(NULL, NULL, &basepath, root->fs, rev,
+  SVN_ERR(svn_fs_git__db_fetch_oid(NULL, NULL, &basepath,
+                                   NULL, NULL, NULL, NULL,
+                                   root->fs, rev,
                                    pool, pool));
 
   *created_path = make_fspath(svn_relpath_join(basepath, relpath, pool), pool);
@@ -784,9 +859,43 @@ fs_git_copied_from(svn_revnum_t *rev_p,
                    svn_fs_root_t *root, const char *path,
                    apr_pool_t *pool)
 {
+  const git_commit *commit;
+  const char *relpath;
+
+  if (*path == '/')
+    path++;
+
   *rev_p = SVN_INVALID_REVNUM;
   *path_p = NULL;
 
+  SVN_ERR(find_branch(&commit, &relpath, root, path, pool));
+
+  if (!relpath)
+    return SVN_NO_ERROR; /* No history*/
+
+  if (!relpath[0])
+    {
+      svn_boolean_t found;
+      const char *rev_path;
+      const char *copyfrom_relpath;
+      svn_revnum_t copyfrom_rev;
+
+      SVN_ERR(svn_fs_git__db_fetch_oid(&found, NULL, &rev_path,
+                                       NULL, NULL,
+                                       &copyfrom_relpath, &copyfrom_rev,
+                                       root->fs, root->rev,
+                                       pool, pool));
+
+      if (!found || strcmp(rev_path, path) != 0)
+        return SVN_NO_ERROR; /* Not copied in this revision */
+
+      *rev_p = copyfrom_rev;
+      *path_p = make_fspath(copyfrom_relpath, pool);
+      return SVN_NO_ERROR;
+    }
+
+  /* TODO: Handle in-branch copies */
+
   return SVN_NO_ERROR;
 }
 
@@ -795,9 +904,41 @@ fs_git_closest_copy(svn_fs_root_t **root
                     svn_fs_root_t *root, const char *path,
                     apr_pool_t *pool)
 {
+  const git_commit *commit;
+  const char *relpath;
+  svn_revnum_t br_rev;
+  const char *br_relpath;
+
   *root_p = NULL;
   *path_p = NULL;
 
+  if (*path == '/')
+    path++;
+
+  if (*path == '\0')
+    return SVN_NO_ERROR; /* Root can't be copied */
+
+  SVN_ERR(find_branch(&commit, &relpath, root, path, pool));
+  if (!commit)
+    return SVN_NO_ERROR; /* Not inside a branch */
+
+  SVN_ERR(svn_fs_git__db_branch_closest_copy(&br_rev, &br_relpath,
+                                             root->fs, path,
+                                             root->rev,
+                                             pool, pool));
+
+  if (relpath && *relpath)
+    {
+      /* TODO: Check if we have a copy in the branch */
+    }
+  else if (SVN_IS_VALID_REVNUM(br_rev))
+    {
+      SVN_ERR(root->fs->vtable->revision_root(root_p, root->fs, br_rev,
+                                              pool));
+      *path_p = make_fspath(br_relpath, pool);
+      return SVN_NO_ERROR;
+    }
+
   return SVN_NO_ERROR;
 }
 
@@ -807,7 +948,9 @@ fs_git_node_prop(svn_string_t **value_p,
                  const char *path, const char *propname,
                  apr_pool_t *pool)
 {
-  return svn_error_create(APR_ENOTIMPL, NULL, NULL);
+  *value_p = NULL;
+
+  return SVN_NO_ERROR;
 }
 
 static svn_error_t *
@@ -1283,6 +1426,7 @@ svn_fs_git__revision_root(svn_fs_root_t
     {
       git_oid *oid;
       SVN_ERR(svn_fs_git__db_fetch_oid(&fgr->exact, &oid, &fgr->rev_path,
+                                       NULL, NULL, NULL, NULL,
                                        fs, rev, pool, pool));
 
       if (oid)

Modified: subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c?rev=1718839&r1=1718838&r2=1718839&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c Wed Dec  9 12:51:39 2015
@@ -101,6 +101,10 @@ svn_error_t *
 svn_fs_git__db_fetch_oid(svn_boolean_t *found,
                          const git_oid **oid,
                          const char **path,
+                         svn_boolean_t *is_add,
+                         svn_boolean_t *is_replace,
+                         const char **copyfrom_path,
+                         svn_revnum_t *copyfrom_rev,
                          svn_fs_t *fs,
                          svn_revnum_t revnum,
                          apr_pool_t *result_pool,
@@ -109,9 +113,13 @@ svn_fs_git__db_fetch_oid(svn_boolean_t *
   svn_fs_git_fs_t *fgf = fs->fsap_data;
   svn_sqlite__stmt_t *stmt;
   svn_boolean_t got_row;
+  svn_boolean_t fetch_origin = (is_add || is_replace
+                                || copyfrom_path || copyfrom_rev);
 
   SVN_ERR(svn_sqlite__get_statement(&stmt, fgf->sdb,
-                                    STMT_SELECT_COMMIT_BY_REV));
+                                    fetch_origin
+                                    ? STMT_SELECT_COMMIT_BY_REV_WITH_SRC
+                                    : STMT_SELECT_COMMIT_BY_REV));
   SVN_ERR(svn_sqlite__bind_revnum(stmt, 1, revnum));
   SVN_ERR(svn_sqlite__step(&got_row, stmt));
 
@@ -128,6 +136,26 @@ svn_fs_git__db_fetch_oid(svn_boolean_t *
         }
       if (path)
         *path = svn_sqlite__column_text(stmt, 1, result_pool);
+
+      if (fetch_origin)
+        {
+          svn_boolean_t have_prev;
+          svn_boolean_t have_origin;
+
+          if (copyfrom_path)
+            *copyfrom_path = svn_sqlite__column_text(stmt, 5, result_pool);
+          if (copyfrom_rev)
+            *copyfrom_rev = svn_sqlite__column_revnum(stmt, 4);
+
+          have_prev = !svn_sqlite__column_is_null(stmt, 3);
+          have_origin = !svn_sqlite__column_is_null(stmt, 4);
+
+          if (is_add)
+            *is_add = !have_prev || have_origin;
+
+          if (is_replace)
+            *is_replace = have_origin && have_prev;
+        }
     }
   else
     {
@@ -137,6 +165,14 @@ svn_fs_git__db_fetch_oid(svn_boolean_t *
         *oid = NULL;
       if (path)
         *path = NULL;
+      if (is_add)
+        *is_add = FALSE;
+      if (is_replace)
+        *is_replace = FALSE;
+      if (copyfrom_path)
+        *copyfrom_path = NULL;
+      if (copyfrom_rev)
+        *copyfrom_rev = SVN_INVALID_REVNUM;
     }
   SVN_ERR(svn_sqlite__reset(stmt));
   return SVN_NO_ERROR;
@@ -338,6 +374,58 @@ svn_fs_git__db_find_branch(const char **
 }
 
 static svn_error_t *
+db_branch_closest_copy(svn_revnum_t *revnum_p,
+                       const char **relpath_p,
+                       svn_fs_t *fs,
+                       const char *relpath,
+                       svn_revnum_t rev,
+                       apr_pool_t *result_pool,
+                       apr_pool_t *scratch_pool)
+{
+  svn_fs_git_fs_t *fgf = fs->fsap_data;
+  svn_sqlite__stmt_t *stmt;
+  svn_boolean_t got_row;
+
+  *revnum_p = SVN_INVALID_REVNUM;
+  *relpath_p = NULL;
+
+  SVN_ERR(svn_sqlite__get_statement(&stmt, fgf->sdb,
+                                    STMT_SELECT_CLOSEST_BRANCH_COPY));
+  SVN_ERR(svn_sqlite__bind_text(stmt, 1, relpath));
+  SVN_ERR(svn_sqlite__bind_revnum(stmt, 1, rev));
+  SVN_ERR(svn_sqlite__step(&got_row, stmt));
+  if (got_row)
+    {
+      *revnum_p = svn_sqlite__column_revnum(stmt, 0);
+      *relpath_p = svn_sqlite__column_text(stmt, 1, result_pool);
+    }
+  SVN_ERR(svn_sqlite__reset(stmt));
+
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_fs_git__db_branch_closest_copy(svn_revnum_t *revnum_p,
+                                   const char **relpath_p,
+                                   svn_fs_t *fs,
+                                   const char *relpath,
+                                   svn_revnum_t rev,
+                                   apr_pool_t *result_pool,
+                                   apr_pool_t *scratch_pool)
+{
+  svn_fs_git_fs_t *fgf = fs->fsap_data;
+
+  SVN_SQLITE__WITH_LOCK(db_branch_closest_copy(revnum_p, relpath_p,
+                                               fs, relpath, rev,
+                                               result_pool, scratch_pool),
+                        fgf->sdb);
+
+  return SVN_NO_ERROR;
+
+}
+
+
+static svn_error_t *
 db_tag_create(svn_revnum_t *tag_rev,
               svn_fs_t *fs,
               const char *relpath,



Mime
View raw message