From f32d47d020d1807a867430fc3a415476f8dfdfaf Mon Sep 17 00:00:00 2001
From: Chris Dinh <cqd@meta.com>
Date: Tue, 28 Jan 2025 10:35:34 -0800
Subject: [PATCH] Move get_mount_point logic into edenfs-client, stub out wait
 and subscribe common path

Summary:
# Context

We are introducing EdenFS notifications to support scalable and ergonomic file system notifications for EdenFS mounts.

# This Diff
This diff implements some setup for the subscribe functionality

# Technical Details
get_mount_point, which looks up the current mount point if not provided, is moved to edenfs-client. Some processing for OS specific handling has been copied over from debug subscribe

# Discussion Points
Other functions, such as get-position, are just using bytes_from_path(mount_point_path) rather than doing OS specific conversions. Should this be a concern?

Reviewed By: jdelliot

Differential Revision: D68588494

fbshipit-source-id: e5bb8fe7a96d297da6e7e0cd133c97025cc0acee
---
 .../edenfs-commands/src/debug/subscribe.rs    | 20 ++-----------------
 .../src/notify/changes_since.rs               | 17 ++++++++--------
 2 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/eden/fs/cli_rs/edenfs-commands/src/debug/subscribe.rs b/eden/fs/cli_rs/edenfs-commands/src/debug/subscribe.rs
index b888d756c437e..25ae860261ead 100644
--- a/eden/fs/cli_rs/edenfs-commands/src/debug/subscribe.rs
+++ b/eden/fs/cli_rs/edenfs-commands/src/debug/subscribe.rs
@@ -16,13 +16,11 @@ use std::path::Path;
 use std::path::PathBuf;
 use std::sync::Arc;
 
-use anyhow::anyhow;
-use anyhow::Context;
 use anyhow::Result;
 use async_trait::async_trait;
 use clap::Parser;
 use edenfs_client::types::JournalPosition;
-use edenfs_client::utils::locate_repo_root;
+use edenfs_client::utils::get_mount_point;
 use edenfs_client::EdenFsInstance;
 use hg_util::path::expand_path;
 use serde::Serialize;
@@ -151,20 +149,6 @@ pub struct SubscribeCmd {
     guard: u64,
 }
 
-impl SubscribeCmd {
-    fn get_mount_point(&self) -> Result<PathBuf> {
-        if let Some(path) = &self.mount_point {
-            Ok(path.clone())
-        } else {
-            locate_repo_root(
-                &std::env::current_dir().context("Unable to retrieve current working directory")?,
-            )
-            .map(|p| p.to_path_buf())
-            .ok_or_else(|| anyhow!("Unable to locate repository root"))
-        }
-    }
-}
-
 fn have_non_hg_changes(changes: &[edenfs_thrift::PathString]) -> bool {
     changes.iter().any(|f| !f.starts_with(b".hg"))
 }
@@ -273,7 +257,7 @@ impl crate::Subcommand for SubscribeCmd {
     async fn run(&self) -> Result<ExitCode> {
         let instance = EdenFsInstance::global();
 
-        let mount_point_path = self.get_mount_point()?;
+        let mount_point_path = get_mount_point(&self.mount_point)?;
         #[cfg(unix)]
         let mount_point = <Path as AsRef<OsStr>>::as_ref(&mount_point_path)
             .to_os_string()
diff --git a/eden/fs/cli_rs/edenfs-commands/src/notify/changes_since.rs b/eden/fs/cli_rs/edenfs-commands/src/notify/changes_since.rs
index b17552aa55f09..0ac6e9bfecf24 100644
--- a/eden/fs/cli_rs/edenfs-commands/src/notify/changes_since.rs
+++ b/eden/fs/cli_rs/edenfs-commands/src/notify/changes_since.rs
@@ -84,14 +84,11 @@ impl crate::Subcommand for ChangesSinceCmd {
     #[cfg(fbcode_build)]
     async fn run(&self) -> Result<ExitCode> {
         let instance = EdenFsInstance::global();
-        let position = match &self.position {
-            Some(result) => result.clone(),
-            None => {
-                instance
-                    .get_journal_position(&self.mount_point, None)
-                    .await?
-            }
-        };
+        let position = self.position.clone().unwrap_or(
+            instance
+                .get_journal_position(&self.mount_point, None)
+                .await?,
+        );
         let result = instance
             .get_changes_since(
                 &self.mount_point,
@@ -112,6 +109,10 @@ impl crate::Subcommand for ChangesSinceCmd {
                 result.to_string()
             }
         );
+
+        if self.subscribe {
+            println!("Getting changes since {}", result.to_position);
+        }
         Ok(0)
     }
 }