Merge branch 'refs/heads/t/hash-sort-for-ls'
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index c2642ed3d13ceb139335cdef0c06c6999cd2ae7b..63a40d790f602c81d6f28e71e02b6d46d907cd5d 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1110,6 +1110,12 @@ out:
        return ret;
 }
 
+static int ls_hash_compare(const void *a, const void *b)
+{
+       struct ls_data *d1 = *(struct ls_data **)a, *d2 = *(struct ls_data **)b;
+       return memcmp(d1->hash, d2->hash, HASH_SIZE);
+}
+
 static int ls_audio_format_compare(const void *a, const void *b)
 {
        struct ls_data *d1 = *(struct ls_data **)a, *d2 = *(struct ls_data **)b;
@@ -1227,6 +1233,8 @@ static int sort_matching_paths(struct ls_options *options)
                compar = ls_duration_compare; break;
        case LS_SORT_BY_AUDIO_FORMAT:
                compar = ls_audio_format_compare; break;
+       case LS_SORT_BY_HASH:
+               compar = ls_hash_compare; break;
        default:
                return -E_BAD_SORT;
        }
@@ -1375,7 +1383,6 @@ out:
        return ret;
 }
 
-/* TODO: flags -h (sort by hash) */
 static int com_ls(struct command_context *cc, struct lls_parse_result *lpr)
 {
        const struct lls_command *cmd = SERVER_CMD_CMD_PTR(LS);
@@ -1441,6 +1448,8 @@ static int com_ls(struct command_context *cc, struct lls_parse_result *lpr)
                        opts->sorting = LS_SORT_BY_DURATION;
                else if (!strcmp(val, "a") || !strcmp(val, "audio-format"))
                        opts->sorting = LS_SORT_BY_AUDIO_FORMAT;
+               else if (!strcmp(val, "h") || !strcmp(val, "hash"))
+                       opts->sorting = LS_SORT_BY_HASH;
                else {
                        ret = -E_AFT_SYNTAX;
                        goto out;