[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Store remote host ip on commit

From: Sander Striker <striker_at_apache.org>
Date: 2002-07-18 00:01:55 CEST

Hi,

This patch adds functionality to subversion to obtain
the ip of the host where a commit is originating from.

Use 'svnlook ${REPOS} rev ${REV} remotehost' to see where
a commit came from. 'remotehost' will not be set when
it couldn't be determined (or when using ra_local).

It was a question by Eric Gillespie on irc that got me
to take a peek to see how much effort it was to implement.
Turned out to be not much effort.

Thoughts?

Sander

PS. Actual log msg not specified yet, simply seeking out
     opinions first.

Index: ./subversion/include/svn_types.h
===================================================================
--- ./subversion/include/svn_types.h
+++ ./subversion/include/svn_types.h Wed Jul 17 11:31:33 2002
@@ -249,6 +249,9 @@
 /* The fs revision property that stores a commit's date. */
 #define SVN_PROP_REVISION_DATE SVN_PROP_PREFIX "date"

+/* The fs revision property that stores a commit's originating host. */
+#define SVN_PROP_REVISION_REMOTEHOST SVN_PROP_PREFIX "remotehost"
+

 
Index: ./subversion/include/svn_repos.h
===================================================================
--- ./subversion/include/svn_repos.h
+++ ./subversion/include/svn_repos.h Wed Jul 17 09:56:28 2002
@@ -143,6 +143,7 @@
 svn_repos_begin_report (void **report_baton,
                         svn_revnum_t revnum,
                         const char *username,
+ const char *remotehost,
                         svn_repos_t *repos,
                         const char *fs_base,
                         const char *target,
@@ -373,7 +374,7 @@
                                       svn_revnum_t *new_rev,
                                       svn_fs_txn_t *txn);

-/* Like svn_fs_begin_txn(), but use AUTHOR and LOG_MSG to set the
+/* Like svn_fs_begin_txn(), but use REMOTEHOST, AUTHOR and LOG_MSG to set the
  * corresponding properties on transaction *TXN_P. REPOS is the
  * repository object which contains the filesystem. REV, *TXN_P, and
  * POOL are as in svn_fs_begin_txn().
@@ -388,13 +389,14 @@
                                                 svn_repos_t *repos,
                                                 svn_revnum_t rev,
                                                 const char *author,
+ const char *remotehost,
                                                 const char *log_msg,
                                                 apr_pool_t *pool);

-/* Like svn_fs_begin_txn(), but use AUTHOR to set the corresponding
- * property on transaction *TXN_P. REPOS is the repository object
- * which contains the filesystem. REV, *TXN_P, and POOL are as in
+/* Like svn_fs_begin_txn(), but use REMOTEHOST and AUTHOR to set the
+ * corresponding properties on transaction *TXN_P. REPOS is the repository
+ * object which contains the filesystem. REV, *TXN_P, and POOL are as in
  * svn_fs_begin_txn().
  *
  * ### Someday: before a txn is created, some kind of read-hook could
@@ -403,6 +405,7 @@
                                                 svn_repos_t *repos,
                                                 svn_revnum_t rev,
                                                 const char *author,
+ const char *remotehost,
                                                 apr_pool_t *pool);

Index: ./subversion/libsvn_ra_local/commit_editor.c
===================================================================
--- ./subversion/libsvn_ra_local/commit_editor.c
+++ ./subversion/libsvn_ra_local/commit_editor.c Wed Jul 17 09:56:28 2002
@@ -136,6 +136,7 @@
                                               eb->repos,
                                               base_revision,
                                               eb->user,
+ NULL,
                                               eb->log_msg,
                                               eb->pool));
   SVN_ERR (svn_fs_txn_root (&(eb->txn_root), eb->txn, eb->pool));
Index: ./subversion/libsvn_ra_local/ra_plugin.c
===================================================================
--- ./subversion/libsvn_ra_local/ra_plugin.c
+++ ./subversion/libsvn_ra_local/ra_plugin.c Wed Jul 17 09:56:28 2002
@@ -380,6 +380,7 @@
   SVN_ERR (svn_repos_begin_report (&rbaton,
                                    revnum_to_update_to,
                                    sbaton->username,
+ NULL,
                                    sbaton->repos,
                                    sbaton->fs_path,
                                    update_target,
@@ -438,6 +439,7 @@
   SVN_ERR (svn_repos_begin_report (&rbaton,
                                    revnum_to_update_to,
                                    sbaton->username,
+ NULL,
                                    sbaton->repos,
                                    sbaton->fs_path,
                                    update_target,
@@ -477,6 +479,7 @@
   SVN_ERR (svn_repos_begin_report (&rbaton,
                                    revnum_to_update_to,
                                    sbaton->username,
+ NULL,
                                    sbaton->repos,
                                    sbaton->fs_path,
                                    status_target,
Index: ./subversion/svnlook/main.c
===================================================================
--- ./subversion/svnlook/main.c
+++ ./subversion/svnlook/main.c Wed Jul 17 10:23:56 2002
@@ -51,6 +51,7 @@
   svnlook_cmd_default = 0,

   svnlook_cmd_author,
+ svnlook_cmd_remotehost,
   svnlook_cmd_changed,
   svnlook_cmd_date,
   svnlook_cmd_diff,
@@ -59,7 +60,7 @@
   svnlook_cmd_info,
   svnlook_cmd_log,
   svnlook_cmd_tree
-
+
 } svnlook_cmd_t;

@@ -769,7 +770,6 @@
   return SVN_NO_ERROR;
 }

-
 /* Print the author of the commit to stdout, followed by a newline. */
 static svn_error_t *
 do_author (svnlook_ctxt_t *c, apr_pool_t *pool)
@@ -790,6 +790,26 @@
 }

