aboutsummaryrefslogtreecommitdiffhomepage
path: root/history.h
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-06-15 16:22:37 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-06-15 16:24:05 -0700
commit18f04adccbaff74f12ad12f3f6ceb123e5ccf47f (patch)
treee389adb623b1028343a3e3f9f8ca0154218b64eb /history.h
parent1ed65b6bd7e8e24bf047872e56ff807e3f81294b (diff)
Support for importing fish 1.x's history and format, and also bash
Diffstat (limited to 'history.h')
-rw-r--r--history.h35
1 files changed, 21 insertions, 14 deletions
diff --git a/history.h b/history.h
index 4b146c1f..b25d3217 100644
--- a/history.h
+++ b/history.h
@@ -57,20 +57,18 @@ class history_item_t {
const path_list_t &get_required_paths() const { return required_paths; }
- bool write_to_file(FILE *f) const;
-
bool operator==(const history_item_t &other) const {
return contents == other.contents &&
creation_timestamp == other.creation_timestamp &&
required_paths == other.required_paths;
}
+};
- bool match_contents(const history_item_t &other) const {
- return contents == other.contents;
- }
-
- /* Functions for testing only */
-
+/* The type of file that we mmap'd */
+enum history_file_type_t {
+ history_type_unknown,
+ history_type_fish_2_0,
+ history_type_fish_1_x
};
class history_t {
@@ -101,8 +99,8 @@ private:
/** New items. */
std::vector<history_item_t> new_items;
- /** Deleted items. */
- std::vector<history_item_t> deleted_items;
+ /** Deleted item contents. */
+ std::set<wcstring> deleted_items;
/** How many items we've added without saving */
size_t unsaved_item_count;
@@ -110,17 +108,18 @@ private:
/** The mmaped region for the history file */
const char *mmap_start;
- /** The size of the mmaped region */
+ /** The size of the mmap'd region */
size_t mmap_length;
+ /** The type of file we mmap'd */
+ history_file_type_t mmap_type;
+
/** Timestamp of when this history was created */
const time_t birth_timestamp;
/** Timestamp of last save */
time_t save_timestamp;
- static history_item_t decode_item(const char *ptr, size_t len);
-
void populate_from_mmap(void);
/** List of old items, as offsets into out mmap data */
@@ -137,6 +136,11 @@ private:
/** Saves history */
void save_internal();
+
+ /* Versioned decoding */
+ static history_item_t decode_item_fish_2_0(const char *base, size_t len);
+ static history_item_t decode_item_fish_1_x(const char *base, size_t len);
+ static history_item_t decode_item(const char *base, size_t len, history_file_type_t type);
public:
/** Returns history with the given name, creating it if necessary */
@@ -157,12 +161,15 @@ public:
/** Irreversibly clears history */
void clear();
+ /** Populates from a bash history file */
+ void populate_from_bash(FILE *f);
+
/* Gets all the history into a string with ARRAY_SEP_STR. This is intended for the $history environment variable. This may be long! */
void get_string_representation(wcstring &str, const wcstring &separator);
/** Return the specified history at the specified index. 0 is the index of the current commandline. (So the most recent item is at index 1.) */
history_item_t item_at_index(size_t idx);
-
+
bool is_deleted(const history_item_t &item) const;
};