Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tree-diff: make list tail-passing more explicit
The ll_diff_tree_paths() function and its helpers all take a pointer to a list tail, possibly add to it, and then return the new tail. This works but has two downsides: - The top-level caller (diff_tree_paths() in this case) has to make a fake combine_diff_path struct to act as the list head. This is especially weird here, as it's a flexible-sized struct which will have an empty FLEX_ARRAY field. That used to be a portability problem, though these days it is legal because our FLEX_ARRAY macro over-allocates if necessary. It's still kind of ugly, though. - Besides the name "tail", it's not immediately obvious that the entry we pass around will not be examined by each function. Using a pointer-to-pointer or similar makes it more obvious we only care about the pointer itself, not its contents. We can solve both by passing around a pointer to the tail instead. That gets rid of the return value entirely, though note that because of the recursion we actually need a three-star pointer for this to work. The result is fairly readable, as we only need to dereference the tail in one spot. If we wanted to make it simpler we could wrap the tail in a struct, which we pass around. Another option is to convert combine_diff to use our generic list_head API. I tried that and found the result became much harder to read overall. It means that _all_ code that looks at combine_diff_path structs needs to be modified, since the "next" pointer is now inside a list_head which has to be dereferenced with list_entry(). And we lose some type safety, since we're just passing around a list_head struct everywhere, and everybody who looks at it has to specify the type to list_entry themselves. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
- Loading branch information