1/*
2 * old-and-busted.c:  routines for reading pre-1.7 working copies.
3 *
4 * ====================================================================
5 *    Licensed to the Apache Software Foundation (ASF) under one
6 *    or more contributor license agreements.  See the NOTICE file
7 *    distributed with this work for additional information
8 *    regarding copyright ownership.  The ASF licenses this file
9 *    to you under the Apache License, Version 2.0 (the
10 *    "License"); you may not use this file except in compliance
11 *    with the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 *    Unless required by applicable law or agreed to in writing,
16 *    software distributed under the License is distributed on an
17 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 *    KIND, either express or implied.  See the License for the
19 *    specific language governing permissions and limitations
20 *    under the License.
21 * ====================================================================
22 */
23
24
25
26#include "svn_time.h"
27#include "svn_xml.h"
28#include "svn_dirent_uri.h"
29#include "svn_hash.h"
30#include "svn_path.h"
31#include "svn_ctype.h"
32#include "svn_pools.h"
33
34#include "wc.h"
35#include "adm_files.h"
36#include "entries.h"
37#include "lock.h"
38
39#include "private/svn_wc_private.h"
40#include "svn_private_config.h"
41
42
43/* Within the (old) entries file, boolean values have a specific string
44   value (thus, TRUE), or they are missing (for FALSE). Below are the
45   values for each of the booleans stored.  */
46#define ENTRIES_BOOL_COPIED     "copied"
47#define ENTRIES_BOOL_DELETED    "deleted"
48#define ENTRIES_BOOL_ABSENT     "absent"
49#define ENTRIES_BOOL_INCOMPLETE "incomplete"
50#define ENTRIES_BOOL_KEEP_LOCAL "keep-local"
51
52/* Tag names used in our old XML entries file.  */
53#define ENTRIES_TAG_ENTRY "entry"
54
55/* Attribute names used in our old XML entries file.  */
56#define ENTRIES_ATTR_NAME               "name"
57#define ENTRIES_ATTR_REPOS              "repos"
58#define ENTRIES_ATTR_UUID               "uuid"
59#define ENTRIES_ATTR_INCOMPLETE         "incomplete"
60#define ENTRIES_ATTR_LOCK_TOKEN         "lock-token"
61#define ENTRIES_ATTR_LOCK_OWNER         "lock-owner"
62#define ENTRIES_ATTR_LOCK_COMMENT       "lock-comment"
63#define ENTRIES_ATTR_LOCK_CREATION_DATE "lock-creation-date"
64#define ENTRIES_ATTR_DELETED            "deleted"
65#define ENTRIES_ATTR_ABSENT             "absent"
66#define ENTRIES_ATTR_CMT_REV            "committed-rev"
67#define ENTRIES_ATTR_CMT_DATE           "committed-date"
68#define ENTRIES_ATTR_CMT_AUTHOR         "last-author"
69#define ENTRIES_ATTR_REVISION           "revision"
70#define ENTRIES_ATTR_URL                "url"
71#define ENTRIES_ATTR_KIND               "kind"
72#define ENTRIES_ATTR_SCHEDULE           "schedule"
73#define ENTRIES_ATTR_COPIED             "copied"
74#define ENTRIES_ATTR_COPYFROM_URL       "copyfrom-url"
75#define ENTRIES_ATTR_COPYFROM_REV       "copyfrom-rev"
76#define ENTRIES_ATTR_CHECKSUM           "checksum"
77#define ENTRIES_ATTR_WORKING_SIZE       "working-size"
78#define ENTRIES_ATTR_TEXT_TIME          "text-time"
79#define ENTRIES_ATTR_CONFLICT_OLD       "conflict-old" /* saved old file */
80#define ENTRIES_ATTR_CONFLICT_NEW       "conflict-new" /* saved new file */
81#define ENTRIES_ATTR_CONFLICT_WRK       "conflict-wrk" /* saved wrk file */
82#define ENTRIES_ATTR_PREJFILE           "prop-reject-file"
83
84/* Attribute values used in our old XML entries file.  */
85#define ENTRIES_VALUE_FILE     "file"
86#define ENTRIES_VALUE_DIR      "dir"
87#define ENTRIES_VALUE_ADD      "add"
88#define ENTRIES_VALUE_DELETE   "delete"
89#define ENTRIES_VALUE_REPLACE  "replace"
90
91
92/* */
93static svn_wc_entry_t *
94alloc_entry(apr_pool_t *pool)
95{
96  svn_wc_entry_t *entry = apr_pcalloc(pool, sizeof(*entry));
97  entry->revision = SVN_INVALID_REVNUM;
98  entry->copyfrom_rev = SVN_INVALID_REVNUM;
99  entry->cmt_rev = SVN_INVALID_REVNUM;
100  entry->kind = svn_node_none;
101  entry->working_size = SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN;
102  entry->depth = svn_depth_infinity;
103  entry->file_external_path = NULL;
104  entry->file_external_peg_rev.kind = svn_opt_revision_unspecified;
105  entry->file_external_rev.kind = svn_opt_revision_unspecified;
106  return entry;
107}
108
109
110
111/* Read an escaped byte on the form 'xHH' from [*BUF, END), placing
112   the byte in *RESULT.  Advance *BUF to point after the escape
113   sequence. */
114static svn_error_t *
115read_escaped(char *result, char **buf, const char *end)
116{
117  apr_uint64_t val;
118  char digits[3];
119
120  if (end - *buf < 3 || **buf != 'x' || ! svn_ctype_isxdigit((*buf)[1])
121      || ! svn_ctype_isxdigit((*buf)[2]))
122    return svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
123                            _("Invalid escape sequence"));
124  (*buf)++;
125  digits[0] = *((*buf)++);
126  digits[1] = *((*buf)++);
127  digits[2] = 0;
128  if ((val = apr_strtoi64(digits, NULL, 16)) == 0)
129    return svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
130                            _("Invalid escaped character"));
131  *result = (char) val;
132  return SVN_NO_ERROR;
133}
134
135/* Read a field, possibly with escaped bytes, from [*BUF, END),
136   stopping at the terminator.  Place the read string in *RESULT, or set
137   *RESULT to NULL if it is the empty string.  Allocate the returned string
138   in POOL.  Advance *BUF to point after the terminator. */
139static svn_error_t *
140read_str(const char **result,
141         char **buf, const char *end,
142         apr_pool_t *pool)
143{
144  svn_stringbuf_t *s = NULL;
145  const char *start;
146  if (*buf == end)
147    return svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
148                            _("Unexpected end of entry"));
149  if (**buf == '\n')
150    {
151      *result = NULL;
152      (*buf)++;
153      return SVN_NO_ERROR;
154    }
155
156  start = *buf;
157  while (*buf != end && **buf != '\n')
158    {
159      if (**buf == '\\')
160        {
161          char c;
162          if (! s)
163            s = svn_stringbuf_ncreate(start, *buf - start, pool);
164          else
165            svn_stringbuf_appendbytes(s, start, *buf - start);
166          (*buf)++;
167          SVN_ERR(read_escaped(&c, buf, end));
168          svn_stringbuf_appendbyte(s, c);
169          start = *buf;
170        }
171      else
172        (*buf)++;
173    }
174
175  if (*buf == end)
176    return svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
177                            _("Unexpected end of entry"));
178
179  if (s)
180    {
181      svn_stringbuf_appendbytes(s, start, *buf - start);
182      *result = s->data;
183    }
184  else
185    *result = apr_pstrndup(pool, start, *buf - start);
186  (*buf)++;
187  return SVN_NO_ERROR;
188}
189
190/* This is wrapper around read_str() (which see for details); it
191   simply asks svn_path_is_canonical() of the string it reads,
192   returning an error if the test fails.
193   ### It seems this is only called for entrynames now
194   */
195static svn_error_t *
196read_path(const char **result,
197          char **buf, const char *end,
198          apr_pool_t *pool)
199{
200  SVN_ERR(read_str(result, buf, end, pool));
201  if (*result && **result && !svn_relpath_is_canonical(*result))
202    return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
203                             _("Entry contains non-canonical path '%s'"),
204                             *result);
205  return SVN_NO_ERROR;
206}
207
208/* This is read_path() for urls. This function does not do the is_canonical
209   test for entries from working copies older than version 10, as since that
210   version the canonicalization of urls has been changed. See issue #2475.
211   If the test is done and fails, read_url returs an error. */
212static svn_error_t *
213read_url(const char **result,
214         char **buf, const char *end,
215         int wc_format,
216         apr_pool_t *pool)
217{
218  SVN_ERR(read_str(result, buf, end, pool));
219
220  /* Always canonicalize the url, as we have stricter canonicalization rules
221     in 1.7+ then before */
222  if (*result && **result)
223    *result = svn_uri_canonicalize(*result, pool);
224
225  return SVN_NO_ERROR;
226}
227
228/* Read a field from [*BUF, END), terminated by a newline character.
229   The field may not contain escape sequences.  The field is not
230   copied and the buffer is modified in place, by replacing the
231   terminator with a NUL byte.  Make *BUF point after the original
232   terminator. */
233static svn_error_t *
234read_val(const char **result,
235          char **buf, const char *end)
236{
237  const char *start = *buf;
238
239  if (*buf == end)
240    return svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
241                            _("Unexpected end of entry"));
242  if (**buf == '\n')
243    {
244      (*buf)++;
245      *result = NULL;
246      return SVN_NO_ERROR;
247    }
248
249  while (*buf != end && **buf != '\n')
250    (*buf)++;
251  if (*buf == end)
252    return svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
253                            _("Unexpected end of entry"));
254  **buf = '\0';
255  *result = start;
256  (*buf)++;
257  return SVN_NO_ERROR;
258}
259
260/* Read a boolean field from [*BUF, END), placing the result in
261   *RESULT.  If there is no boolean value (just a terminator), it
262   defaults to false.  Else, the value must match FIELD_NAME, in which
263   case *RESULT will be set to true.  Advance *BUF to point after the
264   terminator. */
265static svn_error_t *
266read_bool(svn_boolean_t *result, const char *field_name,
267          char **buf, const char *end)
268{
269  const char *val;
270  SVN_ERR(read_val(&val, buf, end));
271  if (val)
272    {
273      if (strcmp(val, field_name) != 0)
274        return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
275                                 _("Invalid value for field '%s'"),
276                                 field_name);
277      *result = TRUE;
278    }
279  else
280    *result = FALSE;
281  return SVN_NO_ERROR;
282}
283
284/* Read a revision number from [*BUF, END) stopping at the
285   terminator.  Set *RESULT to the revision number, or
286   SVN_INVALID_REVNUM if there is none.  Use POOL for temporary
287   allocations.  Make *BUF point after the terminator.  */
288static svn_error_t *
289read_revnum(svn_revnum_t *result,
290            char **buf,
291            const char *end,
292            apr_pool_t *pool)
293{
294  const char *val;
295
296  SVN_ERR(read_val(&val, buf, end));
297
298  if (val)
299    *result = SVN_STR_TO_REV(val);
300  else
301    *result = SVN_INVALID_REVNUM;
302
303  return SVN_NO_ERROR;
304}
305
306/* Read a timestamp from [*BUF, END) stopping at the terminator.
307   Set *RESULT to the resulting timestamp, or 0 if there is none.  Use
308   POOL for temporary allocations.  Make *BUF point after the
309   terminator. */
310static svn_error_t *
311read_time(apr_time_t *result,
312          char **buf, const char *end,
313          apr_pool_t *pool)
314{
315  const char *val;
316
317  SVN_ERR(read_val(&val, buf, end));
318  if (val)
319    SVN_ERR(svn_time_from_cstring(result, val, pool));
320  else
321    *result = 0;
322
323  return SVN_NO_ERROR;
324}
325
326/**
327 * Parse the string at *STR as an revision and save the result in
328 * *OPT_REV.  After returning successfully, *STR points at next
329 * character in *STR where further parsing can be done.
330 */
331static svn_error_t *
332string_to_opt_revision(svn_opt_revision_t *opt_rev,
333                       const char **str,
334                       apr_pool_t *pool)
335{
336  const char *s = *str;
337
338  SVN_ERR_ASSERT(opt_rev);
339
340  while (*s && *s != ':')
341    ++s;
342
343  /* Should not find a \0. */
344  if (!*s)
345    return svn_error_createf
346      (SVN_ERR_INCORRECT_PARAMS, NULL,
347       _("Found an unexpected \\0 in the file external '%s'"), *str);
348
349  if (0 == strncmp(*str, "HEAD:", 5))
350    {
351      opt_rev->kind = svn_opt_revision_head;
352    }
353  else
354    {
355      svn_revnum_t rev;
356      const char *endptr;
357
358      SVN_ERR(svn_revnum_parse(&rev, *str, &endptr));
359      SVN_ERR_ASSERT(endptr == s);
360      opt_rev->kind = svn_opt_revision_number;
361      opt_rev->value.number = rev;
362    }
363
364  *str = s + 1;
365
366  return SVN_NO_ERROR;
367}
368
369/**
370 * Given a revision, return a string for the revision, either "HEAD"
371 * or a string representation of the revision value.  All other
372 * revision kinds return an error.
373 */
374static svn_error_t *
375opt_revision_to_string(const char **str,
376                       const char *path,
377                       const svn_opt_revision_t *rev,
378                       apr_pool_t *pool)
379{
380  switch (rev->kind)
381    {
382    case svn_opt_revision_head:
383      *str = apr_pstrmemdup(pool, "HEAD", 4);
384      break;
385    case svn_opt_revision_number:
386      *str = apr_ltoa(pool, rev->value.number);
387      break;
388    default:
389      return svn_error_createf
390        (SVN_ERR_INCORRECT_PARAMS, NULL,
391         _("Illegal file external revision kind %d for path '%s'"),
392         rev->kind, path);
393      break;
394    }
395
396  return SVN_NO_ERROR;
397}
398
399svn_error_t *
400svn_wc__unserialize_file_external(const char **path_result,
401                                  svn_opt_revision_t *peg_rev_result,
402                                  svn_opt_revision_t *rev_result,
403                                  const char *str,
404                                  apr_pool_t *pool)
405{
406  if (str)
407    {
408      svn_opt_revision_t peg_rev;
409      svn_opt_revision_t op_rev;
410      const char *s = str;
411
412      SVN_ERR(string_to_opt_revision(&peg_rev, &s, pool));
413      SVN_ERR(string_to_opt_revision(&op_rev, &s, pool));
414
415      *path_result = apr_pstrdup(pool, s);
416      *peg_rev_result = peg_rev;
417      *rev_result = op_rev;
418    }
419  else
420    {
421      *path_result = NULL;
422      peg_rev_result->kind = svn_opt_revision_unspecified;
423      rev_result->kind = svn_opt_revision_unspecified;
424    }
425
426  return SVN_NO_ERROR;
427}
428
429svn_error_t *
430svn_wc__serialize_file_external(const char **str,
431                                const char *path,
432                                const svn_opt_revision_t *peg_rev,
433                                const svn_opt_revision_t *rev,
434                                apr_pool_t *pool)
435{
436  const char *s;
437
438  if (path)
439    {
440      const char *s1;
441      const char *s2;
442
443      SVN_ERR(opt_revision_to_string(&s1, path, peg_rev, pool));
444      SVN_ERR(opt_revision_to_string(&s2, path, rev, pool));
445
446      s = apr_pstrcat(pool, s1, ":", s2, ":", path, (char *)NULL);
447    }
448  else
449    s = NULL;
450
451  *str = s;
452
453  return SVN_NO_ERROR;
454}
455
456/* Allocate an entry from POOL and read it from [*BUF, END).  The
457   buffer may be modified in place while parsing.  Return the new
458   entry in *NEW_ENTRY.  Advance *BUF to point at the end of the entry
459   record.
460   The entries file format should be provided in ENTRIES_FORMAT. */
461static svn_error_t *
462read_entry(svn_wc_entry_t **new_entry,
463           char **buf, const char *end,
464           int entries_format,
465           apr_pool_t *pool)
466{
467  svn_wc_entry_t *entry = alloc_entry(pool);
468  const char *name;
469
470#define MAYBE_DONE if (**buf == '\f') goto done
471
472  /* Find the name and set up the entry under that name. */
473  SVN_ERR(read_path(&name, buf, end, pool));
474  entry->name = name ? name : SVN_WC_ENTRY_THIS_DIR;
475
476  /* Set up kind. */
477  {
478    const char *kindstr;
479    SVN_ERR(read_val(&kindstr, buf, end));
480    if (kindstr)
481      {
482        if (strcmp(kindstr, ENTRIES_VALUE_FILE) == 0)
483          entry->kind = svn_node_file;
484        else if (strcmp(kindstr, ENTRIES_VALUE_DIR) == 0)
485          entry->kind = svn_node_dir;
486        else
487          return svn_error_createf
488            (SVN_ERR_NODE_UNKNOWN_KIND, NULL,
489             _("Entry '%s' has invalid node kind"),
490             (name ? name : SVN_WC_ENTRY_THIS_DIR));
491      }
492    else
493      entry->kind = svn_node_none;
494  }
495  MAYBE_DONE;
496
497  /* Attempt to set revision (resolve_to_defaults may do it later, too) */
498  SVN_ERR(read_revnum(&entry->revision, buf, end, pool));
499  MAYBE_DONE;
500
501  /* Attempt to set up url path (again, see resolve_to_defaults). */
502  SVN_ERR(read_url(&entry->url, buf, end, entries_format, pool));
503  MAYBE_DONE;
504
505  /* Set up repository root.  Make sure it is a prefix of url. */
506  SVN_ERR(read_url(&entry->repos, buf, end, entries_format, pool));
507  if (entry->repos && entry->url
508      && ! svn_uri__is_ancestor(entry->repos, entry->url))
509    return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
510                             _("Entry for '%s' has invalid repository "
511                               "root"),
512                             name ? name : SVN_WC_ENTRY_THIS_DIR);
513  MAYBE_DONE;
514
515  /* Look for a schedule attribute on this entry. */
516  {
517    const char *schedulestr;
518    SVN_ERR(read_val(&schedulestr, buf, end));
519    entry->schedule = svn_wc_schedule_normal;
520    if (schedulestr)
521      {
522        if (strcmp(schedulestr, ENTRIES_VALUE_ADD) == 0)
523          entry->schedule = svn_wc_schedule_add;
524        else if (strcmp(schedulestr, ENTRIES_VALUE_DELETE) == 0)
525          entry->schedule = svn_wc_schedule_delete;
526        else if (strcmp(schedulestr, ENTRIES_VALUE_REPLACE) == 0)
527          entry->schedule = svn_wc_schedule_replace;
528        else
529          return svn_error_createf(
530            SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
531            _("Entry '%s' has invalid 'schedule' value"),
532            name ? name : SVN_WC_ENTRY_THIS_DIR);
533      }
534  }
535  MAYBE_DONE;
536
537  /* Attempt to set up text timestamp. */
538  SVN_ERR(read_time(&entry->text_time, buf, end, pool));
539  MAYBE_DONE;
540
541  /* Checksum. */
542  SVN_ERR(read_str(&entry->checksum, buf, end, pool));
543  MAYBE_DONE;
544
545  /* Setup last-committed values. */
546  SVN_ERR(read_time(&entry->cmt_date, buf, end, pool));
547  MAYBE_DONE;
548
549  SVN_ERR(read_revnum(&entry->cmt_rev, buf, end, pool));
550  MAYBE_DONE;
551
552  SVN_ERR(read_str(&entry->cmt_author, buf, end, pool));
553  MAYBE_DONE;
554
555  /* has-props, has-prop-mods, cachable-props, present-props are all
556     deprecated. Read any values that may be in the 'entries' file, but
557     discard them, and just put default values into the entry. */
558  {
559    const char *unused_value;
560
561    /* has-props flag. */
562    SVN_ERR(read_val(&unused_value, buf, end));
563    entry->has_props = FALSE;
564    MAYBE_DONE;
565
566    /* has-prop-mods flag. */
567    SVN_ERR(read_val(&unused_value, buf, end));
568    entry->has_prop_mods = FALSE;
569    MAYBE_DONE;
570
571    /* Use the empty string for cachable_props, indicating that we no
572       longer attempt to cache any properties. An empty string for
573       present_props means that no cachable props are present. */
574
575    /* cachable-props string. */
576    SVN_ERR(read_val(&unused_value, buf, end));
577    entry->cachable_props = "";
578    MAYBE_DONE;
579
580    /* present-props string. */
581    SVN_ERR(read_val(&unused_value, buf, end));
582    entry->present_props = "";
583    MAYBE_DONE;
584  }
585
586  /* Is this entry in a state of mental torment (conflict)? */
587  {
588    SVN_ERR(read_path(&entry->prejfile, buf, end, pool));
589    MAYBE_DONE;
590    SVN_ERR(read_path(&entry->conflict_old, buf, end, pool));
591    MAYBE_DONE;
592    SVN_ERR(read_path(&entry->conflict_new, buf, end, pool));
593    MAYBE_DONE;
594    SVN_ERR(read_path(&entry->conflict_wrk, buf, end, pool));
595    MAYBE_DONE;
596  }
597
598  /* Is this entry copied? */
599  SVN_ERR(read_bool(&entry->copied, ENTRIES_BOOL_COPIED, buf, end));
600  MAYBE_DONE;
601
602  SVN_ERR(read_url(&entry->copyfrom_url, buf, end, entries_format, pool));
603  MAYBE_DONE;
604  SVN_ERR(read_revnum(&entry->copyfrom_rev, buf, end, pool));
605  MAYBE_DONE;
606
607  /* Is this entry deleted? */
608  SVN_ERR(read_bool(&entry->deleted, ENTRIES_BOOL_DELETED, buf, end));
609  MAYBE_DONE;
610
611  /* Is this entry absent? */
612  SVN_ERR(read_bool(&entry->absent, ENTRIES_BOOL_ABSENT, buf, end));
613  MAYBE_DONE;
614
615  /* Is this entry incomplete? */
616  SVN_ERR(read_bool(&entry->incomplete, ENTRIES_BOOL_INCOMPLETE, buf, end));
617  MAYBE_DONE;
618
619  /* UUID. */
620  SVN_ERR(read_str(&entry->uuid, buf, end, pool));
621  MAYBE_DONE;
622
623  /* Lock token. */
624  SVN_ERR(read_str(&entry->lock_token, buf, end, pool));
625  MAYBE_DONE;
626
627  /* Lock owner. */
628  SVN_ERR(read_str(&entry->lock_owner, buf, end, pool));
629  MAYBE_DONE;
630
631  /* Lock comment. */
632  SVN_ERR(read_str(&entry->lock_comment, buf, end, pool));
633  MAYBE_DONE;
634
635  /* Lock creation date. */
636  SVN_ERR(read_time(&entry->lock_creation_date, buf, end, pool));
637  MAYBE_DONE;
638
639  /* Changelist. */
640  SVN_ERR(read_str(&entry->changelist, buf, end, pool));
641  MAYBE_DONE;
642
643  /* Keep entry in working copy after deletion? */
644  SVN_ERR(read_bool(&entry->keep_local, ENTRIES_BOOL_KEEP_LOCAL, buf, end));
645  MAYBE_DONE;
646
647  /* Translated size */
648  {
649    const char *val;
650
651    /* read_val() returns NULL on an empty (e.g. default) entry line,
652       and entry has already been initialized accordingly already */
653    SVN_ERR(read_val(&val, buf, end));
654    if (val)
655      entry->working_size = (apr_off_t)apr_strtoi64(val, NULL, 0);
656  }
657  MAYBE_DONE;
658
659  /* Depth. */
660  {
661    const char *result;
662    SVN_ERR(read_val(&result, buf, end));
663    if (result)
664      {
665        svn_boolean_t invalid;
666        svn_boolean_t is_this_dir;
667
668        entry->depth = svn_depth_from_word(result);
669
670        /* Verify the depth value:
671           THIS_DIR should not have an excluded value and SUB_DIR should only
672           have excluded value. Remember that infinity value is not stored and
673           should not show up here. Otherwise, something bad may have
674           happened. However, infinity value itself will always be okay. */
675        is_this_dir = !name;
676        /* '!=': XOR */
677        invalid = is_this_dir != (entry->depth != svn_depth_exclude);
678        if (entry->depth != svn_depth_infinity && invalid)
679          return svn_error_createf(
680            SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
681            _("Entry '%s' has invalid 'depth' value"),
682            name ? name : SVN_WC_ENTRY_THIS_DIR);
683      }
684    else
685      entry->depth = svn_depth_infinity;
686
687  }
688  MAYBE_DONE;
689
690  /* Tree conflict data. */
691  SVN_ERR(read_str(&entry->tree_conflict_data, buf, end, pool));
692  MAYBE_DONE;
693
694  /* File external URL and revision. */
695  {
696    const char *str;
697    SVN_ERR(read_str(&str, buf, end, pool));
698    SVN_ERR(svn_wc__unserialize_file_external(&entry->file_external_path,
699                                              &entry->file_external_peg_rev,
700                                              &entry->file_external_rev,
701                                              str,
702                                              pool));
703  }
704  MAYBE_DONE;
705
706 done:
707  *new_entry = entry;
708  return SVN_NO_ERROR;
709}
710
711
712/* If attribute ATTR_NAME appears in hash ATTS, set *ENTRY_FLAG to its
713   boolean value, else set *ENTRY_FLAG false.  ENTRY_NAME is the name
714   of the WC-entry. */
715static svn_error_t *
716do_bool_attr(svn_boolean_t *entry_flag,
717             apr_hash_t *atts, const char *attr_name,
718             const char *entry_name)
719{
720  const char *str = svn_hash_gets(atts, attr_name);
721
722  *entry_flag = FALSE;
723  if (str)
724    {
725      if (strcmp(str, "true") == 0)
726        *entry_flag = TRUE;
727      else if (strcmp(str, "false") == 0 || strcmp(str, "") == 0)
728        *entry_flag = FALSE;
729      else
730        return svn_error_createf
731          (SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
732           _("Entry '%s' has invalid '%s' value"),
733           (entry_name ? entry_name : SVN_WC_ENTRY_THIS_DIR), attr_name);
734    }
735  return SVN_NO_ERROR;
736}
737
738
739/* */
740static const char *
741extract_string(apr_hash_t *atts,
742               const char *att_name,
743               apr_pool_t *result_pool)
744{
745  const char *value = svn_hash_gets(atts, att_name);
746
747  if (value == NULL)
748    return NULL;
749
750  return apr_pstrdup(result_pool, value);
751}
752
753
754/* Like extract_string(), but normalizes empty strings to NULL.  */
755static const char *
756extract_string_normalize(apr_hash_t *atts,
757                         const char *att_name,
758                         apr_pool_t *result_pool)
759{
760  const char *value = svn_hash_gets(atts, att_name);
761
762  if (value == NULL)
763    return NULL;
764
765  if (*value == '\0')
766    return NULL;
767
768  return apr_pstrdup(result_pool, value);
769}
770
771
772/* NOTE: this is used for upgrading old XML-based entries file. Be wary of
773         removing items.
774
775   ### many attributes are no longer used within the old-style log files.
776   ### These attrs need to be recognized for old entries, however. For these
777   ### cases, the code will parse the attribute, but not set *MODIFY_FLAGS
778   ### for that particular field. MODIFY_FLAGS is *only* used by the
779   ### log-based entry modification system, and will go way once we
780   ### completely move away from loggy.
781
782   Set *NEW_ENTRY to a new entry, taking attributes from ATTS, whose
783   keys and values are both char *.  Allocate the entry and copy
784   attributes into POOL as needed. */
785static svn_error_t *
786atts_to_entry(svn_wc_entry_t **new_entry,
787              apr_hash_t *atts,
788              apr_pool_t *pool)
789{
790  svn_wc_entry_t *entry = alloc_entry(pool);
791  const char *name;
792
793  /* Find the name and set up the entry under that name. */
794  name = svn_hash_gets(atts, ENTRIES_ATTR_NAME);
795  entry->name = name ? apr_pstrdup(pool, name) : SVN_WC_ENTRY_THIS_DIR;
796
797  /* Attempt to set revision (resolve_to_defaults may do it later, too)
798
799     ### not used by loggy; no need to set MODIFY_FLAGS  */
800  {
801    const char *revision_str
802      = svn_hash_gets(atts, ENTRIES_ATTR_REVISION);
803
804    if (revision_str)
805      entry->revision = SVN_STR_TO_REV(revision_str);
806    else
807      entry->revision = SVN_INVALID_REVNUM;
808  }
809
810  /* Attempt to set up url path (again, see resolve_to_defaults).
811
812     ### not used by loggy; no need to set MODIFY_FLAGS  */
813  entry->url = extract_string(atts, ENTRIES_ATTR_URL, pool);
814
815  /* Set up repository root.  Make sure it is a prefix of url.
816
817     ### not used by loggy; no need to set MODIFY_FLAGS  */
818  entry->repos = extract_string(atts, ENTRIES_ATTR_REPOS, pool);
819
820  if (entry->url && entry->repos
821      && !svn_uri__is_ancestor(entry->repos, entry->url))
822    return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
823                             _("Entry for '%s' has invalid repository "
824                               "root"),
825                             name ? name : SVN_WC_ENTRY_THIS_DIR);
826
827  /* Set up kind. */
828  /* ### not used by loggy; no need to set MODIFY_FLAGS  */
829  {
830    const char *kindstr
831      = svn_hash_gets(atts, ENTRIES_ATTR_KIND);
832
833    entry->kind = svn_node_none;
834    if (kindstr)
835      {
836        if (strcmp(kindstr, ENTRIES_VALUE_FILE) == 0)
837          entry->kind = svn_node_file;
838        else if (strcmp(kindstr, ENTRIES_VALUE_DIR) == 0)
839          entry->kind = svn_node_dir;
840        else
841          return svn_error_createf
842            (SVN_ERR_NODE_UNKNOWN_KIND, NULL,
843             _("Entry '%s' has invalid node kind"),
844             (name ? name : SVN_WC_ENTRY_THIS_DIR));
845      }
846  }
847
848  /* Look for a schedule attribute on this entry. */
849  /* ### not used by loggy; no need to set MODIFY_FLAGS  */
850  {
851    const char *schedulestr
852      = svn_hash_gets(atts, ENTRIES_ATTR_SCHEDULE);
853
854    entry->schedule = svn_wc_schedule_normal;
855    if (schedulestr)
856      {
857        if (strcmp(schedulestr, ENTRIES_VALUE_ADD) == 0)
858          entry->schedule = svn_wc_schedule_add;
859        else if (strcmp(schedulestr, ENTRIES_VALUE_DELETE) == 0)
860          entry->schedule = svn_wc_schedule_delete;
861        else if (strcmp(schedulestr, ENTRIES_VALUE_REPLACE) == 0)
862          entry->schedule = svn_wc_schedule_replace;
863        else if (strcmp(schedulestr, "") == 0)
864          entry->schedule = svn_wc_schedule_normal;
865        else
866          return svn_error_createf(
867                   SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
868                   _("Entry '%s' has invalid 'schedule' value"),
869                   (name ? name : SVN_WC_ENTRY_THIS_DIR));
870      }
871  }
872
873  /* Is this entry in a state of mental torment (conflict)? */
874  entry->prejfile = extract_string_normalize(atts,
875                                             ENTRIES_ATTR_PREJFILE,
876                                             pool);
877  entry->conflict_old = extract_string_normalize(atts,
878                                                 ENTRIES_ATTR_CONFLICT_OLD,
879                                                 pool);
880  entry->conflict_new = extract_string_normalize(atts,
881                                                 ENTRIES_ATTR_CONFLICT_NEW,
882                                                 pool);
883  entry->conflict_wrk = extract_string_normalize(atts,
884                                                 ENTRIES_ATTR_CONFLICT_WRK,
885                                                 pool);
886
887  /* Is this entry copied? */
888  /* ### not used by loggy; no need to set MODIFY_FLAGS  */
889  SVN_ERR(do_bool_attr(&entry->copied, atts, ENTRIES_ATTR_COPIED, name));
890
891  /* ### not used by loggy; no need to set MODIFY_FLAGS  */
892  entry->copyfrom_url = extract_string(atts, ENTRIES_ATTR_COPYFROM_URL, pool);
893
894  /* ### not used by loggy; no need to set MODIFY_FLAGS  */
895  {
896    const char *revstr;
897
898    revstr = svn_hash_gets(atts, ENTRIES_ATTR_COPYFROM_REV);
899    if (revstr)
900      entry->copyfrom_rev = SVN_STR_TO_REV(revstr);
901  }
902
903  /* Is this entry deleted?
904
905     ### not used by loggy; no need to set MODIFY_FLAGS  */
906  SVN_ERR(do_bool_attr(&entry->deleted, atts, ENTRIES_ATTR_DELETED, name));
907
908  /* Is this entry absent?
909
910     ### not used by loggy; no need to set MODIFY_FLAGS  */
911  SVN_ERR(do_bool_attr(&entry->absent, atts, ENTRIES_ATTR_ABSENT, name));
912
913  /* Is this entry incomplete?
914
915     ### not used by loggy; no need to set MODIFY_FLAGS  */
916  SVN_ERR(do_bool_attr(&entry->incomplete, atts, ENTRIES_ATTR_INCOMPLETE,
917                       name));
918
919  /* Attempt to set up timestamps. */
920  /* ### not used by loggy; no need to set MODIFY_FLAGS  */
921  {
922    const char *text_timestr;
923
924    text_timestr = svn_hash_gets(atts, ENTRIES_ATTR_TEXT_TIME);
925    if (text_timestr)
926      SVN_ERR(svn_time_from_cstring(&entry->text_time, text_timestr, pool));
927
928    /* Note: we do not persist prop_time, so there is no need to attempt
929       to parse a new prop_time value from the log. Certainly, on any
930       recent working copy, there will not be a log record to alter
931       the prop_time value. */
932  }
933
934  /* Checksum. */
935  /* ### not used by loggy; no need to set MODIFY_FLAGS  */
936  entry->checksum = extract_string(atts, ENTRIES_ATTR_CHECKSUM, pool);
937
938  /* UUID.
939
940     ### not used by loggy; no need to set MODIFY_FLAGS  */
941  entry->uuid = extract_string(atts, ENTRIES_ATTR_UUID, pool);
942
943  /* Setup last-committed values. */
944  {
945    const char *cmt_datestr, *cmt_revstr;
946
947    cmt_datestr = svn_hash_gets(atts, ENTRIES_ATTR_CMT_DATE);
948    if (cmt_datestr)
949      {
950        SVN_ERR(svn_time_from_cstring(&entry->cmt_date, cmt_datestr, pool));
951      }
952    else
953      entry->cmt_date = 0;
954
955    cmt_revstr = svn_hash_gets(atts, ENTRIES_ATTR_CMT_REV);
956    if (cmt_revstr)
957      {
958        entry->cmt_rev = SVN_STR_TO_REV(cmt_revstr);
959      }
960    else
961      entry->cmt_rev = SVN_INVALID_REVNUM;
962
963    entry->cmt_author = extract_string(atts, ENTRIES_ATTR_CMT_AUTHOR, pool);
964  }
965
966  /* ### not used by loggy; no need to set MODIFY_FLAGS  */
967  entry->lock_token = extract_string(atts, ENTRIES_ATTR_LOCK_TOKEN, pool);
968  entry->lock_owner = extract_string(atts, ENTRIES_ATTR_LOCK_OWNER, pool);
969  entry->lock_comment = extract_string(atts, ENTRIES_ATTR_LOCK_COMMENT, pool);
970  {
971    const char *cdate_str =
972      svn_hash_gets(atts, ENTRIES_ATTR_LOCK_CREATION_DATE);
973    if (cdate_str)
974      {
975        SVN_ERR(svn_time_from_cstring(&entry->lock_creation_date,
976                                      cdate_str, pool));
977      }
978  }
979  /* ----- end of lock handling.  */
980
981  /* Note: if there are attributes for the (deprecated) has_props,
982     has_prop_mods, cachable_props, or present_props, then we're just
983     going to ignore them. */
984
985  /* Translated size */
986  /* ### not used by loggy; no need to set MODIFY_FLAGS  */
987  {
988    const char *val = svn_hash_gets(atts, ENTRIES_ATTR_WORKING_SIZE);
989    if (val)
990      {
991        /* Cast to off_t; it's safe: we put in an off_t to start with... */
992        entry->working_size = (apr_off_t)apr_strtoi64(val, NULL, 0);
993      }
994  }
995
996  *new_entry = entry;
997  return SVN_NO_ERROR;
998}
999
1000/* Used when reading an entries file in XML format. */
1001struct entries_accumulator
1002{
1003  /* Keys are entry names, vals are (struct svn_wc_entry_t *)'s. */
1004  apr_hash_t *entries;
1005
1006  /* The parser that's parsing it, for signal_expat_bailout(). */
1007  svn_xml_parser_t *parser;
1008
1009  /* Don't leave home without one. */
1010  apr_pool_t *pool;
1011
1012  /* Cleared before handling each entry. */
1013  apr_pool_t *scratch_pool;
1014};
1015
1016
1017
1018/* Called whenever we find an <open> tag of some kind. */
1019static void
1020handle_start_tag(void *userData, const char *tagname, const char **atts)
1021{
1022  struct entries_accumulator *accum = userData;
1023  apr_hash_t *attributes;
1024  svn_wc_entry_t *entry;
1025  svn_error_t *err;
1026
1027  /* We only care about the `entry' tag; all other tags, such as `xml'
1028     and `wc-entries', are ignored. */
1029  if (strcmp(tagname, ENTRIES_TAG_ENTRY))
1030    return;
1031
1032  svn_pool_clear(accum->scratch_pool);
1033  /* Make an entry from the attributes. */
1034  attributes = svn_xml_make_att_hash(atts, accum->scratch_pool);
1035  err = atts_to_entry(&entry, attributes, accum->pool);
1036  if (err)
1037    {
1038      svn_xml_signal_bailout(err, accum->parser);
1039      return;
1040    }
1041
1042  /* Find the name and set up the entry under that name.  This
1043     should *NOT* be NULL, since svn_wc__atts_to_entry() should
1044     have made it into SVN_WC_ENTRY_THIS_DIR. */
1045  svn_hash_sets(accum->entries, entry->name, entry);
1046}
1047
1048/* Parse BUF of size SIZE as an entries file in XML format, storing the parsed
1049   entries in ENTRIES.  Use SCRATCH_POOL for temporary allocations and
1050   RESULT_POOL for the returned entries.  */
1051static svn_error_t *
1052parse_entries_xml(const char *dir_abspath,
1053                  apr_hash_t *entries,
1054                  const char *buf,
1055                  apr_size_t size,
1056                  apr_pool_t *result_pool,
1057                  apr_pool_t *scratch_pool)
1058{
1059  svn_xml_parser_t *svn_parser;
1060  struct entries_accumulator accum;
1061
1062  /* Set up userData for the XML parser. */
1063  accum.entries = entries;
1064  accum.pool = result_pool;
1065  accum.scratch_pool = svn_pool_create(scratch_pool);
1066
1067  /* Create the XML parser */
1068  svn_parser = svn_xml_make_parser(&accum,
1069                                   handle_start_tag,
1070                                   NULL,
1071                                   NULL,
1072                                   scratch_pool);
1073
1074  /* Store parser in its own userdata, so callbacks can call
1075     svn_xml_signal_bailout() */
1076  accum.parser = svn_parser;
1077
1078  /* Parse. */
1079  SVN_ERR_W(svn_xml_parse(svn_parser, buf, size, TRUE),
1080            apr_psprintf(scratch_pool,
1081                         _("XML parser failed in '%s'"),
1082                         svn_dirent_local_style(dir_abspath, scratch_pool)));
1083
1084  svn_pool_destroy(accum.scratch_pool);
1085
1086  /* Clean up the XML parser */
1087  svn_xml_free_parser(svn_parser);
1088
1089  return SVN_NO_ERROR;
1090}
1091
1092
1093
1094/* Use entry SRC to fill in blank portions of entry DST.  SRC itself
1095   may not have any blanks, of course.
1096   Typically, SRC is a parent directory's own entry, and DST is some
1097   child in that directory. */
1098static void
1099take_from_entry(const svn_wc_entry_t *src,
1100                svn_wc_entry_t *dst,
1101                apr_pool_t *pool)
1102{
1103  /* Inherits parent's revision if doesn't have a revision of one's
1104     own, unless this is a subdirectory. */
1105  if ((dst->revision == SVN_INVALID_REVNUM) && (dst->kind != svn_node_dir))
1106    dst->revision = src->revision;
1107
1108  /* Inherits parent's url if doesn't have a url of one's own. */
1109  if (! dst->url)
1110    dst->url = svn_path_url_add_component2(src->url, dst->name, pool);
1111
1112  if (! dst->repos)
1113    dst->repos = src->repos;
1114
1115  if ((! dst->uuid)
1116      && (! ((dst->schedule == svn_wc_schedule_add)
1117             || (dst->schedule == svn_wc_schedule_replace))))
1118    {
1119      dst->uuid = src->uuid;
1120    }
1121}
1122
1123/* Resolve any missing information in ENTRIES by deducing from the
1124   directory's own entry (which must already be present in ENTRIES). */
1125static svn_error_t *
1126resolve_to_defaults(apr_hash_t *entries,
1127                    apr_pool_t *pool)
1128{
1129  apr_hash_index_t *hi;
1130  svn_wc_entry_t *default_entry
1131    = svn_hash_gets(entries, SVN_WC_ENTRY_THIS_DIR);
1132
1133  /* First check the dir's own entry for consistency. */
1134  if (! default_entry)
1135    return svn_error_create(SVN_ERR_ENTRY_NOT_FOUND,
1136                            NULL,
1137                            _("Missing default entry"));
1138
1139  if (default_entry->revision == SVN_INVALID_REVNUM)
1140    return svn_error_create(SVN_ERR_ENTRY_MISSING_REVISION,
1141                            NULL,
1142                            _("Default entry has no revision number"));
1143
1144  if (! default_entry->url)
1145    return svn_error_create(SVN_ERR_ENTRY_MISSING_URL,
1146                            NULL,
1147                            _("Default entry is missing URL"));
1148
1149
1150  /* Then use it to fill in missing information in other entries. */
1151  for (hi = apr_hash_first(pool, entries); hi; hi = apr_hash_next(hi))
1152    {
1153      svn_wc_entry_t *this_entry = svn__apr_hash_index_val(hi);
1154
1155      if (this_entry == default_entry)
1156        /* THIS_DIR already has all the information it can possibly
1157           have.  */
1158        continue;
1159
1160      if (this_entry->kind == svn_node_dir)
1161        /* Entries that are directories have everything but their
1162           name, kind, and state stored in the THIS_DIR entry of the
1163           directory itself.  However, we are disallowing the perusing
1164           of any entries outside of the current entries file.  If a
1165           caller wants more info about a directory, it should look in
1166           the entries file in the directory.  */
1167        continue;
1168
1169      if (this_entry->kind == svn_node_file)
1170        /* For file nodes that do not explicitly have their ancestry
1171           stated, this can be derived from the default entry of the
1172           directory in which those files reside.  */
1173        take_from_entry(default_entry, this_entry, pool);
1174    }
1175
1176  return SVN_NO_ERROR;
1177}
1178
1179
1180
1181/* Read and parse an old-style 'entries' file in the administrative area
1182   of PATH, filling in ENTRIES with the contents. The results will be
1183   allocated in RESULT_POOL, and temporary allocations will be made in
1184   SCRATCH_POOL.  */
1185svn_error_t *
1186svn_wc__read_entries_old(apr_hash_t **entries,
1187                         const char *dir_abspath,
1188                         apr_pool_t *result_pool,
1189                         apr_pool_t *scratch_pool)
1190{
1191  char *curp;
1192  const char *endp;
1193  svn_wc_entry_t *entry;
1194  svn_stream_t *stream;
1195  svn_string_t *buf;
1196
1197  *entries = apr_hash_make(result_pool);
1198
1199  /* Open the entries file. */
1200  SVN_ERR(svn_wc__open_adm_stream(&stream, dir_abspath, SVN_WC__ADM_ENTRIES,
1201                                  scratch_pool, scratch_pool));
1202  SVN_ERR(svn_string_from_stream(&buf, stream, scratch_pool, scratch_pool));
1203
1204  /* We own the returned data; it is modifiable, so cast away... */
1205  curp = (char *)buf->data;
1206  endp = buf->data + buf->len;
1207
1208  /* If the first byte of the file is not a digit, then it is probably in XML
1209     format. */
1210  if (curp != endp && !svn_ctype_isdigit(*curp))
1211    SVN_ERR(parse_entries_xml(dir_abspath, *entries, buf->data, buf->len,
1212                              result_pool, scratch_pool));
1213  else
1214    {
1215      int entryno, entries_format;
1216      const char *val;
1217
1218      /* Read the format line from the entries file. In case we're in the
1219         middle of upgrading a working copy, this line will contain the
1220         original format pre-upgrade. */
1221      SVN_ERR(read_val(&val, &curp, endp));
1222      if (val)
1223        entries_format = (int)apr_strtoi64(val, NULL, 0);
1224      else
1225        return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
1226                                 _("Invalid version line in entries file "
1227                                   "of '%s'"),
1228                                 svn_dirent_local_style(dir_abspath,
1229                                                        scratch_pool));
1230      entryno = 1;
1231
1232      while (curp != endp)
1233        {
1234          svn_error_t *err = read_entry(&entry, &curp, endp,
1235                                        entries_format, result_pool);
1236          if (! err)
1237            {
1238              /* We allow extra fields at the end of the line, for
1239                 extensibility. */
1240              curp = memchr(curp, '\f', endp - curp);
1241              if (! curp)
1242                err = svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
1243                                       _("Missing entry terminator"));
1244              if (! err && (curp == endp || *(++curp) != '\n'))
1245                err = svn_error_create(SVN_ERR_WC_CORRUPT, NULL,
1246                                       _("Invalid entry terminator"));
1247            }
1248          if (err)
1249            return svn_error_createf(err->apr_err, err,
1250                                     _("Error at entry %d in entries file for "
1251                                       "'%s':"),
1252                                     entryno,
1253                                     svn_dirent_local_style(dir_abspath,
1254                                                            scratch_pool));
1255
1256          ++curp;
1257          ++entryno;
1258
1259          svn_hash_sets(*entries, entry->name, entry);
1260        }
1261    }
1262
1263  /* Fill in any implied fields. */
1264  return svn_error_trace(resolve_to_defaults(*entries, result_pool));
1265}
1266
1267
1268/* For non-directory PATHs full entry information is obtained by reading
1269 * the entries for the parent directory of PATH and then extracting PATH's
1270 * entry.  If PATH is a directory then only abrieviated information is
1271 * available in the parent directory, more complete information is
1272 * available by reading the entries for PATH itself.
1273 *
1274 * Note: There is one bit of information about directories that is only
1275 * available in the parent directory, that is the "deleted" state.  If PATH
1276 * is a versioned directory then the "deleted" state information will not
1277 * be returned in ENTRY.  This means some bits of the code (e.g. revert)
1278 * need to obtain it by directly extracting the directory entry from the
1279 * parent directory's entries.  I wonder if this function should handle
1280 * that?
1281 */
1282svn_error_t *
1283svn_wc_entry(const svn_wc_entry_t **entry,
1284             const char *path,
1285             svn_wc_adm_access_t *adm_access,
1286             svn_boolean_t show_hidden,
1287             apr_pool_t *pool)
1288{
1289  svn_wc__db_t *db = svn_wc__adm_get_db(adm_access);
1290  const char *local_abspath;
1291  svn_wc_adm_access_t *dir_access;
1292  const char *entry_name;
1293  apr_hash_t *entries;
1294
1295  SVN_ERR(svn_dirent_get_absolute(&local_abspath, path, pool));
1296
1297  /* Does the provided path refer to a directory with an associated
1298     access baton?  */
1299  dir_access = svn_wc__adm_retrieve_internal2(db, local_abspath, pool);
1300  if (dir_access == NULL)
1301    {
1302      /* Damn. Okay. Assume the path is to a child, and let's look for
1303         a baton associated with its parent.  */
1304
1305      const char *dir_abspath;
1306
1307      svn_dirent_split(&dir_abspath, &entry_name, local_abspath, pool);
1308
1309      dir_access = svn_wc__adm_retrieve_internal2(db, dir_abspath, pool);
1310    }
1311  else
1312    {
1313      /* Woo! Got one. Look for "this dir" in the entries hash.  */
1314      entry_name = "";
1315    }
1316
1317  if (dir_access == NULL)
1318    {
1319      /* Early exit.  */
1320      *entry = NULL;
1321      return SVN_NO_ERROR;
1322    }
1323
1324  /* Load an entries hash, and cache it into DIR_ACCESS. Go ahead and
1325     fetch all entries here (optimization) since we know how to filter
1326     out a "hidden" node.  */
1327  SVN_ERR(svn_wc__entries_read_internal(&entries, dir_access, TRUE, pool));
1328  *entry = svn_hash_gets(entries, entry_name);
1329
1330  if (!show_hidden && *entry != NULL)
1331    {
1332      svn_boolean_t hidden;
1333
1334      SVN_ERR(svn_wc__entry_is_hidden(&hidden, *entry));
1335      if (hidden)
1336        *entry = NULL;
1337    }
1338
1339  return SVN_NO_ERROR;
1340}
1341