core: turn existing_filename into std::string

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-03-16 16:06:39 +01:00 committed by bstoeger
parent 37f2207f94
commit 41cb916060
10 changed files with 59 additions and 55 deletions

View file

@ -207,8 +207,6 @@ extern void invalidate_dive_cache(struct dive *dc);
extern int total_weight(const struct dive *);
extern const char *existing_filename;
extern bool has_planned(const struct dive *dive, bool planned);
/* Get gasmixes at increasing timestamps.
@ -229,8 +227,11 @@ extern void update_setpoint_events(const struct dive *dive, struct divecomputer
* QVariants and through QML.
*/
#include <QObject>
#include <string>
Q_DECLARE_METATYPE(struct dive *);
extern std::string existing_filename;
#endif
#endif // DIVE_H

View file

@ -44,7 +44,7 @@
#include <libxslt/documents.h>
const char *existing_filename;
std::string existing_filename;
static QLocale loc;
static inline QString degreeSigns()
@ -521,12 +521,6 @@ QLocale getLocale()
return loc;
}
void set_filename(const char *filename)
{
free((void *)existing_filename);
existing_filename = copy_string(filename);
}
QString get_depth_string(int mm, bool showunit, bool showdecimal)
{
if (prefs.units.length == units::METERS) {

View file

@ -125,7 +125,6 @@ bool canReachCloudServer(struct git_info *);
void updateWindowTitle();
void subsurface_mkdir(const char *dir);
char *get_file_name(const char *fileName);
void set_filename(const char *filename);
void copy_image_and_overwrite(const char *cfileName, const char *path, const char *cnewName);
char *move_away(const char *path);
const char *local_file_path(struct picture *picture);

View file

@ -1192,12 +1192,12 @@ static int create_new_commit(struct git_info *info, git_oid *tree_id, bool creat
return report_error("Unable to look up parent in branch '%s'", info->branch);
if (!saved_git_id.empty()) {
if (existing_filename && verbose)
report_info("existing filename %s\n", existing_filename);
if (!existing_filename.empty() && verbose)
report_info("existing filename %s\n", existing_filename.c_str());
const git_oid *id = git_commit_id((const git_commit *) parent);
/* if we are saving to the same git tree we got this from, let's make
* sure there is no confusion */
if (same_string(existing_filename, info->url) && git_oid_strcmp(id, saved_git_id.c_str()))
if (existing_filename == info->url && git_oid_strcmp(id, saved_git_id.c_str()))
return report_error("The git branch does not match the git parent of the source");
}

View file

@ -76,5 +76,11 @@ std::string format_string_std(const char *fmt, Args&&... args)
return res;
}
// Sadly, starts_with only with C++20!
inline bool starts_with(const std::string &s, const char *s2)
{
return s.rfind(s2, 0) == 0;
}
#endif
#endif // SUBSURFACE_STRING_H