+/* Print the originating host of the commit to stdout, followed by a newline. */
+static svn_error_t *
+do_remotehost (svnlook_ctxt_t *c, apr_pool_t *pool)
+{
+ svn_string_t *prop_value;
+
+ SVN_ERR (get_property (&prop_value, c, SVN_PROP_REVISION_REMOTEHOST, pool));
+
+ if (prop_value && prop_value->data) {
+ const char *remotehost_native;
+ SVN_ERR (svn_utf_cstring_from_utf8 (&remotehost_native, prop_value->data,
+ pool));
+ printf ("%s", remotehost_native);
+ }
+
+ printf ("\n");
+ return SVN_NO_ERROR;
+}
+
+
 /* Print a list of all directories in which files, or directory
    properties, have been modified. */
 static svn_error_t *
@@ -932,7 +952,6 @@
 }

-
 
 /*** Argument parsing and usage. ***/
 static void
@@ -953,6 +972,7 @@
      "COMMAND can be one of: \n"
      "\n"
      " author: print author.\n"
+ " remotehost: print the orignating host.\n"
      " changed: print full change summary: all dirs & files changed.\n"
      " date: print the timestamp (revisions only).\n"
      " diff: print GNU-style diffs of changed files and props.\n"
@@ -1047,6 +1067,8 @@
     {
       if (! strcmp (argv[cmd_offset], "author"))
         command = svnlook_cmd_author;
+ else if (! strcmp (argv[cmd_offset], "remotehost"))
+ command = svnlook_cmd_remotehost;
       else if (! strcmp (argv[cmd_offset], "changed"))
         command = svnlook_cmd_changed;
       else if (! strcmp (argv[cmd_offset], "date"))
@@ -1104,6 +1126,10 @@
     {
     case svnlook_cmd_author:
       INT_ERR (do_author (&c, pool));
+ break;
+
+ case svnlook_cmd_remotehost:
+ INT_ERR (do_remotehost (&c, pool));
       break;

     case svnlook_cmd_changed:
Index: ./subversion/mod_dav_svn/update.c
===================================================================
--- ./subversion/mod_dav_svn/update.c
+++ ./subversion/mod_dav_svn/update.c Wed Jul 17 09:56:28 2002
@@ -660,7 +660,8 @@
      dir_delta() between REPOS_PATH/TARGET and TARGET_PATH. In the
      case of an update or status, these paths should be identical. In
      the case of a switch, they should be different. */
- if ((serr = svn_repos_begin_report(&rbaton, revnum, repos->username,
+ if ((serr = svn_repos_begin_report(&rbaton, revnum,
+ repos->username, repos->remotehost,
                                      repos->repos,
                                      resource->info->repos_path, target,
                                      dst_path,
Index: ./subversion/mod_dav_svn/dav_svn.h
===================================================================
--- ./subversion/mod_dav_svn/dav_svn.h
+++ ./subversion/mod_dav_svn/dav_svn.h Wed Jul 17 10:05:26 2002
@@ -92,6 +92,9 @@
   /* the user operating against this repository */
   const char *username;

+ /* the host the operation is originating from */
+ const char *remotehost;
+
 } dav_svn_repos;

Index: ./subversion/mod_dav_svn/repos.c
===================================================================
--- ./subversion/mod_dav_svn/repos.c
+++ ./subversion/mod_dav_svn/repos.c Wed Jul 17 11:57:32 2002
@@ -942,6 +942,10 @@
   repos->base_url = ap_construct_url(r->pool, "", r);
   repos->special_uri = dav_svn_get_special_uri(r);

+ /* Remember where this request is coming from */
+ repos->remotehost = ap_get_remote_host(r->connection, r->per_dir_config,
+ REMOTE_NOLOOKUP, NULL);
+
   /* Remember who is making this request */
   if ((repos->username = r->user) == NULL)
     repos->username = "anonymous";
Index: ./subversion/mod_dav_svn/activity.c
===================================================================
--- ./subversion/mod_dav_svn/activity.c
+++ ./subversion/mod_dav_svn/activity.c Wed Jul 17 09:56:28 2002
@@ -123,7 +123,8 @@
     }

   serr = svn_repos_fs_begin_txn_for_commit(&txn, repos->repos, rev,
- repos->username, NULL, pool);
+ repos->username, repos->remotehost,
+ NULL, pool);
   if (serr != NULL)
     {
       return dav_svn_convert_err(serr, HTTP_INTERNAL_SERVER_ERROR,
Index: ./subversion/libsvn_repos/reporter.c
===================================================================
--- ./subversion/libsvn_repos/reporter.c
+++ ./subversion/libsvn_repos/reporter.c Wed Jul 17 09:56:28 2002
@@ -37,6 +37,9 @@
   svn_fs_txn_t *txn2;
   svn_fs_root_t *txn2_root;

+ /* Which host is the update originating from */
+ const char *remotehost;
+
   /* Which user is doing the update (building the temporary txn) */
   const char *username;

@@ -167,6 +170,7 @@
                                                   rbaton->repos,
                                                   revision,
                                                   rbaton->username,
+ rbaton->remotehost,
                                                   rbaton->pool));
       SVN_ERR (svn_fs_txn_root (&(rbaton->txn_root), rbaton->txn,
                                 rbaton->pool));
@@ -233,6 +237,7 @@
                                                   rbaton->repos,
                                                   rbaton->revnum_to_update_to,
                                                   rbaton->username,
+ rbaton->remotehost,
                                                   rbaton->pool));
       SVN_ERR (svn_fs_txn_root (&(rbaton->txn2_root), rbaton->txn2,
                                 rbaton->pool));
@@ -386,6 +391,7 @@
 svn_repos_begin_report (void **report_baton,
                         svn_revnum_t revnum,
                         const char *username,
+ const char *remotehost,
                         svn_repos_t *repos,
                         const char *fs_base,
                         const char *target,
@@ -411,6 +417,7 @@
   /* Copy these since we're keeping them past the end of this function call.
      We don't know what the caller might do with them after we return... */
   rbaton->username = apr_pstrdup (pool, username);
+ rbaton->remotehost = remotehost ? apr_pstrdup (pool, remotehost) : NULL;
   rbaton->base_path = apr_pstrdup (pool, fs_base);
   rbaton->target = target ? apr_pstrdup (pool, target) : NULL;
   rbaton->tgt_path = tgt_path ? apr_pstrdup (pool, tgt_path) : NULL;
Index: ./subversion/libsvn_repos/hooks.c
===================================================================
--- ./subversion/libsvn_repos/hooks.c
+++ ./subversion/libsvn_repos/hooks.c Wed Jul 17 10:08:41 2002
@@ -211,6 +211,7 @@
                                    svn_repos_t *repos,
                                    svn_revnum_t rev,
                                    const char *author,
+ const char *remotehost,
                                    const char *log_msg,
                                    apr_pool_t *pool)
 {
@@ -233,7 +234,18 @@
       SVN_ERR (svn_fs_change_txn_prop (*txn_p, SVN_PROP_REVISION_AUTHOR,
                                        &val, pool));
     }
-
+
+ /* Host (originating). */
+ if (remotehost != NULL)
+ {
+ svn_string_t val;
+ val.data = remotehost;
+ val.len = strlen (remotehost);
+
+ SVN_ERR (svn_fs_change_txn_prop (*txn_p, SVN_PROP_REVISION_REMOTEHOST,
+ &val, pool));
+ }
+
     /* Log message. */
     if (log_msg != NULL)
       {
@@ -264,6 +276,7 @@
                                    svn_repos_t *repos,
                                    svn_revnum_t rev,
                                    const char *author,
+ const char *remotehost,
                                    apr_pool_t *pool)
 {
   /* ### someday, we might run a read-hook here. */
@@ -282,7 +295,18 @@

       SVN_ERR (svn_fs_change_txn_prop (*txn_p, SVN_PROP_REVISION_AUTHOR,
                                        &val, pool));
- }
+ }
+
+ /* Host (originating). */
+ if (remotehost != NULL)
+ {
+ svn_string_t val;
+ val.data = remotehost;
+ val.len = strlen (remotehost);
+
+ SVN_ERR (svn_fs_change_txn_prop (*txn_p, SVN_PROP_REVISION_REMOTEHOST,
+ &val, pool));
+ }
   }

   return SVN_NO_ERROR;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jul 17 23:52:51 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.