You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Refael Ackermann <mo...@netvision.net.il> on 2004/06/05 23:30:56 UTC

[PATCH] Added dirent info to XML output from svnserve/get_dir

Index: subversion/include/svn_repos.h
===================================================================
--- subversion/include/svn_repos.h	(revision 9929)
+++ subversion/include/svn_repos.h	(working copy)
@@ -1178,6 +1178,12 @@
                                 apr_pool_t *pool);


+svn_error_t *
+svn_repos_fs_ents_to_dirents(apr_hash_t *entries,
+                             svn_fs_root_t *root,
+                             const char *path,
+                             apr_pool_t *pool);
+
  /** @} */

  #ifdef __cplusplus
Index: subversion/mod_dav_svn/repos.c
===================================================================
--- subversion/mod_dav_svn/repos.c	(revision 9929)
+++ subversion/mod_dav_svn/repos.c	(working copy)
@@ -37,6 +37,7 @@
  #include "svn_dav.h"
  #include "svn_sorts.h"
  #include "svn_version.h"
+#include "svn_time.h"

  #include "dav_svn.h"
  #include "mod_dav_svn.h"
@@ -2039,7 +2040,7 @@
                     resource->info->repos->xslt_uri);
          ap_fputs(output, bb, xml_index_dtd);
          ap_fputs(output, bb,
-                 "<svn version=\"" SVN_VERSION "\"\n"
+                 "<svn version=\"" SVN_VERSION "\""
                   "     href=\"http://subversion.tigris.org/\">\n");
          ap_fputs(output, bb, "  <index");
          if (name)
@@ -2064,6 +2065,12 @@
            ap_fprintf(output, bb, "    <updir />\n");
        }

+    /* convert ftents to dirent for more info [moseack] */
+    serr = svn_repos_fs_ents_to_dirents(entries,
+                                        resource->info->root.root,
+                                        resource->info->repos_path,
+                                        resource->pool);
+
      /* get a sorted list of the entries */
      sorted = svn_sort__hash(entries, svn_sort_compare_items_as_paths,
                              resource->pool);
@@ -2074,7 +2081,7 @@
        {
          const svn_sort__item_t *item = &APR_ARRAY_IDX(sorted, i,
                                                        const 
svn_sort__item_t);
-        const svn_fs_dirent_t *entry = item->value;
+        const svn_dirent_t *entry = item->value;
          const char *name = item->key;
          const char *href = name;
          svn_boolean_t is_dir = (entry->kind == svn_node_dir);
@@ -2100,16 +2107,40 @@
            }
          else
            {
-            const char *const tag = (is_dir ? "dir" : "file");
-            name = apr_xml_quote_string(entry_pool, name, 1);
-            href = apr_xml_quote_string(entry_pool, href, 1);

-            /* ### This is where the we could search for props */
+            if (is_dir)
+              {
+                name = apr_xml_quote_string(entry_pool, name, 1);
+                href = apr_xml_quote_string(entry_pool, href, 1);
+                ap_fprintf(output, bb,
+                           "    <dir name=\"%s\" href=\"%s\"></dir>\n",
+                           name, href);
+              }
+            else
+              {
+                apr_uint64_t size = (apr_uint64_t) entry->size;
+                long rev = (long) entry->created_rev;
+                const char *cauthor;
+                const char *last_time;

-            ap_fprintf(output, bb,
-                       "    <%s name=\"%s\" href=\"%s\"></%s>\n",
-                       tag, name, href, tag);
-          }
+                cauthor = entry->last_author;
+                cauthor = apr_xml_quote_string(entry_pool, cauthor, 1);
+                last_time = svn_time_to_human_cstring(entry->time,
+                                                      entry_pool);
+                last_time = apr_xml_quote_string(entry_pool,
+                                                 last_time, 1);
+                name = apr_xml_quote_string(entry_pool, name, 1);
+
+                /* ### This is where the we could search for props */
+
+                /* Patched by moseack */
+                ap_fprintf(output, bb,
+                           "    <file name=\"%s\" href=\"%s\" "
+                           "size=\"%" APR_INT64_T_FMT "\" cauthor=\"%s\" "
+                           "rev=\"%ld\" time=\"%s\"></file>\n",
+                           name, name, size, cauthor, rev, last_time);
+              }
+            }
          svn_pool_clear(entry_pool);
        }

Index: subversion/libsvn_repos/repos.c
===================================================================
--- subversion/libsvn_repos/repos.c	(revision 9929)
+++ subversion/libsvn_repos/repos.c	(working copy)
@@ -1335,3 +1335,69 @@
    return SVN_NO_ERROR;
  }

