Rename head text to indicate that it's not always going to be from head

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Julia 2022-10-03 15:11:06 -04:00
parent a5c2f22bf7
commit e6487de069
11 changed files with 78 additions and 78 deletions

View file

@ -490,11 +490,7 @@ impl FakeFs {
.boxed()
}
pub async fn set_head_state_for_git_repository(
&self,
dot_git: &Path,
head_state: &[(&Path, String)],
) {
pub async fn set_index_for_repo(&self, dot_git: &Path, head_state: &[(&Path, String)]) {
let content_path = dot_git.parent().unwrap();
let mut state = self.state.lock().await;
let entry = state.read_path(dot_git).await.unwrap();

View file

@ -424,7 +424,7 @@ impl Project {
client.add_model_request_handler(Self::handle_open_buffer_by_id);
client.add_model_request_handler(Self::handle_open_buffer_by_path);
client.add_model_request_handler(Self::handle_save_buffer);
client.add_model_message_handler(Self::handle_update_head_text);
client.add_model_message_handler(Self::handle_update_diff_base);
}
pub fn local(
@ -4675,22 +4675,22 @@ impl Project {
let client = self.client.clone();
cx.spawn(|_, mut cx| async move {
let head_text = cx
let diff_base = cx
.background()
.spawn(async move { repo.repo.lock().load_head_text(&path) })
.spawn(async move { repo.repo.lock().load_index(&path) })
.await;
let buffer_id = buffer.update(&mut cx, |buffer, cx| {
buffer.update_head_text(head_text.clone(), cx);
buffer.update_diff_base(diff_base.clone(), cx);
buffer.remote_id()
});
if let Some(project_id) = shared_remote_id {
client
.send(proto::UpdateHeadText {
.send(proto::UpdateDiffBase {
project_id,
buffer_id: buffer_id as u64,
head_text,
diff_base,
})
.log_err();
}
@ -5272,22 +5272,22 @@ impl Project {
})
}
async fn handle_update_head_text(
async fn handle_update_diff_base(
this: ModelHandle<Self>,
envelope: TypedEnvelope<proto::UpdateHeadText>,
envelope: TypedEnvelope<proto::UpdateDiffBase>,
_: Arc<Client>,
mut cx: AsyncAppContext,
) -> Result<()> {
this.update(&mut cx, |this, cx| {
let buffer_id = envelope.payload.buffer_id;
let head_text = envelope.payload.head_text;
let diff_base = envelope.payload.diff_base;
let buffer = this
.opened_buffers
.get_mut(&buffer_id)
.and_then(|b| b.upgrade(cx))
.ok_or_else(|| anyhow!("No such buffer {}", buffer_id))?;
buffer.update(cx, |buffer, cx| buffer.update_head_text(head_text, cx));
buffer.update(cx, |buffer, cx| buffer.update_diff_base(diff_base, cx));
Ok(())
})

View file

@ -481,11 +481,11 @@ impl LocalWorktree {
) -> Task<Result<ModelHandle<Buffer>>> {
let path = Arc::from(path);
cx.spawn(move |this, mut cx| async move {
let (file, contents, head_text) = this
let (file, contents, diff_base) = this
.update(&mut cx, |t, cx| t.as_local().unwrap().load(&path, cx))
.await?;
Ok(cx.add_model(|cx| {
let mut buffer = Buffer::from_file(0, contents, head_text, Arc::new(file), cx);
let mut buffer = Buffer::from_file(0, contents, diff_base, Arc::new(file), cx);
buffer.git_diff_recalc(cx);
buffer
}))
@ -673,13 +673,13 @@ impl LocalWorktree {
cx.spawn(|this, mut cx| async move {
let text = fs.load(&abs_path).await?;
let head_text = match files_included {
let diff_base = match files_included {
settings::GitFilesIncluded::All | settings::GitFilesIncluded::OnlyTracked => {
let results = if let Some(repo) = snapshot.repo_for(&abs_path) {
cx.background()
.spawn({
let path = path.clone();
async move { repo.repo.lock().load_head_text(&path) }
async move { repo.repo.lock().load_index(&path) }
})
.await
} else {
@ -714,7 +714,7 @@ impl LocalWorktree {
is_local: true,
},
text,
head_text,
diff_base,
))
})
}