sapling/cfastmanifest/tree_dump.c
Tony Tung b0604f946a [fastmanifest] utility to dump some specs about a tree to disk
Test Plan: run tree_dump on a fastmanifest file.  did some spot checks against the text manifest with the same sha (`hg debugdata -m`)

Reviewers: lcharignon, durham

Reviewed By: durham

Subscribers: mitrandir, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3585843

Tasks: 12119301

Signature: t1:3585843:1469050470:70729d5601f935f2de80f89a7ad83590bcb8dd00
2016-07-26 23:35:53 -07:00

47 lines
1.1 KiB
C

//
// tree_dump: Load a tree from disk. Then print all the node hashes along
// with the length of the name and the number of children.
//
// no-check-code
#include <stdlib.h>
#include "convert.h"
#include "tree.h"
#include "tests.h"
static char buffer[SHA1_BYTES * 2];
void print_subtree(node_t *node) {
hexlify(node->checksum, node->checksum_sz, buffer);
printf("%.*s\t%d\t%d\n",
node->checksum_sz * 2, buffer, node->name_sz, node->num_children);
for (uint32_t ix = 0; ix < node->num_children; ix ++) {
print_subtree(get_child_by_index(node, ix));
}
}
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: %s <tree-save-file>\n", argv[0]);
exit(1);
}
read_from_file_result_t read_from_file_result =
read_from_file(argv[1], strlen(argv[1]));
if (read_from_file_result.code != READ_FROM_FILE_OK) {
fprintf(stderr, "Unable to read tree file %s\n", argv[1]);
exit(1);
}
tree_t *tree = read_from_file_result.tree;
node_t *shadow_root = tree->shadow_root;
node_t *real_root = get_child_by_index(shadow_root, 0);
print_subtree(real_root);
return 0;
}