+
+/* Transform the hash table's FS entries into dirents.  This probably
+ * belongs in libsvn_repos. */
+svn_error_t *
+svn_repos_fs_ents_to_dirents(apr_hash_t *entries,
+                              svn_fs_root_t *root,
+                              const char *path,
+                              apr_pool_t *pool)
+{
+  const char *file_path, *name, *cauthor, *cdate;
+  apr_hash_t *file_props;
+  apr_hash_index_t *hi;
+  svn_dirent_t *entry;
+  svn_fs_dirent_t *fsent;
+  const void *key;
+  void *val;
+  apr_pool_t *subpool;
+
+  subpool = svn_pool_create(pool);
+
+  for (hi = apr_hash_first(pool, entries); hi; hi = apr_hash_next(hi))
+    {
+      apr_hash_this(hi, &key, NULL, &val);
+      name = key;
+      fsent = val;
+
+      file_path = svn_path_join(path, name, subpool);
+      entry = apr_pcalloc(pool, sizeof(*entry));
+
+      /* kind */
+      entry->kind = fsent->kind;
+
+      /* size */
+      if (entry->kind == svn_node_dir)
+        entry->size = 0;
+      else
+        SVN_ERR (svn_fs_file_length(&entry->size, root, file_path, subpool));
+
+      /* has_props */
+      SVN_ERR (svn_fs_node_proplist(&file_props, root, file_path, subpool));
+      entry->has_props = (apr_hash_count(file_props) > 0) ? TRUE : FALSE;
+
+      /* created_rev, last_author, time */
+      SVN_ERR (svn_repos_get_committed_info(&entry->created_rev, &cdate, 
&cauthor, root, file_path, subpool));
+      entry->last_author = apr_pstrdup(pool, cauthor);
+      if (cdate)
+        SVN_ERR (svn_time_from_cstring(&entry->time, cdate, subpool));
+      else
+        entry->time = (time_t) -1;
+
+      /* Store the entry. */
+      apr_hash_set(entries, name, APR_HASH_KEY_STRING, entry);
+      svn_pool_clear(subpool);
+    }
+  svn_pool_destroy(subpool);
+
+  for (hi = apr_hash_first(pool, entries); hi; hi = apr_hash_next(hi))
+    {
+      apr_hash_this(hi, &key, NULL, &val);
+      name = key;
+      entry = val;
+      cdate = (entry->time == (time_t) -1) ?
+        NULL : svn_time_to_cstring(entry->time, pool);
+    }
+  return SVN_NO_ERROR;
+}
Index: subversion/svnserve/serve.c
===================================================================
--- subversion/svnserve/serve.c	(revision 9929)
+++ subversion/svnserve/serve.c	(working copy)
@@ -19,6 +19,7 @@

  
  #define APR_WANT_STRFUNC
+#include <stdio.h>
  #include <apr_want.h>
  #include <apr_general.h>
  #include <apr_lib.h>
@@ -659,49 +660,8 @@
    if (want_contents)
      {
        SVN_CMD_ERR(svn_fs_dir_entries(&entries, root, full_path, pool));
-
-      /* Transform the hash table's FS entries into dirents.  This probably
-       * belongs in libsvn_repos. */
-      subpool = svn_pool_create(pool);
-      for (hi = apr_hash_first(pool, entries); hi; hi = apr_hash_next(hi))
-        {
-          apr_hash_this(hi, &key, NULL, &val);
-          name = key;
-          fsent = val;
-
-          file_path = svn_path_join(full_path, name, subpool);
-          entry = apr_pcalloc(pool, sizeof(*entry));
-
-          /* kind */
-          entry->kind = fsent->kind;
-
-          /* size */
-          if (entry->kind == svn_node_dir)
-            entry->size = 0;
-          else
-            SVN_CMD_ERR(svn_fs_file_length(&entry->size, root, file_path,
-                                           subpool));
-
-          /* has_props */
-          SVN_CMD_ERR(svn_fs_node_proplist(&file_props, root, file_path,
-                                           subpool));
-          entry->has_props = (apr_hash_count(file_props) > 0) ? TRUE : FALSE;
-
-          /* created_rev, last_author, time */
-          SVN_CMD_ERR(svn_repos_get_committed_info(&entry->created_rev, 
&cdate,
-                                                   &cauthor, root, file_path,
-                                                   subpool));
-          entry->last_author = apr_pstrdup(pool, cauthor);
-          if (cdate)
-            SVN_CMD_ERR(svn_time_from_cstring(&entry->time, cdate, subpool));
-          else
-            entry->time = (time_t) -1;
-
-          /* Store the entry. */
-          apr_hash_set(entries, name, APR_HASH_KEY_STRING, entry);
-          svn_pool_clear(subpool);
-        }
-      svn_pool_destroy(subpool);
+      SVN_CMD_ERR(svn_repos_fs_ents_to_dirents(entries, root,
+                                               full_path, pool));
      }

    /* Write out response. */
Index: tools/xslt/svnindex.xsl
===================================================================
--- tools/xslt/svnindex.xsl	(revision 9929)
+++ tools/xslt/svnindex.xsl	(working copy)
@@ -90,6 +90,17 @@
          </xsl:attribute>
          <xsl:value-of select="@name"/>
        </xsl:element>
+      <br/>
+      <small>
+        <xsl:text>size=</xsl:text>
+        <xsl:value-of select="@size"/>
+        <xsl:text>B, Rev:</xsl:text>
+        <xsl:value-of select="@rev"/>
+        <xsl:text>, By:</xsl:text>
+        <xsl:value-of select="@cauthor"/>
+        <xsl:text>, At:</xsl:text>
+        <xsl:value-of select="@time"/>
+      </small>
      </div>
      <!-- xsl:apply-templates/ -->
    </xsl:template>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Added dirent info to XML output from svnserve/get_dir

Posted by Michael W Thelen <th...@cs.utah.edu>.
* Refael Ackermann <mo...@netvision.net.il> [2004-06-05 19:07]:
> Index: subversion/include/svn_repos.h
> ===================================================================

Thanks for the patch, I've added it as issue #1936:
http://subversion.tigris.org/issues/show_bug.cgi?id=1936

-- Mike

-- 
Michael W. Thelen
Never attribute to malice what can be adequately explained by stupidity.
                -- Nick Diamos