Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 11, 2016
0 parents commit c0f9aa0
Show file tree
Hide file tree
Showing 37 changed files with 1,195 additions and 0 deletions.
Binary file added 3232.pdf
Binary file not shown.
Binary file added 3233.pdf
Binary file not shown.
Binary file added 9781590597538.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2007 Garrett Rooney and Daniel Berlin

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
#Apress Source Code

This repository accompanies [*Practical Subversion*](http://www.apress.com/9781590597538) by Garrett Rooney and Daniel Berlin (Apress, 2007).

![Cover image](9781590597538.jpg)

Download the files as a zip using the green button, or clone the repository to your machine using Git.

##Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

##Contributions

See the file Contributing.md for more information on how you can contribute to this repository.
14 changes: 14 additions & 0 deletions contributing.md
@@ -0,0 +1,14 @@
# Contributing to Apress Source Code

Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.

## How to Contribute

1. Make sure you have a GitHub account.
2. Fork the repository for the relevant book.
3. Create a new branch on which to make your change, e.g.
`git checkout -b my_code_contribution`
4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
5. Submit a pull request.

Thank you for your contribution!
@@ -0,0 +1,5 @@
This tarball contains the source code to the examples in chapter 8 of
Practical Subversion. The C examples have been modified to add some
includes of necessary headers and declaration of necessary functions,
but other than that should be unchanged from the version found in the
book.
@@ -0,0 +1,16 @@
#include <apr.h>
#include <apr_file_io.h>

void
parse_file (const char *filename, apr_pool_t *pool)
{
apr_file_t *file;
apr_status_t err;

err = apr_file_open (&file, filename, 0, APR_OS_DEFAULT, pool);
if (err) {
/* couldn't open the file, so handle the error somehow */
} else {
/* it succeeded, so we continue on parsing the contents of the file */
}
}
@@ -0,0 +1,33 @@
#include <apr.h>
#include <apr_tables.h>

void
demonstrate_apr_arrays (apr_pool_t *pool)
{
int i;

/* make an array with 2 slots in it */
apr_array_header_t *array = apr_array_make (pool, 2, sizeof (char *));

/* push two strings onto the array */
(*(char **) apr_array_push (array)) = "foo";
(*(char **) apr_array_push (array)) = "bar";

/* push another one on, this causes the extra spot to be allocated */
(*(char **) apr_array_push (array)) = "baz";

/* iterate over them */
for (i = 0; i < array->nelts; ++i)
{
printf ("%s\n", ((char **) array->elts)[i]);
}

{
/* try to pop off the first item */
char *item = apr_array_pop (array);
if (item)
{
/* use it */
}
}
}
@@ -0,0 +1,128 @@
#include <svn_auth.h>
#include <svn_types.h>
#include <svn_error.h>
#include <svn_client.h>

/* prompt the user for a username and password */
static svn_error_t *
simple_prompt_callback (svn_auth_cred_simple_t **cred,
void *baton,
const char *realm,
const char *username,
svn_boolean_t may_save,
apr_pool_t *pool)
{
svn_auth_cred_simple_t *ret = apr_pcalloc (pool, sizeof (*ret));
size_t len;
char *line;

/* tell the user what the repository realm is, so he knows what username
he should enter. */
if (realm)
printf ("Realm: %s\n", realm);

/* if we were passed a username, that means subversion had one cached for
this realm already, so use that. */
if (username)
ret->username = apr_pstrdup (pool, username);
else
{
/* we didn't have a username, so prompt the user to enter one. */
printf ("Username? : ");

/* read in the username the user entered */
line = fgetln (stdin, &len);

/* assuming the user entered something copy it into our final
svn_auth_cred_simple_t structure so we can return it. */
if (line)
{
ret->username = apr_palloc (pool, len);
snprintf (ret->username, len - 1, line);
}
}

/* now we do the same thing for the user's password... */
printf ("Password? : ");

line = fgetln (stdin, &len);

if (line)
{
ret->password = apr_palloc (pool, len);
snprintf (ret->password, len - 1, line);
}

/* return the svn_auth_cred_simple_t by reference. */
*cred = ret;

return SVN_NO_ERROR;
}

/* similar to the previous function, but just prompts for a username */
static svn_error_t *
username_prompt_callback (svn_auth_cred_username_t **cred,
void *baton,
const char *realm,
svn_boolean_t may_save,
apr_pool_t *pool)
{
svn_auth_cred_simple_t *ret = apr_pcalloc (pool, sizeof (*ret));
size_t len;
char *line;

if (realm)
printf ("Realm: %s\n", realm);

printf ("Username? : ");

line = fgetln (stdin, &len);

if (line)
{
ret->username = apr_palloc (pool, len);
snprintf (ret->username, len - 1, line);
}

*cred = ret;

return SVN_NO_ERROR;
}

/* build authentication providers that use our prompting functions and add
them to a client context. */
static svn_error_t *
set_up_auth (svn_client_ctx_t *ctx, apr_pool_t *pool)
{
svn_auth_provider_object_t *provider;

/* create an array to hold our two providers. */
apr_array_header_t *providers
= apr_array_make (pool, 2, sizeof (svn_auth_provider_object_t *));

/* create the svn.simple provider. */
svn_client_get_simple_prompt_provider (&provider,
simple_prompt_callback,
NULL, /* the baton goes here */
2, /* number of times to retry */
pool);

/* add it to the array. */
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;

/* create the svn.username provider. */
svn_client_get_username_prompt_provider (&provider,
username_prompt_callback,
NULL, /* the baton goes here */
2, /* number of times to retry */
pool);

/* add it to the array. */
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;

/* now that we've got the array of providers, use them to create our auth
baton. */
svn_auth_open (&ctx->auth_baton, providers, pool);

return SVN_NO_ERROR;
}
@@ -0,0 +1,37 @@
#include <svn_types.h>
#include <svn_error.h>
#include <svn_error_codes.h>
#include <svn_client.h>

static volatile sig_atomic_t been_cancelled = FALSE;

static void
signal_handler (int unused)
{
been_cancelled = TRUE;
}

svn_error_t *
cancellation_callback (void *baton)
{
if (been_cancelled)
return svn_error_create (SVN_ERR_CANCELLED, NULL, "Caught signal");
else
return SVN_NO_ERROR;
}

svn_error_t *
set_up_cancellation (svn_client_ctx_t *ctx, apr_pool_t *pool)
{
apr_signal (SIGINT, signal_handler);

ctx->cancel_func = cancellation_callback;

/* in a more complex application with multiple operations in progress at
* once, we'd set this to whatever data the callback would need to look at
* to determine if the action this context is being used for was cancelled.
*/
ctx->cancel_baton = NULL;

return SVN_NO_ERROR;
}
@@ -0,0 +1,107 @@
#include <svn_repos.h>

svn_error_t *empty_uuid_record_function (const char *uuid,
void *parse_baton,
apr_pool_t *pool);
svn_error_t *empty_set_revision_property_function (void *revision_baton,
const char *name,
const svn_string_t *value);
svn_error_t *empty_set_node_property_function (void *node_baton,
const char *name,
const svn_string_t *value);
svn_error_t *empty_remove_node_props (void *node_baton);
svn_error_t *empty_close_node_function (void *node_baton);
svn_error_t *empty_close_revision_function (void *node_baton);
svn_error_t *empty_delete_node_property (void *node_baton, const char *name);

/* A baton to hold the path we're looking for and the current count. */
struct count_baton {
const char *path;
int count;
};

/* callback to be called at the start of each revision */
svn_error_t *
new_revision_record (void **revision_baton,
apr_hash_t *headers,
void *parse_baton,
apr_pool_t *pool)
{
/* the only state we need to keep is in the parse_baton, so we'll treat the
revision baton and the parse baton as the same thing. */
*revision_baton = parse_baton;

return SVN_NO_ERROR;
}

/* callback to be called for each new node */
svn_error_t *
new_node_record (void **node_baton,
apr_hash_t *headers,
void *revision_baton,
apr_pool_t *pool)
{
struct count_baton *cb = revision_baton;

/* grab the filename out of the headers */
const char *filename = apr_hash_get (headers, SVN_REPOS_DUMPFILE_NODE_PATH,
APR_HASH_KEY_STRING);

/* if it matches the path we're looking for, increment our count */
if (filename && strcmp (filename, cb->path) == 0)
{
cb->count++;
}

return SVN_NO_ERROR;
}

/* callback to be called when we get to the fulltext of each file */
svn_error_t *
set_fulltext (svn_stream_t **stream,
void *node_baton)
{
/* we don't care about the content of the file, so we return a NULL stream */
*stream = NULL;

return SVN_NO_ERROR;
}

/* count the number of times a particular file is modified in a dumpfile */
svn_error_t *
count_times_modified (const char *path,
svn_stream_t *dumpfile,
apr_pool_t *pool)
{
struct count_baton cb;
struct svn_repos_parse_fns_t parser_fns;

/* initialize our count baton */
cb.path = path;
cb.count = 0;

/* fill in the parser function callbacks.
*
* Note: The empty functions used for uninteresting callbacks have not been
* included to save space. Just assume all they do is return SVN_NO_ERROR.
*/
parser_fns.new_revision_record = new_revision_record;
parser_fns.uuid_record = empty_uuid_record_function;
parser_fns.new_node_record = new_node_record;
parser_fns.set_revision_property = empty_set_revision_property_function;
parser_fns.set_node_property = empty_set_node_property_function;
parser_fns.delete_node_property = empty_delete_node_property;
parser_fns.remove_node_props = empty_remove_node_props;
parser_fns.set_fulltext = set_fulltext;
parser_fns.apply_textdelta = NULL;
parser_fns.close_node = empty_close_node_function;
parser_fns.close_revision = empty_close_revision_function;

/* parse the dumpstream using our callback functions and count baton */
SVN_ERR (svn_repos_parse_dumpstream (dumpfile, &parser_fns, &cb,
NULL, NULL, pool));

printf ("%s changed %d times in the dumpfile\n", cb.path, cb.count);

return SVN_NO_ERROR;
}

0 comments on commit c0f9aa0

Please sign in to comment.