Skip to content

Commit

Permalink
pathhistory: fix fetching bug when a path prefix was not a directory
Browse files Browse the repository at this point in the history
Summary:
When a prefix of the given path was a file (or symlink) in the commit history, the load_tree_entry() will fail,
since it was trying to read a directory.  For example, let's assume the given path is `a/b/c`, and `a/b` is a
directory now; but in the commit history, `a/b` was not a directory (regular file or symlink).

This diff fixes the issue by ignoring the non-directory items, this will make pathhistory ignore those commits
that the prefix was not a directory. If the file was a symlink to another folder, it will not follow the link.

Reviewed By: muirdm

Differential Revision: D67412803

fbshipit-source-id: 5e8ace29e2b26d295f31d3014cb1c67cf98c10e5
  • Loading branch information
zzl0 authored and facebook-github-bot committed Dec 19, 2024
1 parent 4f47687 commit 2e5037e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions eden/scm/lib/pathhistory/src/pathops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ impl<'a> State<'a> {
None | Some(None) => return Ok(None),
Some(Some(item)) => item,
};
if item.flag != Flag::Directory {
// This happens when the path was a file (or symlink)
tracing::debug!(" load_tree_entry: {:?} is not a directory", item);
return Ok(None);
}
if item.loaded.is_none() {
let entry = tree_store.get_content(item.path, item.id, FetchMode::AllowRemote)?;
let format = tree_store.format();
Expand Down
18 changes: 18 additions & 0 deletions eden/scm/lib/pathhistory/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,24 @@ async fn test_log_dirs() {
);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_log_when_a_prefix_was_not_directory() {
let t = TestHistory::from_history(&[
(0, "a/b", 1, R),
(50, "a/b", 0, R),
(100, "a/b/c/e", 2, R),
(150, "a/b/c/e", 0, R),
(200, "h/i/j/k", 5, E),
(250, "a/b/c/f", 3, R),
]);

let mut h = t.paths_history(300, &["a/b/c"]).await;
assert_eq!(h.next_n(5).await, [250, 150, 100]);

let mut h = t.paths_history(300, &["a/b"]).await;
assert_eq!(h.next_n(5).await, [250, 150, 100, 50, 0]);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_log_with_roots() {
// Use a commit graph with a few roots.
Expand Down

0 comments on commit 2e5037e

Please sign in to comment.