[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-devel] relative paths from ls unknown/ignored/missing/known
From: |
Derek Scherger |
Subject: |
[Monotone-devel] relative paths from ls unknown/ignored/missing/known |
Date: |
Fri, 15 Dec 2006 22:53:31 -0700 |
User-agent: |
Thunderbird 1.5.0.8 (X11/20061111) |
The subject of having ls unknown/ignored/missing/known list paths
relative to the current directory has come up a few times and it seems
like it *might* be a good idea. So I've worked up a small patch that
does this to see what people might think.
This is probably not ready for prime-time though:
-- there was talk of making this optional behaviour and this patch
does not yet do that, it always lists relative paths
-- it's a bit weird if you don't restrict things to the current
directory, as it lists the whole tree from the perspective of
the current directory and many paths will have ../ prefixes
to get them back to the root
-- the current dir is listed as an empty line when run from a
subdirectory (it should probably be listed as a "." I guess)
-- this is not going to be consistent with other commands
like diff and status which always list paths relative to the
root
-- internally the as_relative function abuses the concept of a
split_path somewhat by jamming in a few ".." components to get
things right and this seems a bit questionable
The main point of listing paths relative to the current dir would be so
that shell scripts can use them more readily.
i.e. mtn ls known | xargs mumble
from within a subdirectory doesn't work at the moment and with this
change it would.
Thoughts?
Derek
#
# old_revision [5e318f5a9a1365820a36c418e6d5b24b017c4981]
#
# patch "cmd_list.cc"
# from [aa095825907151ba4f39a9182aabdf306d561a6a]
# to [36c5119f41161d63f5df9628fcdc05779eeb9408]
#
# patch "paths.cc"
# from [3fcc561710618bd984b8ea3396c5e90577bf581d]
# to [190aa44a52096526d7daefe1a779236927d73f17]
#
# patch "paths.hh"
# from [601092879bde9e640b917cd6515dfa60151ca587]
# to [e65ab22d5a9223d8935630d190dba3580c2b615c]
#
============================================================
--- cmd_list.cc aa095825907151ba4f39a9182aabdf306d561a6a
+++ cmd_list.cc 36c5119f41161d63f5df9628fcdc05779eeb9408
@@ -362,7 +362,7 @@ ls_known(app_state & app, vector<utf8> c
{
split_path sp;
new_roster.get_name(nid, sp);
- cout << file_path(sp) << "\n";
+ cout << as_relative(sp) << "\n";
}
}
}
@@ -387,11 +387,11 @@ ls_unknown_or_ignored(app_state & app, b
if (want_ignored)
for (path_set::const_iterator i = ignored.begin();
i != ignored.end(); ++i)
- cout << file_path(*i) << "\n";
+ cout << as_relative(*i) << "\n";
else
for (path_set::const_iterator i = unknown.begin();
i != unknown.end(); ++i)
- cout << file_path(*i) << "\n";
+ cout << as_relative(*i) << "\n";
}
static void
@@ -410,9 +410,7 @@ ls_missing(app_state & app, vector<utf8>
for (path_set::const_iterator i = missing.begin();
i != missing.end(); ++i)
- {
- cout << file_path(*i) << "\n";
- }
+ cout << as_relative(*i) << "\n";
}
============================================================
--- paths.cc 3fcc561710618bd984b8ea3396c5e90577bf581d
+++ paths.cc 190aa44a52096526d7daefe1a779236927d73f17
@@ -304,6 +304,7 @@ bookkeeping_path::bookkeeping_path(strin
data = path;
}
+// this looks rather dangerous!
bool
bookkeeping_path::is_bookkeeping_path(string const & path)
{
@@ -382,6 +383,42 @@ file_path::split(split_path & sp) const
}
}
+string
+as_relative(split_path const & sp)
+{
+ I(initial_rel_path.initialized);
+ fs::path base = initial_rel_path.get_but_unused();
+ file_path fp = file_path_internal(base.string());
+ split_path bp;
+ fp.split(bp);
+
+ split_path relative;
+ path_component const dots("..");
+
+ relative.push_back(the_null_component);
+
+ split_path::const_iterator i = sp.begin();
+ split_path::const_iterator j = bp.begin();
+ while (i != sp.end() && j != bp.end() && *i == *j)
+ {
+ i++;
+ j++;
+ }
+ while (j != bp.end())
+ {
+ relative.push_back(dots);
+ j++;
+ }
+ while (i != sp.end())
+ {
+ relative.push_back(*i);
+ i++;
+ }
+
+ return file_path(relative).as_internal();
+}
+
+
template <>
void dump(split_path const & sp, string & out)
{
============================================================
--- paths.hh 601092879bde9e640b917cd6515dfa60151ca587
+++ paths.hh e65ab22d5a9223d8935630d190dba3580c2b615c
@@ -275,6 +275,9 @@ internal_string_to_split_path(std::strin
void
internal_string_to_split_path(std::string const & path, split_path & sp);
+std::string
+as_relative(split_path const & sp);
+
// Local Variables:
// mode: C++
// fill-column: 76
- [Monotone-devel] relative paths from ls unknown/ignored/missing/known,
Derek Scherger <=